Skip to content

Commit

Permalink
Merge branch 'trunk' into fix/number-control-infinity-attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Infinite-Null committed Feb 12, 2025
2 parents d4d17c8 + 9182d59 commit f26c7b0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 47 deletions.
2 changes: 2 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

- `NumberControl`: Fix invalid HTML attributes for infinite bounds ([#69033](https://github.com/WordPress/gutenberg/pull/69033)).

- `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

0 comments on commit f26c7b0

Please sign in to comment.