-
Notifications
You must be signed in to change notification settings - Fork 116
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 ActionMenu item activation #2885
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
🦋 Changeset detectedLatest commit: 72805fe The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
camertron
requested review from
mperrotti and
jonrohan
and removed request for
mperrotti
June 6, 2024 18:13
jonrohan
approved these changes
Jun 11, 2024
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Authors: Please fill out this form carefully and completely.
Reviewers: By approving this Pull Request you are approving the code change, as well as its deployment and mitigation plans.
Please read this description carefully. If you feel there is anything unclear or missing, please ask for updates.
What are you trying to accomplish?
In working on the experimental
SelectPanel
in dotcom, we have noticed a number of issues using the keyboard to activate items in multiple- and single-select modes. SinceSelectPanel
is based onActionMenu
, I decided to take another look atActionMenu
to inform my work onSelectPanel
. In so doing, I discovered a number of deficiencies inActionMenu
's custom element code that I believe are causing the issues we're seeing inSelectPanel
.Integration
No changes necessary in production.
Risk Assessment
What approach did you choose and why?
One of the big issues my work uncovered is that browsers appear to fire both a
PointerEvent
and aKeyboardEvent
when you press 'Enter' on anActionMenu
item. This is causing the item to be activated twice, and is why we're seeing the item fail to toggle when we press 'Enter' on it (i.e. the first event checks and the second one unchecks so quickly it appears nothing happens). I don't remember two events firing before, so it's possible some browser-level thing changed recently 🤷It turns out we can use
PointerEvent
s almost exclusively, as they fire when clicking and pressing 'Enter.' I say "almost" because activating menu items is also possible by pressing 'Space' on anchor tag items (eg. items that use the<a>
tag), which does not cause aPointerEvent
but instead aKeyboardEvent
(confused yet?) By listening forkeydown
specifically on anchor items andclick
for everything else, all interactions via the mouse and keyboard work as expected.I also simplified how activating items works by removing the
#activateItem
method. Previously,#handleEvent
would call#activateItem
and then#handleItemActivated
. The#activateItem
method contained some logic to handle issues to override the default button click behavior, which included callingclick()
on the button to simulate a mouse-driven click (as opposed to a keyboard-driven one). This was causing another form of the double activation issue I mentioned earlier, ashandleEvent
would call#activateItem
which would callclick()
on the item, which would triggerhandleEvent
again. This would eventually result in two calls to#handleItemActivated
, which would check and then uncheck the item in rapid succession, appearing to have no effect.Accessibility
Merge checklist
- [ ] Added/updated documentation- [ ] Added/updated previews (Lookbook)Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.