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 Size Picker: Remove Custom option from FontSizePickerSelect dropdown #69038

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- `FontSizePicker`: Remove Custom option from dropdown to prevent unexpected context changes during keyboard navigation ([#69038](https://github.com/WordPress/gutenberg/pull/69038)).

- `ComboboxControl`: Add an `isLoading` prop to show a loading spinner ([#68990](https://github.com/WordPress/gutenberg/pull/68990))

## 29.3.0 (2025-01-29)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,8 @@ const DEFAULT_OPTION: FontSizePickerSelectOption = {
value: undefined,
};

const CUSTOM_OPTION: FontSizePickerSelectOption = {
key: 'custom',
name: __( 'Custom' ),
};

const FontSizePickerSelect = ( props: FontSizePickerSelectProps ) => {
const {
__next40pxDefaultSize,
fontSizes,
value,
disableCustomFontSizes,
size,
onChange,
onSelectCustom,
} = props;
const { __next40pxDefaultSize, fontSizes, value, size, onChange } = props;

const areAllSizesSameUnit = !! getCommonSizeUnit( fontSizes );

Expand All @@ -59,12 +46,10 @@ const FontSizePickerSelect = ( props: FontSizePickerSelectProps ) => {
hint,
};
} ),
...( disableCustomFontSizes ? [] : [ CUSTOM_OPTION ] ),
];

const selectedOption = value
? options.find( ( option ) => option.value === value ) ?? CUSTOM_OPTION
: DEFAULT_OPTION;
const selectedOption =
options.find( ( option ) => option.value === value ) ?? DEFAULT_OPTION;

return (
<CustomSelectControl
Expand All @@ -86,11 +71,7 @@ const FontSizePickerSelect = ( props: FontSizePickerSelectProps ) => {
}: {
selectedItem: FontSizePickerSelectOption;
} ) => {
if ( selectedItem === CUSTOM_OPTION ) {
onSelectCustom();
} else {
onChange( selectedItem.value );
}
onChange( selectedItem.value );
} }
size={ size }
/>
Expand Down
26 changes: 2 additions & 24 deletions packages/components/src/font-size-picker/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,14 @@ describe( 'FontSizePicker', () => {
screen.getByRole( 'combobox', { name: 'Font size' } )
);
const options = screen.getAllByRole( 'option' );
expect( options ).toHaveLength( 8 );
expect( options ).toHaveLength( 7 );
expect( options[ 0 ] ).toHaveAccessibleName( 'Default' );
expect( options[ 1 ] ).toHaveAccessibleName( 'Tiny 8' );
expect( options[ 2 ] ).toHaveAccessibleName( 'Small 12' );
expect( options[ 3 ] ).toHaveAccessibleName( 'Medium 16' );
expect( options[ 4 ] ).toHaveAccessibleName( 'Large 20' );
expect( options[ 5 ] ).toHaveAccessibleName( 'Extra Large 30' );
expect( options[ 6 ] ).toHaveAccessibleName( 'xx-large 40' );
expect( options[ 7 ] ).toHaveAccessibleName( 'Custom' );
} );

test.each( [
Expand Down Expand Up @@ -186,7 +185,6 @@ describe( 'FontSizePicker', () => {
}
);

commonSelectTests( fontSizes );
commonTests( fontSizes );
} );

Expand Down Expand Up @@ -231,15 +229,14 @@ describe( 'FontSizePicker', () => {
screen.getByRole( 'combobox', { name: 'Font size' } )
);
const options = screen.getAllByRole( 'option' );
expect( options ).toHaveLength( 8 );
expect( options ).toHaveLength( 7 );
expect( options[ 0 ] ).toHaveAccessibleName( 'Default' );
expect( options[ 1 ] ).toHaveAccessibleName( 'Tiny 8px' );
expect( options[ 2 ] ).toHaveAccessibleName( 'Small 1em' );
expect( options[ 3 ] ).toHaveAccessibleName( 'Medium 2rem' );
expect( options[ 4 ] ).toHaveAccessibleName( 'Large' );
expect( options[ 5 ] ).toHaveAccessibleName( 'Extra Large 30px' );
expect( options[ 6 ] ).toHaveAccessibleName( 'xx-large 40px' );
expect( options[ 7 ] ).toHaveAccessibleName( 'Custom' );
} );

test.each( [
Expand Down Expand Up @@ -327,7 +324,6 @@ describe( 'FontSizePicker', () => {
}
);

commonSelectTests( fontSizes );
commonTests( fontSizes );
} );

Expand Down Expand Up @@ -523,24 +519,6 @@ describe( 'FontSizePicker', () => {
);
}

function commonSelectTests( fontSizes: FontSize[] ) {
it( 'shows custom input when Custom is selected', async () => {
const user = userEvent.setup();
const onChange = jest.fn();
await render(
<FontSizePicker fontSizes={ fontSizes } onChange={ onChange } />
);
await user.click(
screen.getByRole( 'combobox', { name: 'Font size' } )
);
await user.click(
screen.getByRole( 'option', { name: 'Custom' } )
);
expect( screen.getByLabelText( 'Custom' ) ).toBeVisible();
expect( onChange ).not.toHaveBeenCalled();
} );
}

function commonTests( fontSizes: FontSize[] ) {
it( 'shows custom input when value is unknown', async () => {
await render(
Expand Down
7 changes: 6 additions & 1 deletion schemas/json/wp-env.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,12 @@
"$ref": "#/definitions/wpEnvPropertyNames"
},
{
"enum": [ "$schema", "env", "testsPort", "lifecycleScripts" ]
"enum": [
"$schema",
"env",
"testsPort",
"lifecycleScripts"
]
}
]
}
Expand Down
Loading