Stop keypresses being caught by other elements when they happen in a CustomSelectControl#30557
Conversation
|
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @opr! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
|
Hi folks - coming in with an update to provide context. Here's a real-world example of what this PR aims to solve, when a user has a WordPress site, connected via Jetpack, there is a sidebar that can be opened by pressing N. When a customer is using WooCommerce Blocks, there are input fields for Country/State that use If the user tries to type into these boxes, for example 'United Kingdom', then the here's a video to show it happening (note the inputs given while the select box is focused are |
ntsekouras
left a comment
There was a problem hiding this comment.
Thanks for working on this @opr !
After reading a bit more the issue in downshift and related discussions there, this approach seems to be the suggested workaround. I'm wondering though why even with this code, the Escape still propagated.
I inserted a CustomSelectControl in a Modal here, after the TextControl
-- demo snippet:
<CustomSelectControl
label="Font Size"
options={ [
{
key: 'small',
name: 'Small',
style: { fontSize: '50%' },
},
{
key: 'normal',
name: 'Normal',
style: { fontSize: '100%' },
},
] }
/>
Then:
- insert a
Template Partand clickNew template part - open the select control
- press
Escape
I would expect the Modal to stay open and only the select to close, but this is not happening..
459df8b to
e7ba1b9
Compare
|
Thanks @ntsekouras I've made a change to stop the synthetic event propagating and it has solved the issue you mentioned in your review. |
e7ba1b9 to
ce80b19
Compare
|
Hey @ciampo thanks for the review and sorry for the delay! All done and ready for a re-review :) |
This stops other listeners receiving this event, whereas stopping the native event still somehow allowed propagation.
6014960 to
58a2dca
Compare
…CustomSelectControl (#30557) * Stop the keydown event from propagating in CustomSelect component * Stop the synthetic event propagating instead of native This stops other listeners receiving this event, whereas stopping the native event still somehow allowed propagation. * Move keyDown handler into useCallback and use optional chaining * Add unit tests for CustomSelectControl * Update changelog * Add inline comment about role and remove unneeded class name * Move mocked function into test * Add correct spacing to changelog * Add options as an array of key value pairs * Use accessible roles instead of looking for elements by className
Description
In the
<ul>output byCustomSelectControlI have added a function to handleonKeyDown- this stops the event from propagating, but still calls theonKeyDownhandler (which is derived ultimately fromdownshift).This PR fixes #30204.
How has this been tested?
In the linked issue (#30204) the reproducible steps can also be used to test:
npm run storybook:devCustomSelectControl > Defaultcomponent, click it and start typingsto get to the entrySmallskeypress being cancelled.Types of changes
Bug fix
Checklist: