-
Notifications
You must be signed in to change notification settings - Fork 4.5k
FormTokenField
: Fix focus lost on tab when __experimentalExpandOnFocus
is set
#70591
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
FormTokenField
: Fix focus lost on tab when __experimentalExpandOnFocus
is set
#70591
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. |
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.
Thanks for the PR!
Although this PR works fine, I think this issue is not directly related to the Modal
component. That is, it is an issue with the component itself that the focus is lost when pressing the Tab key when the __experimentalExpandOnFocus
property is true
. So, according to the PR title and changelog entry, some may misunderstand that the issue only occurs in the Modal
component, so it would be good to fix that.
Another thing worth noting is that this PR changes the behavior when the __experimentalExpandOnFocus
prop is false
.
trunk - Pressing the Tab key doesn't close the suggestions list:
trunk.mp4
This PR - Pressing the Tab key closes the suggestions list:
pr.mp4
The behavior in trunk looks like a bug to me 🤔
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 works well for me 👍 Thanks @yogeshbhutkar!
I'd suggest reorganizing the code a bit differently, but I don't think it is a major blocker for this fix.
* Also updates CHANGELOG for better intent
FormTokenField
: Fix focus lost on Tab when used within Modal
FormTokenField
: Fix focus lost on tab when __experimentalExpandOnFocus
is set
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 👍
What, Why, and How?
Closes #66571
This PR fixes a focus loss issue triggered during
tab
navigation when theFormTokenField
component is used inside aModal
.The problem arises because, when tabbing, the
SuggestionList
briefly receives focus. This triggers theonBlur
logic, which collapses theSuggestionList
prematurely and results in a loss of focus.To address this, the PR introduces a
keydown
handler for theTab
key. This ensures theSuggestionList
is collapsed before the defaultTab
behaviour is executed, allowing the focus to correctly move to the next focusable element.Testing Instructions
Options
, thenCreate pattern
.Testing Instructions for Keyboard
Same.
Screencast
pr-demo.mov