-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Fix ComboboxControl reset button when using the keyboard. #63410
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -306,4 +306,153 @@ describe.each( [ | |
expect( onChangeSpy ).toHaveBeenCalledWith( targetOption.value ); | ||
expect( input ).toHaveValue( targetOption.label ); | ||
} ); | ||
|
||
it( 'should render with Reset button disabled', () => { | ||
render( | ||
<Component | ||
options={ timezones } | ||
label={ defaultLabelText } | ||
allowReset | ||
/> | ||
); | ||
|
||
const resetButton = screen.getByRole( 'button', { name: 'Reset' } ); | ||
|
||
expect( resetButton ).toBeInTheDocument(); | ||
expect( resetButton ).toBeVisible(); | ||
expect( resetButton ).toBeDisabled(); | ||
} ); | ||
|
||
it( 'should render with Reset button enabled after option selection', async () => { | ||
const user = await userEvent.setup(); | ||
const targetOption = timezones[ 13 ]; | ||
|
||
render( | ||
<Component | ||
options={ timezones } | ||
label={ defaultLabelText } | ||
allowReset | ||
/> | ||
); | ||
|
||
// Pressing tab selects the input and shows the options. | ||
await user.tab(); | ||
// Type enough characters to ensure a predictable search result. | ||
await user.keyboard( getOptionSearchString( targetOption ) ); | ||
// Pressing Enter/Return selects the currently focused option. | ||
await user.keyboard( '{Enter}' ); | ||
|
||
const resetButton = screen.getByRole( 'button', { name: 'Reset' } ); | ||
|
||
expect( resetButton ).toBeInTheDocument(); | ||
expect( resetButton ).toBeVisible(); | ||
expect( resetButton ).toBeEnabled(); | ||
} ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test feels superflous, since the next three tests (click/enter/spacebar on the button) would also fail if the button was disabled. At most we can add the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK |
||
|
||
it( 'should reset input when clicking the Reset button', async () => { | ||
const user = await userEvent.setup(); | ||
const targetOption = timezones[ 13 ]; | ||
|
||
render( | ||
<Component | ||
options={ timezones } | ||
label={ defaultLabelText } | ||
allowReset | ||
/> | ||
); | ||
|
||
// Pressing tab selects the input and shows the options. | ||
await user.tab(); | ||
// Type enough characters to ensure a predictable search result. | ||
await user.keyboard( getOptionSearchString( targetOption ) ); | ||
// Pressing Enter/Return selects the currently focused option. | ||
await user.keyboard( '{Enter}' ); | ||
|
||
const input = getInput( defaultLabelText ); | ||
|
||
expect( input ).toHaveValue( targetOption.label ); | ||
|
||
const resetButton = screen.getByRole( 'button', { name: 'Reset' } ); | ||
await user.click( resetButton ); | ||
|
||
expect( input ).toHaveValue( '' ); | ||
expect( resetButton ).toBeDisabled(); | ||
expect( input ).toHaveFocus(); | ||
} ); | ||
|
||
it( 'should reset input when pressing the Reset button with the Enter key', async () => { | ||
const user = await userEvent.setup(); | ||
const targetOption = timezones[ 13 ]; | ||
|
||
render( | ||
<Component | ||
options={ timezones } | ||
label={ defaultLabelText } | ||
allowReset | ||
/> | ||
); | ||
|
||
// Pressing tab selects the input and shows the options. | ||
await user.tab(); | ||
// Type enough characters to ensure a predictable search result. | ||
await user.keyboard( getOptionSearchString( targetOption ) ); | ||
// Pressing Enter/Return selects the currently focused option. | ||
await user.keyboard( '{Enter}' ); | ||
|
||
const input = getInput( defaultLabelText ); | ||
|
||
expect( input ).toHaveValue( targetOption.label ); | ||
|
||
// Pressing tab moves focus to the Reset buttons | ||
await user.tab(); | ||
|
||
const resetButton = screen.getByRole( 'button', { name: 'Reset' } ); | ||
|
||
expect( resetButton ).toHaveFocus(); | ||
|
||
// Pressing Enter/Return resets the input. | ||
await user.keyboard( '{Enter}' ); | ||
|
||
expect( input ).toHaveValue( '' ); | ||
expect( resetButton ).toBeDisabled(); | ||
expect( input ).toHaveFocus(); | ||
} ); | ||
|
||
it( 'should reset input when pressing the Reset button with the Spacebar key', async () => { | ||
const user = await userEvent.setup(); | ||
const targetOption = timezones[ 13 ]; | ||
|
||
render( | ||
<Component | ||
options={ timezones } | ||
label={ defaultLabelText } | ||
allowReset | ||
/> | ||
); | ||
|
||
// Pressing tab selects the input and shows the options. | ||
await user.tab(); | ||
// Type enough characters to ensure a predictable search result. | ||
await user.keyboard( getOptionSearchString( targetOption ) ); | ||
// Pressing Enter/Return selects the currently focused option. | ||
await user.keyboard( '{Enter}' ); | ||
|
||
const input = getInput( defaultLabelText ); | ||
|
||
expect( input ).toHaveValue( targetOption.label ); | ||
|
||
// Pressing tab moves focus to the Reset buttons. | ||
await user.tab(); | ||
|
||
const resetButton = screen.getByRole( 'button', { name: 'Reset' } ); | ||
|
||
expect( resetButton ).toHaveFocus(); | ||
|
||
// Pressing Spacebar resets the input. | ||
await user.keyboard( ' ' ); | ||
|
||
expect( input ).toHaveValue( '' ); | ||
expect( resetButton ).toBeDisabled(); | ||
expect( input ).toHaveFocus(); | ||
} ); | ||
} ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toBeVisible()
should already imply that the element is in the documentThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, I just copied and pasted from the existing test
should render with visible label
, will fix it there as well