Skip to content

Commit

Permalink
Add a unit test and some documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Oct 30, 2023
1 parent d0ba9ea commit 5fc5d70
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Enhancements

- `InputControl`/`SelectControl`: update `height`/`min-height` to `32px` instead of `30px` to align with modern sizing scale ([#55490](https://github.com/WordPress/gutenberg/pull/55490)).
- `ComboboxControl`: Add `shouldFilter` prop to allow the options to be controlled and filtered externally ([#55574](https://github.com/WordPress/gutenberg/pull/55574)).

### Bug Fix

Expand Down
8 changes: 8 additions & 0 deletions packages/components/src/combobox-control/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ Function called when the control's search input value changes. The argument cont
- Type: `( value: string ) => void`
- Required: No

#### shouldFilter

Function called to determine whether the control should filter the list of displayed options based on the user input or whether it's something that is handled externally by updating the `options` prop when the `onFilterValueChange` callback is called.

- Type: `boolean`
- Required: No
- Default: `true`

#### onChange

Function called with the selected value changes.
Expand Down
28 changes: 28 additions & 0 deletions packages/components/src/combobox-control/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,34 @@ describe.each( [
expect( input ).toHaveValue( targetOption.label );
} );

it( 'should not filter the list of options if shouldFilter is false', async () => {
const user = await userEvent.setup();
const targetOption = timezones[ 0 ];
const onChangeSpy = jest.fn();
render(
<Component
options={ timezones }
label={ defaultLabelText }
onChange={ onChangeSpy }
shouldFilter={ false }
/>
);
const input = getInput( defaultLabelText );

// Pressing tab selects the input and shows the options
await user.tab();

// Type enough characters to ensure a predictable search result
await user.keyboard( 'Japan' );

// Pressing Enter/Return selects the currently focused option
await user.keyboard( '{Enter}' );

expect( onChangeSpy ).toHaveBeenCalledTimes( 1 );
expect( onChangeSpy ).toHaveBeenCalledWith( targetOption.value );
expect( input ).toHaveValue( targetOption.label );
} );

it( 'should render aria-live announcement upon selection', async () => {
const user = await userEvent.setup();
const targetOption = timezones[ 9 ];
Expand Down

0 comments on commit 5fc5d70

Please sign in to comment.