Skip to content

Conversation

@ze-flo
Copy link
Contributor

@ze-flo ze-flo commented Mar 28, 2025

Description

This PR addresses a bug where the Menu’s dropdown remained open when the user clicked outside its iframe. The dropdown now correctly closes when focus is moved outside the iframe.

Detail

This PR implements the fix in Menu for manual testing in Storybook.

Checklist

  • 🌐 demo is up-to-date (npm start)
  • 💂‍♂️ includes new unit tests
  • ♿ tested for WCAG 2.1 AA compliance
  • 📝 tested in Chrome, Firefox, Safari, and Edge

@ze-flo ze-flo requested a review from a team as a code owner March 28, 2025 01:19
@coveralls
Copy link

coveralls commented Mar 28, 2025

Coverage Status

coverage: 94.934% (-0.9%) from 95.786%
when pulling 16da5cf on ze-flo/usemenu-blur-fix
into 9475f21 on main.

Copy link
Member

@jzempel jzempel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Controlled usage can't escape the trigger with the keyboard.

Copy link
Contributor Author

@ze-flo ze-flo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the Storybook demos and the Website Menu examples.

if (!isMenuOrTriggerFocused) {
const nextElementIsFocusable =
!!event.relatedTarget /* [1] */ &&
event.relatedTarget?.nodeName !== '#document'; /* [2] */
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On our Gatsby site, when a menu dropdown is open and you click outside, focus shifts to a <div> with tabIndex="-1" instead of the trigger. Should I handle that case?

Screenshot 2025-04-03 at 4 53 53 PM

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I doubt it, because the updated behavior is so much better than current https://garden.zendesk.com/components/menu – which jumps to the currently expanded menu when you trigger a menu further down the page.

Copy link
Member

@jzempel jzempel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't quite pin it down, but I run into some obscure combos where the state feels just a bit off. However, overall I think we can call this a real nice quality-of-life boost for the menu hook. And the accompanying tests + comments are an excellent guide if we need to revisit for future tweaks. Nice work @ze-flo 🙌

if (!isMenuOrTriggerFocused) {
const nextElementIsFocusable =
!!event.relatedTarget /* [1] */ &&
event.relatedTarget?.nodeName !== '#document'; /* [2] */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I doubt it, because the updated behavior is so much better than current https://garden.zendesk.com/components/menu – which jumps to the currently expanded menu when you trigger a menu further down the page.

Co-authored-by: Jonathan Zempel <jzempel@gmail.com>
@ze-flo ze-flo merged commit 90bdb14 into main Apr 8, 2025
4 checks passed
@ze-flo ze-flo deleted the ze-flo/usemenu-blur-fix branch April 8, 2025 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants