Skip to content

fix(menu): avoid focusing hidden anchors on mount - #5139

Open
KuroGeo wants to merge 2 commits into
callstack:mainfrom
KuroGeo:fix/menu-focus-on-hidden-mount
Open

KuroGeo wants to merge 2 commits into
callstack:mainfrom
KuroGeo:fix/menu-focus-on-hidden-mount

Conversation

@KuroGeo

@KuroGeo KuroGeo commented Oct 9, 2026 •

Copy link
Copy Markdown

Motivation

Closed menus steal focus on mount and scroll async lists. Initialize previous visibility from visible, preserving focus on open/close.

Related issue

Closes #4907

Screenshots / Videos

Append 30 closed menus: before, focus moves to Menu 29 and scroll reaches 1620px; after, focus stays on the append button and scroll stays at 0.

Before
After

Test plan

Append closed menus: focus/scroll stay put. Open: first item focuses. Escape: anchor focuses. Chrome checked.

695 tests and 234 snapshots pass; lint/typecheck pass. Hidden-mount regression fails before the fix.

Repro and DOM checks

Comment thread src/components/__tests__/Menu.test.tsx Outdated
it('moves focus when opened and restores it when closed', async () => {
const { rerender } = await render(makeMenu(false));
await rerender(makeMenu(true));
await act(() => jest.advanceTimersByTime(300));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: instead of using a magic number 300, I'd create a constant like:

const PAST_ANIMATION_MS = 300; 

this explains the value

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed in b04739b: all four web-focus timer advances now use PAST_ANIMATION_MS = 300.

@ziarno ziarno left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

lgtm, added one comment with a nit

This branch has not been deployed

No deployments
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.

[Web] Menu anchor inside lists causes aggressive auto-scroll and focus hijacking on mount

2 participants