Skip to content

Commit

Permalink
Refactor font variant components to use useId for checkbox IDs (#69050)
Browse files Browse the repository at this point in the history
Co-authored-by: torounit <toro_unit@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: chiilog <mel_cha@git.wordpress.org>
  • Loading branch information
5 people authored Feb 5, 2025
1 parent d9d138a commit 3f0a805
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
/**
* WordPress dependencies
*/
import {
CheckboxControl,
Flex,
privateApis as componentsPrivateApis,
} from '@wordpress/components';
import { useId } from '@wordpress/element';
import { CheckboxControl, Flex } from '@wordpress/components';

/**
* Internal dependencies
*/
import { getFontFaceVariantName } from './utils';
import FontDemo from './font-demo';
import { unlock } from '../../../lock-unlock';

const { kebabCase } = unlock( componentsPrivateApis );

function CollectionFontVariant( {
face,
Expand All @@ -31,9 +25,7 @@ function CollectionFontVariant( {
};

const displayName = font.name + ' ' + getFontFaceVariantName( face );
const checkboxId = kebabCase(
`${ font.slug }-${ getFontFaceVariantName( face ) }`
);
const checkboxId = useId();

return (
<div className="font-library-modal__font-card">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
/**
* WordPress dependencies
*/
import { useContext } from '@wordpress/element';
import {
CheckboxControl,
Flex,
privateApis as componentsPrivateApis,
} from '@wordpress/components';
import { useContext, useId } from '@wordpress/element';
import { CheckboxControl, Flex } from '@wordpress/components';

/**
* Internal dependencies
*/
import { getFontFaceVariantName } from './utils';
import { FontLibraryContext } from './context';
import FontDemo from './font-demo';
import { unlock } from '../../../lock-unlock';

const { kebabCase } = unlock( componentsPrivateApis );

function LibraryFontVariant( { face, font } ) {
const { isFontActivated, toggleActivateFont } =
Expand All @@ -41,9 +34,7 @@ function LibraryFontVariant( { face, font } ) {
};

const displayName = font.name + ' ' + getFontFaceVariantName( face );
const checkboxId = kebabCase(
`${ font.slug }-${ getFontFaceVariantName( face ) }`
);
const checkboxId = useId();

return (
<div className="font-library-modal__font-card">
Expand Down

0 comments on commit 3f0a805

Please sign in to comment.