Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Font Library modal: Try to improve checkbox labelling #58339

Merged
merged 13 commits into from
Feb 2, 2024
4 changes: 4 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
- `DropdownMenuV2`: Restore accent color themability ([#58130](https://github.com/WordPress/gutenberg/pull/58130)).
- Expand theming support in the `COLORS` variable object ([#58097](https://github.com/WordPress/gutenberg/pull/58097)).

### Enhancements

- `CheckboxControl`: Remove ability for label prop to be false ([#58339](https://github.com/WordPress/gutenberg/pull/58339)).

## 25.16.0 (2024-01-24)

### Enhancements
Expand Down
3 changes: 1 addition & 2 deletions packages/components/src/checkbox-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,11 @@ const MyCheckboxControl = () => {
The set of props accepted by the component will be specified below.
Props not included in this set will be applied to the input element.

#### `label`: `string|false`
#### `label`: `string`

A label for the input field, that appears at the side of the checkbox.
The prop will be rendered as content a label element.
If no prop is passed an empty label is rendered.
If the prop is set to false no label is rendered.

- Required: No

Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/checkbox-control/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ describe( 'CheckboxControl', () => {
expect( label ).toBeInTheDocument();
} );

it( 'should not render label element if label is set to false', () => {
render( <CheckboxControl label={ false } /> );
it( 'should not render label element if label is not set', () => {
render( <CheckboxControl /> );

const label = screen.queryByRole( 'label' );
expect( label ).not.toBeInTheDocument();
Expand Down
5 changes: 2 additions & 3 deletions packages/components/src/checkbox-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ export type CheckboxControlProps = Pick<
/**
* A label for the input field, that appears at the side of the checkbox.
* The prop will be rendered as content a label element. If no prop is
* passed an empty label is rendered. If the prop is set to false no label
* is rendered.
* passed an empty label is rendered.
*/
label?: string | false;
label?: string;
/**
* If checked is true the checkbox will be checked. If checked is false the
* checkbox will be unchecked. If no value is passed the checkbox will be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,23 @@ function CollectionFontVariant( {
);

return (
<label
className="font-library-modal__library-font-variant"
htmlFor={ checkboxId }
>
<div className="font-library-modal__library-font-variant">
<Flex justify="flex-start" align="center" gap="1rem">
<CheckboxControl
checked={ selected }
onChange={ handleToggleActivation }
__nextHasNoMarginBottom={ true }
id={ checkboxId }
label={ false }
/>
<FontFaceDemo fontFace={ face } text={ displayName } />
<label htmlFor={ checkboxId }>
<FontFaceDemo
fontFace={ face }
text={ displayName }
onClick={ handleToggleActivation }
/>
</label>
</Flex>
</label>
</div>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,23 @@ function LibraryFontVariant( { face, font } ) {
);

return (
<label
className="font-library-modal__library-font-variant"
htmlFor={ checkboxId }
>
<div className="font-library-modal__library-font-variant">
<Flex justify="flex-start" align="center" gap="1rem">
<CheckboxControl
checked={ isInstalled }
onChange={ handleToggleActivation }
__nextHasNoMarginBottom={ true }
id={ checkboxId }
label={ false }
/>
<FontFaceDemo fontFace={ face } text={ displayName } />
<label htmlFor={ checkboxId }>
<FontFaceDemo
fontFace={ face }
text={ displayName }
onClick={ handleToggleActivation }
/>
</label>
</Flex>
</label>
</div>
);
}

Expand Down
Loading