-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
packages/components/CHANGELOG.md
Outdated
@@ -19,6 +19,7 @@ | |||
|
|||
### Bug Fixes | |||
|
|||
- `ComboboxControl`: Fix ComboboxControl reset button when using the keyboard. ([#63410](https://github.com/WordPress/gutenberg/pull/63410)) |
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.
We will need to move this CHANGELOG entry to the Unreleased
section above, in a new Bug fixes
sub section
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.
Thank you for working on this, @afercia!
Code changes LGTM. Would you be able to also add a unit test for the reset behavior, so that we don't incur in future regressions?
Tanks @ciampo. Sure will work on an |
A unit test is better suited — we already have unit tests for You would then be able to run the test suite with the command |
36a8345
to
a978978
Compare
@ciampo I added a few unit tests. Confirmed the specific test for the |
Note: I was surprised the Testing Library syntax to press the Spacebar is |
Flaky tests detected in a978978. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9904222095
|
|
expect( resetButton ).toBeInTheDocument(); | ||
expect( resetButton ).toBeVisible(); |
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.
expect( resetButton ).toBeInTheDocument(); | |
expect( resetButton ).toBeVisible(); | |
expect( resetButton ).toBeVisible(); |
toBeVisible()
should already imply that the element is in the document
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.
Yup, I just copied and pasted from the existing test should render with visible label
, will fix it there as well
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 comment
The 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 expect( resetButton ).toBeEnabled()
check in each test?
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.
OK
Thanks, I think I addressed all the points. |
…63410) * Fix combobox reset button when using the keyboard. * Add changelog entry. * Add unit tests. * Adjust changelog entry. * Improve unit tests. Co-authored-by: afercia <afercia@git.wordpress.org> Co-authored-by: ciampo <mciampini@git.wordpress.org>
Fixes #63408
What?
The combobox Reset button doesn't work with the Enter key.
Why?
All UI controls should work with the keyboard.
How?
Prevents propagation of the keydown event.
Testing Instructions
Testing Instructions for Keyboard
Screenshots or screencast