-
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
Tags autocompleter keyboard interaction improvements. #8031
Tags autocompleter keyboard interaction improvements. #8031
Conversation
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.
LGTM code wise. I just wonder if the "reset the text when clicking escape" is not confusing for users (thus the "need design review" label)
@youknowriad yeah I'd also prefer the text entered in the input field to stay there when pressing Escape. Haven't found a way to do that, as seems to me the only way to properly close the suggestions list is to reset the state to its initial values: |
@afercia Just a guess:
|
@youknowriad I did try that, nope. Actually |
07b03f9
to
c6feb24
Compare
Rebased. With some refactoring, I've found a way to keep the typed text after pressing Escape. If this approach is not desirable, I can revert the latest commit and let the entered text go away. No strong opinions about the best behavior. Either ways, I'd like to make one more round to let the suggestions list close when tabbing away from the field. Currently, it stays open. It should close. @youknowriad when you have a chance I'd greatly appreciate your eyes here, especially for the tests part. I had no idea how to fix them other than what I've done. |
If I'm reading this properly, it looks like |
Yes it is possible I've missed the duplication, will double check thanks! |
Worth noting that everytime I had to change the tests for this component, then I got an error "cannot find ... |
c6feb24
to
d8dc0e0
Compare
Rebased. Dropped Re: closing the suggestions list when tabbing away from the field (or clicking outside), I'm having a second thought. In a way, it may make sense to keep it as is and show the matching suggestions when there's a valid value in the field. We can always revisit later if the preferred behavior is to always close. |
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.
Looks good to me code wise.
if ( this.props.tokenizeOnSpace ) { | ||
preventDefault = this.addCurrentToken(); | ||
} | ||
break; | ||
case ESCAPE: | ||
preventDefault = this.handleEscapeKey( event ); | ||
event.stopPropagation(); |
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.
Can you explain the use of stopPropagation
here? Ideally omitting any mention of the word "autocompleter", as this is intended to be a general-use component unaware of any such context usage.
I'm not suggesting it's not needed, but I've become very wary of their use, as they have the tendency to be used as an extreme solution which are never obvious to evaluate as being necessary to the future maintainer. I might propose we go so far as to introduce an ESLint rule which we'd knowingly anticipate to be disabled in specific circumstances, but more as a general deterrent (also encouraging comments to explain the disabling).
Description
This PR aims to improve keyboard interaction with the tags "autocompleter" (i.e. the flat term selector
FormTokenField
).Also uses
@wordpress/keycodes
instead of numeric keycodes.Consistency with similar UIs is improved too, as many other similar tools (mention autocompleter, slash inserter autocompleter, all the various menus) already cycle through the options and close on Escape.
How has this been tested?
npm test
Fixes #8028