Skip to content

Commit

Permalink
Combobox Control: Do not clear values when focusing the textbox
Browse files Browse the repository at this point in the history
  • Loading branch information
zaguiini committed Sep 12, 2024
1 parent e9d31c2 commit 0423a7e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 0 additions & 3 deletions packages/components/src/combobox-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,6 @@ function ComboboxControl( props: ComboboxControlProps ) {
if ( expandOnFocus ) {
setIsExpanded( true );
}

onFilterValueChange( '' );
setInputValue( '' );
};

const onClick = () => {
Expand Down
20 changes: 20 additions & 0 deletions packages/components/src/combobox-control/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,26 @@ describe.each( [
expect( input ).toHaveValue( targetOption.label );
} );

it( 'calls onFilterValueChange whenever the textbox changes', async () => {
const user = userEvent.setup();
const onChangeSpy = jest.fn();
render(
<Component
options={ timezones }
label={ defaultLabelText }
onFilterValueChange={ onChangeSpy }
/>
);
const input = getInput( defaultLabelText );

await user.click( input );
expect( onChangeSpy ).not.toHaveBeenCalled();

await user.type( input, 'a' );
expect( onChangeSpy ).toHaveBeenCalledTimes( 1 );
expect( onChangeSpy ).toHaveBeenCalledWith( 'a' );
} );

it( 'should select the correct option from a search', async () => {
const user = await userEvent.setup();
const targetOption = timezones[ 13 ];
Expand Down

0 comments on commit 0423a7e

Please sign in to comment.