Skip to content

Fix Menu's Appearing Behind Home Content#394

Open
PauloMFJ wants to merge 5 commits into
datacommonsorg:mainfrom
madebypxlp:paulo/fix-menu-appearing-behind
Open

Fix Menu's Appearing Behind Home Content#394
PauloMFJ wants to merge 5 commits into
datacommonsorg:mainfrom
madebypxlp:paulo/fix-menu-appearing-behind

Conversation

@PauloMFJ

@PauloMFJ PauloMFJ commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Overview

Implemented Portal element to fix open Menu showing behind home content.

Fixed focus events in InFrontOfCanvas getting consumed by tldraw. To do so implemented new capture config option on useKeyDown.

Re-ordered zoom options:
image

Tickets:
image
image

@PauloMFJ PauloMFJ self-assigned this Jul 6, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new Portal primitive to lift canvas elements above tldraw's stacking context, refactors the Menu component, and updates the useFocusTrap and useKeydown hooks to improve keyboard navigation. Key feedback includes: avoiding a global capture-phase listener in useKeydown to prevent breaking event propagation, optimizing the Portal component to prevent DOM recreation and state loss on className changes, retaining the focus trap in the Menu component for accessibility, and refining the tabbable elements selector in useFocusTrap to support all non-negative tab indices.

Comment thread dataweaver/apps/web/src/hooks/use_keydown.ts Outdated
Comment thread dataweaver/apps/web/src/components/primitives/portal.tsx
Comment thread dataweaver/apps/web/src/components/elements/menu.tsx
Comment thread dataweaver/apps/web/src/components/elements/menu.tsx
Comment thread dataweaver/apps/web/src/hooks/use_focus_trap.ts

@nick-nlb nick-nlb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thank you Paulo - a couple of comments before merging, but otherwise looks great.


useEffect(() => {
const element = document.createElement('div');
if (className) element.className = className;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This effect really does two things. Assuming that the className might change independently of the initial mounting, this triggers the mounting (ie.. setMountedElement) when the class changes. We can separate these into two separate effects, a primary mounting effect and a secondary className change effect.

return () => removeListener(eventTarget, listener, capture);
}
}, [config.isEnabled, config.target, keyCode, callback]);
}, [config.isEnabled, config.target, config.capture, keyCode, callback]);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If the callback is not memoized coming in to this, then we might see a significant amount of churn here. This isn't new to this PR, but something to flag for later.


useKeydown('Escape', onClose);

// TODO: For now this doesn't seem to really work due to TLDraw consuming

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This comment also exists in menu_chart_options.tsx and can be removed from there as well.

const QUERIES = new Map<EventTarget, Query>();
// Capture-phase and bubble-phase listeners require separate `addEventListener`
// registrations on the same target, so each phase gets its own registry.
const BUBBLE_QUERIES = new Map<EventTarget, Query>();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since we are using DOM elements as keys, let's update this to a WeakMap (it shouldn't matter in this particular case, but generally, it will allow a safety-net for garbage collection where destroyed DOM elements can be garbage-collected and removed from the map automatically).

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