Skip to content

fix(ui): dismiss account menu on route change; stop dropdown swallowing nav clicks#574

Open
eliran-ops wants to merge 2 commits intomainfrom
feat/fix-account-menu-dismissal-and-dropdown-click-capture
Open

fix(ui): dismiss account menu on route change; stop dropdown swallowing nav clicks#574
eliran-ops wants to merge 2 commits intomainfrom
feat/fix-account-menu-dismissal-and-dropdown-click-capture

Conversation

@eliran-ops
Copy link
Copy Markdown
Contributor

@eliran-ops eliran-ops commented Apr 29, 2026

Summary

Two routing-adjacent dismissal bugs (SKY-822):

  • 7 — Clicking a tab while a dropdown is open (e.g. Resources during the namespace dropdown) silently swallowed the click — no navigation, no apparent dropdown state change.
  • 8 — Account menu (avatar dropdown) did not dismiss when navigating to a different page; persisted across page changes.

Root cause

  • Bug 7: `NamespaceSelector` mounted a `fixed inset-0 z-[9998]` overlay above the entire viewport to detect outside clicks. The overlay's `onClick` closed the dropdown but, being above the nav, also ate the user's click — so Resources never received it.
  • Bug 8: `UserMenu` lives in the app shell and survives router transitions, so its open `isOpen` state persisted across navigations. The previous code only listened for outside clicks via `mousedown`, not for route changes.

Fix

  • New shared `useDismissable` hook in `packages/k8s-ui/src/hooks/` covering pointerdown-outside, Escape, and popstate dismissal in one declarative call. 7 unit tests pin the listener-attachment contract.
  • `UserMenu` now uses `useDismissable`, so the menu closes on outside click, Escape, AND route change.
  • `NamespaceSelector`'s click-eating backdrop is removed — the existing document-level `mousedown` listener already handled outside clicks cleanly. With the backdrop gone, a click on e.g. the Resources nav while the dropdown is open closes the dropdown AND navigates.
  • `NamespaceSelector` also gets a small `popstate` listener so the dropdown closes on browser navigation.

Test plan

  • `cd packages/k8s-ui && npm test` — 75 passed (7 new for `useDismissable`)
  • `cd web && npm run tsc` — clean
  • `cd web && npm run build` — clean

Made with Cursor


Note

Medium Risk
Changes global event-listener behavior for overlay dismissal (including switching to document-level pointerdown and adding popstate handling), which could affect interaction timing or close overlays unexpectedly if container refs are misconfigured.

Overview
Introduces a reusable useDismissable hook (exported from packages/k8s-ui) that attaches global pointerdown, keydown (Escape), and popstate listeners to dismiss transient overlays, with opt-outs and container refs to treat multiple elements as “inside”.

Updates UserMenu to use useDismissable instead of its ad-hoc outside-click useEffect, fixing the menu staying open across route changes. Updates NamespaceSelector to close on popstate and removes the viewport-wide backdrop so outside clicks dismiss without swallowing the underlying navigation click.

Reviewed by Cursor Bugbot for commit 0fc6ff6. Bugbot is set up for automated code reviews on this repo. Configure here.

…ng nav clicks

Two routing-adjacent dismissal bugs (SKY-822):

7. Clicking a tab while a dropdown is open (e.g. Resources during the
   namespace dropdown) silently swallowed the click — no navigation,
   no apparent dropdown state change. Root cause: NamespaceSelector
   mounted a `fixed inset-0 z-[9998]` overlay above the entire viewport
   to detect outside clicks. The overlay's onClick closed the dropdown
   but, being above the nav, also ate the user's click — so Resources
   never received it.

8. Account menu (avatar dropdown) did not dismiss when navigating to a
   different page. Root cause: UserMenu lives in the app shell and
   survives router transitions, so its open `isOpen` state persisted
   across navigations. Nothing was listening for popstate.

Fixes:

- New shared `useDismissable` hook in `packages/k8s-ui/src/hooks/`
  covering pointerdown-outside, Escape, and popstate dismissal in one
  declarative call. 7 unit tests pin the listener-attachment contract.
- `UserMenu` now uses `useDismissable`, so the menu closes on outside
  click, Escape, AND route change.
- `NamespaceSelector`'s click-eating backdrop is removed — the existing
  document-level mousedown listener already handled outside clicks
  cleanly. With the backdrop gone, a click on e.g. the Resources nav
  while the dropdown is open closes the dropdown AND navigates, which
  is what the user expects.
- `NamespaceSelector` also gets a popstate listener so the dropdown
  closes on browser navigation.

Linear: SKY-822
Made-with: Cursor
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit b48ca0a. Configure here.

Comment thread packages/k8s-ui/src/hooks/useDismissable.ts Outdated
Cursor Bugbot caught the mismatch: the comment, JSDoc, and handler
name all reference `pointerdown` (chosen so we'd cover touch + pen
in addition to mouse), but the addEventListener call was registering
for `mousedown`. The touch/pen benefits described in the comment
weren't actually delivered.

Switch the listener to `pointerdown` and update the handler signature
to `PointerEvent`. PointerEvent is supported across all browsers radar
targets (Chromium, Safari 13+, Firefox 59+).

Made-with: Cursor
@eliran-ops
Copy link
Copy Markdown
Contributor Author

@nadaverell @hisco — ready for review. Cursor bugbot found 1 issue on an earlier commit (addEventListener('mousedown') instead of pointerdown); fixed in commit 0fc6ff6. Cursor Bugbot SUCCESS on current HEAD.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants