Repository navigation
fix(core): TopNavMegaMenu hover-then-click no longer dismisses the panel (#3121) - #4555
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR Analysis Report📚 Storybook PreviewView Storybook for this PR 🧪 Sandbox PreviewView Sandbox for this PR Modified ComponentsTopNav (@astryxdesign/core) · View in Storybook
Bundle Size Summary
Accessibility AuditStatus: No accessibility violations detected. Generated by PR Enrichment workflow | Storybook | Sandbox | View full report |
|
Just found #3851 (thanks Cindy for sharing that). will iterate on that PR since that's older |
37c5949 to
3f05972
Compare
Register the trigger as the native auto-popover invoker and add a 500 ms hover-to-click confirmation guard. Preserve native light dismiss, Escape behavior, focus restoration, and sibling-popover exclusivity while pinning deliberate click and keyboard opens.
3f05972 to
f2261bd
Compare
|
#3851 hasn't been updated for a while so I am reopening this PR |
cixzhang
left a comment
There was a problem hiding this comment.
Hmm trying in the deployment but seems like it doesn't open the mega menu at all, so let me take a closer look.
|
@cixzhang Thanks for reviewing! Follow-up on the docsite issue: Why Storybook worked while the docsite did not:
Commit
We also discovered that this PR fixes the production issue tracked in #4785: hovering a closed panel’s invisible area could reopen it. The PR separates the panel and trigger hover handlers so only the trigger can schedule an open. Verified in Chrome; 37 component tests and 303 docsite tests pass. |
…nvoker wiring Consolidates the hover/click interaction the TopNavMegaMenu fix (#4555) solved locally into the shared hook, so every menu that opens on hover gets it.
TopNavMegaMenu drops its private hover/click machine (#4555) for the shared hook; DropdownMenuSubMenu takes the guard through confirmHoverOpen and loses its rAF focus; the nav headings' in-popup dismiss affordances route through the hook's close so focus returns to the trigger. jsdom now reports (hover: hover) as matching, which is what a desktop browser reports — hover paths were unreachable in tests before.
#4936) * fix(hooks): useMenuHover hover-then-click guard, synchronous focus, invoker wiring Consolidates the hover/click interaction the TopNavMegaMenu fix (#4555) solved locally into the shared hook, so every menu that opens on hover gets it. * refactor(core): put every hover menu on useMenuHover TopNavMegaMenu drops its private hover/click machine (#4555) for the shared hook; DropdownMenuSubMenu takes the guard through confirmHoverOpen and loses its rAF focus; the nav headings' in-popup dismiss affordances route through the hook's close so focus returns to the trigger. jsdom now reports (hover: hover) as matching, which is what a desktop browser reports — hover paths were unreachable in tests before. * test(core): cover the shared hover-menu contract and its a11y 19 hook tests through TopNavMenu plus per-component guard/focus tests for both nav headings and the dropdown submenu: who holds focus after each way of opening and closing, keyboard activation on an open menu, Escape restore, and that a device without a hover-capable pointer cannot be tricked into opening one. * fix(hooks): a closed menu no longer reopens under a stationary pointer Found in Chrome, not jsdom: a panel positioned over its own trigger (the nav headings) puts the trigger back under a pointer that never moved when it closes, and the browser fires a fresh mouseenter for that. With a zero show delay the menu reopened instantly, which made Escape and the in-panel close affordance look inert. Replaces the one-shot skip-next-mouseenter with a 300ms window after any close, so the enter caused by the panel vanishing is ignored while a deliberate re-hover seconds later still opens the menu. * fix(hooks): move close bookkeeping out of render; trim comments The reopen-suppression timestamp was taken during render, which the purity lint rule rightly rejects. It moves to a layout effect — which also has to land before the browser hit-tests the vanished panel, so it is the correct phase rather than just the legal one. Comments cut back to what the code cannot say. * fix(hooks): let a pointer-only consumer keep its own focus and toggle #4880 landed SideNavItem on useMenuHover while this branch was rewriting it, wiring the pointer half only: its flyout is a focus-trapped dialog of links, not a menu of items, and usePopover owns focus there. - `ownsFocus` (default true) stops the hook suppressing the popover's auto-focus and reaching for a first item that flyout does not have. - SideNavItem opts out of the hover→click guard: its flyout opens beside the rail rather than over the icon, so the click after a hover-open is a dismissal, not the #3121 confirmation. - A real mouseleave now clears the reopen-suppression window, so a deliberate leave-and-return reopens immediately rather than waiting it out. - Its fireEvent clicks say `detail: 1`; a detail-0 click is Enter/Space to the hook, which always opens instead of toggling.
…nvoker wiring Consolidates the hover/click interaction the TopNavMegaMenu fix (#4555) solved locally into the shared hook, so every menu that opens on hover gets it.
TopNavMegaMenu drops its private hover/click machine (#4555) for the shared hook; DropdownMenuSubMenu takes the guard through confirmHoverOpen and loses its rAF focus; the nav headings' in-popup dismiss affordances route through the hook's close so focus returns to the trigger. jsdom now reports (hover: hover) as matching, which is what a desktop browser reports — hover paths were unreachable in tests before.
Fixes #3121.
Summary
The Top Nav mega menu flickered shut when you hovered a nav item and then clicked it—the click that naturally follows a hover dismissed the menu.
Root cause: the panel is a native
popover="auto", and the trigger button sits outside it. Without a native invoker relationship, the browser can light-dismiss the hover-opened panel during the trigger's pointer interaction, before React's click guard decides what the click means. jsdom does not implement this native event ordering, so unit tests alone cannot reproduce the original failure.Fix (
packages/core/src/TopNav/TopNavMegaMenu.tsx):popover="auto"so native outside-click dismissal, Escape handling, focus restoration, and sibling-popover exclusivity remain intact.popoverTarget, which exempts the trigger interaction from auto-popover light-dismiss.preventDefault()so the component's interaction logic remains the single source of truth.No public API change.
Test plan
Automated
packages/core/src/TopNav/TopNavMegaMenu.test.tsx: 37 passing, covering the 500 ms guard, pinned versus transient behavior, native-invoker wiring, default-toggle cancellation, native-dismiss state reconciliation, sibling-popover exclusivity, panel exit-hover behavior, and keyboard behavior.packages/core/src/TopNavsuite: 103 passing.pnpm -F @astryxdesign/core typecheckand ESLint: clean.The unit tests intentionally lock in the required wiring, but jsdom cannot exercise native
popoverTarget/light-dismiss ordering. The interaction below was therefore verified in a real Chromium browser against the Storybookcore-topnavmenu--mega-menustory.Real browser
Browsers without the Popover API retain the component's existing degraded
useLayerfallback; this PR does not add a legacy outside-dismiss polyfill.Before
Hover → immediate click dismisses the menu:
Mega.Menu.repro.mov
After
Hover → immediate click keeps the menu open:
Mega.Menu.fix.mov