Skip to content

[menu] Add initialFocus prop to Menu.Popup - #5189

Closed
kylemcd wants to merge 1 commit into
mui:masterfrom
kylemcd:fix/menu-popup-initial-focus
Closed

kylemcd wants to merge 1 commit into
mui:masterfrom
kylemcd:fix/menu-popup-initial-focus

Conversation

@kylemcd

@kylemcd kylemcd commented Jul 8, 2026 •

Copy link
Copy Markdown

Menu.Popup hardcodes initial focus on its focus manager, so there's no way to stop the popup grabbing focus on open. Popover.Popup and Dialog.Popup already expose initialFocus for exactly this — this adds the same prop to Menu.Popup.

motivation: a trigger that renders a typeable input (combobox-style) can't keep focus when the menu opens, since the popup always pulls focus inside. initialFocus={false} lets the consumer opt out.

  • forwards initialFocus to FloatingFocusManager, same type/JSDoc as Popover/Dialog
  • default is unchanged: undefined still resolves to parent.type !== 'menu', so it's a no-op unless set
  • deliberately did not reuse createDefaultInitialFocus like popover/dialog — that adds touch/virtual-keyboard handling menus don't have today, which would change behavior
  • adds tests + regenerates the types.md tables (menu + context-menu)

test plan

pnpm test:jsdom on MenuPopup.test.tsx — 23 pass, incl. two new cases: default focuses the first item, and initialFocus={false} keeps focus on the trigger

@kylemcd
kylemcd marked this pull request as ready for review July 8, 2026 22:43
@pkg-pr-new

pkg-pr-new Bot commented Jul 8, 2026

Copy link
Copy Markdown

commit: ef999c3

@code-infra-dashboard

code-infra-dashboard Bot commented Jul 8, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+37B(+0.01%) 🔺+13B(+0.01%)

Details of bundle changes

Performance

Total duration: 1,150.04 ms -1.81 ms(-0.2%) | Renders: 78 (+0)

Test Duration Renders
Checkbox mount (500 instances) 77.75 ms 🔺+17.07 ms(+28.1%) 1 (+0)
Tooltip mount (300 contained roots) 45.96 ms ▼-15.34 ms(-25.0%) 1 (+0)

12 tests within noise — details

Metric alarms

Test Metric Change
Checkbox mount (500 instances) bench:paint 🔺 +23.23 ms

Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Jul 8, 2026

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit ef999c3
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a4ed225264b0900083a30bc
😎 Deploy Preview https://deploy-preview-5189--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@aarongarciah

aarongarciah commented Jul 10, 2026 •

Copy link
Copy Markdown
Member

@kylemcd can you share some screenshots/wireframes of what you're trying to build to better understand the motivation? If I understood correctly, you are using an input as a Menu trigger, but I want to understand why you didn't reach for Autocomplete in this case.

@aarongarciah

aarongarciah commented Jul 10, 2026 •

Copy link
Copy Markdown
Member

I just noticed https://telegraph-storybook-git-kyle-kno-14086-telegra-21a570-knocklabs.vercel.app/?path=/story/components-menu--typeable-trigger from knocklabs/telegraph#869. Although I not have the necessary context, looking at that Storybook link it looks like Autocomplete might be what you're looking for.

image

@kylemcd

kylemcd commented Jul 10, 2026 •

Copy link
Copy Markdown
Author

@aarongarciah

yeah here's some context, but feel free to close this if there isn't utility in it for anyone else.

we recently completed a radix to base ui migration for our component library telegraph. within telegraph we have the menu component which under the hood used radix's internal menu API so that we could get the keyboard / focus management a11y for free. within the knock dashboard, we have this super complex variable selector component that utilized the radix menu to get some of the keyboard management for free (see screenshot). this component does a lot of heavy lifting across our dashboard and refactoring that carries a ton of risk we're not wanting to take on right now. (eventually though you're right, we should migrate to the base ui autocomplete component)

Screenshot 2026-07-10 at 07-59-55

the base-ui menu fit the bill perfectly besides not being able to manage the initial focus. in the popover and dialog components, there's the initialFocus prop available which we're able to use to create a shim to manage auto focus in the same way that radix did, see this bit of code: https://github.com/knocklabs/telegraph/blob/13c3aa24c301d33a00701376ed54eca70205da0d/packages/popover/src/Popover/Popover.tsx#L232

because the base ui menu component doesn't allow for setting this prop in the same way dialog and popover does, we have to write this gross code in order to manage the focus in a way that doesn't break the variable selector code for example, see code: https://github.com/knocklabs/telegraph/pull/869/changes#diff-68ffc570fefcc972b7f997962aae62f5d4fc8be21fa7522ebb47128900d48dd8

so the ask is just to have parity between these. (there's already access to the finalFocus prop on the menu) maybe there's a reason why we wouldn't want the initiaFocus prop available to be set or maybe was just a consistency miss? either way it would help us immensely to have a more predictable focus code path for the menu.

@aarongarciah

Copy link
Copy Markdown
Member

From what you describe, it looks like you're after Autocomplete (or Combobox, depending on the exact UX). The problem with the pattern you're using (Menu with typeable trigger) is that it breaks the WAI-ARIA pattern: the trigger is supposed to be a button, and the focus always moves focus to the first or last menu item (see https://www.w3.org/WAI/ARIA/apg/patterns/menu-button/#keyboardinteraction).

Since the focus must always be moved to a menu item, there wasn't a use case for initialFocus AFAIK. There's been some discussions around an imperative API like highlightItem('first' | 'last' | 'none') (#4815) to have control when the menu is programmatically opened, which keeps being WAI-ARIA compliant, but that's not related to your pattern.

In short, it's unlikely we merge this since there's no use case for initialFocus.

@aarongarciah

Copy link
Copy Markdown
Member

Thanks for the PR @kylemcd, but we won't go ahead with it as we don't think there's a good use case for initialFocus on Menu.Popup.

kylemcd added a commit to knocklabs/telegraph that referenced this pull request Jul 30, 2026
…nce (KNO-14119)

Reframe the typeable-input-inside-`Menu.Trigger` composition as a deprecated
legacy recipe across the menu package, pointing new UI at `@telegraph/combobox`'s
input-as-trigger arrangement. No runtime change — the focus-bounce that keeps
focus in place when a consumer prevents `onOpenAutoFocus` is retained byte-for-
byte as permanent Radix-compat behavior.

- Story: rename to "Typeable Trigger (deprecated)" and rewrite its doc comment
  as a deprecation notice linking the combobox input-as-trigger story.
- Fixture / test / browser-test: keep as focus-bounce regression coverage,
  reframe the JSDoc and describe names to the behavior under test (Radix-compat
  prevented-onOpenAutoFocus), keeping the KNO-14086 repro context.
- `Menu.tsx`: rewrite the bounce comment to describe permanent Radix-compat
  behavior instead of a shim pending an upstream `initialFocus` opt-out.
- Add a patch changeset.

Upstream housekeeping (close mui/base-ui#5189, delete the fork branch) is done
separately outside the repo.
kylemcd added a commit to knocklabs/telegraph that referenced this pull request Aug 25, 2026
…nce (KNO-14119)

Reframe the typeable-input-inside-`Menu.Trigger` composition as a deprecated
legacy recipe across the menu package, pointing new UI at `@telegraph/combobox`'s
input-as-trigger arrangement. No runtime change — the focus-bounce that keeps
focus in place when a consumer prevents `onOpenAutoFocus` is retained byte-for-
byte as permanent Radix-compat behavior.

- Story: rename to "Typeable Trigger (deprecated)" and rewrite its doc comment
  as a deprecation notice linking the combobox input-as-trigger story.
- Fixture / test / browser-test: keep as focus-bounce regression coverage,
  reframe the JSDoc and describe names to the behavior under test (Radix-compat
  prevented-onOpenAutoFocus), keeping the KNO-14086 repro context.
- `Menu.tsx`: rewrite the bounce comment to describe permanent Radix-compat
  behavior instead of a shim pending an upstream `initialFocus` opt-out.
- Add a patch changeset.

Upstream housekeeping (close mui/base-ui#5189, delete the fork branch) is done
separately outside the repo.
kylemcd added a commit to knocklabs/telegraph that referenced this pull request Aug 25, 2026
…nce (KNO-14119)

Reframe the typeable-input-inside-`Menu.Trigger` composition as a deprecated
legacy recipe across the menu package, pointing new UI at `@telegraph/combobox`'s
input-as-trigger arrangement. No runtime change — the focus-bounce that keeps
focus in place when a consumer prevents `onOpenAutoFocus` is retained byte-for-
byte as permanent Radix-compat behavior.

- Story: rename to "Typeable Trigger (deprecated)" and rewrite its doc comment
  as a deprecation notice linking the combobox input-as-trigger story.
- Fixture / test / browser-test: keep as focus-bounce regression coverage,
  reframe the JSDoc and describe names to the behavior under test (Radix-compat
  prevented-onOpenAutoFocus), keeping the KNO-14086 repro context.
- `Menu.tsx`: rewrite the bounce comment to describe permanent Radix-compat
  behavior instead of a shim pending an upstream `initialFocus` opt-out.
- Add a patch changeset.

Upstream housekeeping (close mui/base-ui#5189, delete the fork branch) is done
separately outside the repo.
kylemcd added a commit to knocklabs/telegraph that referenced this pull request Aug 25, 2026
…nce (KNO-14119)

Reframe the typeable-input-inside-`Menu.Trigger` composition as a deprecated
legacy recipe across the menu package, pointing new UI at `@telegraph/combobox`'s
input-as-trigger arrangement. No runtime change — the focus-bounce that keeps
focus in place when a consumer prevents `onOpenAutoFocus` is retained byte-for-
byte as permanent Radix-compat behavior.

- Story: rename to "Typeable Trigger (deprecated)" and rewrite its doc comment
  as a deprecation notice linking the combobox input-as-trigger story.
- Fixture / test / browser-test: keep as focus-bounce regression coverage,
  reframe the JSDoc and describe names to the behavior under test (Radix-compat
  prevented-onOpenAutoFocus), keeping the KNO-14086 repro context.
- `Menu.tsx`: rewrite the bounce comment to describe permanent Radix-compat
  behavior instead of a shim pending an upstream `initialFocus` opt-out.
- Add a patch changeset.

Upstream housekeeping (close mui/base-ui#5189, delete the fork branch) is done
separately outside the repo.
@kylemcd

kylemcd commented Aug 25, 2026

Copy link
Copy Markdown
Author

Thanks for the guidance here. We've now moved this typeable-trigger use case to a Combobox/Autocomplete-based implementation in Telegraph and deprecated the Menu-based recipe, so this can stay closed. I'll remove the fork branch as well.

@kylemcd
kylemcd deleted the fix/menu-popup-initial-focus branch August 25, 2026 16:01
kylemcd added a commit to knocklabs/telegraph that referenced this pull request Aug 25, 2026
…nce (KNO-14119)

Reframe the typeable-input-inside-`Menu.Trigger` composition as a deprecated
legacy recipe across the menu package, pointing new UI at `@telegraph/combobox`'s
input-as-trigger arrangement. No runtime change — the focus-bounce that keeps
focus in place when a consumer prevents `onOpenAutoFocus` is retained byte-for-
byte as permanent Radix-compat behavior.

- Story: rename to "Typeable Trigger (deprecated)" and rewrite its doc comment
  as a deprecation notice linking the combobox input-as-trigger story.
- Fixture / test / browser-test: keep as focus-bounce regression coverage,
  reframe the JSDoc and describe names to the behavior under test (Radix-compat
  prevented-onOpenAutoFocus), keeping the KNO-14086 repro context.
- `Menu.tsx`: rewrite the bounce comment to describe permanent Radix-compat
  behavior instead of a shim pending an upstream `initialFocus` opt-out.
- Add a patch changeset.

Upstream housekeeping (close mui/base-ui#5189, delete the fork branch) is done
separately outside the repo.
kylemcd added a commit to knocklabs/telegraph that referenced this pull request Aug 25, 2026
…nce (KNO-14119)

Reframe the typeable-input-inside-`Menu.Trigger` composition as a deprecated
legacy recipe across the menu package, pointing new UI at `@telegraph/combobox`'s
input-as-trigger arrangement. No runtime change — the focus-bounce that keeps
focus in place when a consumer prevents `onOpenAutoFocus` is retained byte-for-
byte as permanent Radix-compat behavior.

- Story: rename to "Typeable Trigger (deprecated)" and rewrite its doc comment
  as a deprecation notice linking the combobox input-as-trigger story.
- Fixture / test / browser-test: keep as focus-bounce regression coverage,
  reframe the JSDoc and describe names to the behavior under test (Radix-compat
  prevented-onOpenAutoFocus), keeping the KNO-14086 repro context.
- `Menu.tsx`: rewrite the bounce comment to describe permanent Radix-compat
  behavior instead of a shim pending an upstream `initialFocus` opt-out.
- Add a patch changeset.

Upstream housekeeping (close mui/base-ui#5189, delete the fork branch) is done
separately outside the repo.
kylemcd added a commit to knocklabs/telegraph that referenced this pull request Aug 25, 2026
…nce (KNO-14119)

Reframe the typeable-input-inside-`Menu.Trigger` composition as a deprecated
legacy recipe across the menu package, pointing new UI at `@telegraph/combobox`'s
input-as-trigger arrangement. No runtime change — the focus-bounce that keeps
focus in place when a consumer prevents `onOpenAutoFocus` is retained byte-for-
byte as permanent Radix-compat behavior.

- Story: rename to "Typeable Trigger (deprecated)" and rewrite its doc comment
  as a deprecation notice linking the combobox input-as-trigger story.
- Fixture / test / browser-test: keep as focus-bounce regression coverage,
  reframe the JSDoc and describe names to the behavior under test (Radix-compat
  prevented-onOpenAutoFocus), keeping the KNO-14086 repro context.
- `Menu.tsx`: rewrite the bounce comment to describe permanent Radix-compat
  behavior instead of a shim pending an upstream `initialFocus` opt-out.
- Add a patch changeset.

Upstream housekeeping (close mui/base-ui#5189, delete the fork branch) is done
separately outside the repo.
kylemcd added a commit to knocklabs/telegraph that referenced this pull request Aug 26, 2026
…nce (KNO-14119)

Reframe the typeable-input-inside-`Menu.Trigger` composition as a deprecated
legacy recipe across the menu package, pointing new UI at `@telegraph/combobox`'s
input-as-trigger arrangement. No runtime change — the focus-bounce that keeps
focus in place when a consumer prevents `onOpenAutoFocus` is retained byte-for-
byte as permanent Radix-compat behavior.

- Story: rename to "Typeable Trigger (deprecated)" and rewrite its doc comment
  as a deprecation notice linking the combobox input-as-trigger story.
- Fixture / test / browser-test: keep as focus-bounce regression coverage,
  reframe the JSDoc and describe names to the behavior under test (Radix-compat
  prevented-onOpenAutoFocus), keeping the KNO-14086 repro context.
- `Menu.tsx`: rewrite the bounce comment to describe permanent Radix-compat
  behavior instead of a shim pending an upstream `initialFocus` opt-out.
- Add a patch changeset.

Upstream housekeeping (close mui/base-ui#5189, delete the fork branch) is done
separately outside the repo.
kylemcd added a commit to knocklabs/telegraph that referenced this pull request Aug 26, 2026
…nce (KNO-14119)

Reframe the typeable-input-inside-`Menu.Trigger` composition as a deprecated
legacy recipe across the menu package, pointing new UI at `@telegraph/combobox`'s
input-as-trigger arrangement. No runtime change — the focus-bounce that keeps
focus in place when a consumer prevents `onOpenAutoFocus` is retained byte-for-
byte as permanent Radix-compat behavior.

- Story: rename to "Typeable Trigger (deprecated)" and rewrite its doc comment
  as a deprecation notice linking the combobox input-as-trigger story.
- Fixture / test / browser-test: keep as focus-bounce regression coverage,
  reframe the JSDoc and describe names to the behavior under test (Radix-compat
  prevented-onOpenAutoFocus), keeping the KNO-14086 repro context.
- `Menu.tsx`: rewrite the bounce comment to describe permanent Radix-compat
  behavior instead of a shim pending an upstream `initialFocus` opt-out.
- Add a patch changeset.

Upstream housekeeping (close mui/base-ui#5189, delete the fork branch) is done
separately outside the repo.
kylemcd added a commit to knocklabs/telegraph that referenced this pull request Aug 26, 2026
…nce (KNO-14119)

Reframe the typeable-input-inside-`Menu.Trigger` composition as a deprecated
legacy recipe across the menu package, pointing new UI at `@telegraph/combobox`'s
input-as-trigger arrangement. No runtime change — the focus-bounce that keeps
focus in place when a consumer prevents `onOpenAutoFocus` is retained byte-for-
byte as permanent Radix-compat behavior.

- Story: rename to "Typeable Trigger (deprecated)" and rewrite its doc comment
  as a deprecation notice linking the combobox input-as-trigger story.
- Fixture / test / browser-test: keep as focus-bounce regression coverage,
  reframe the JSDoc and describe names to the behavior under test (Radix-compat
  prevented-onOpenAutoFocus), keeping the KNO-14086 repro context.
- `Menu.tsx`: rewrite the bounce comment to describe permanent Radix-compat
  behavior instead of a shim pending an upstream `initialFocus` opt-out.
- Add a patch changeset.

Upstream housekeeping (close mui/base-ui#5189, delete the fork branch) is done
separately outside the repo.
kylemcd added a commit to knocklabs/telegraph that referenced this pull request Aug 27, 2026
…nce (KNO-14119)

Reframe the typeable-input-inside-`Menu.Trigger` composition as a deprecated
legacy recipe across the menu package, pointing new UI at `@telegraph/combobox`'s
input-as-trigger arrangement. No runtime change — the focus-bounce that keeps
focus in place when a consumer prevents `onOpenAutoFocus` is retained byte-for-
byte as permanent Radix-compat behavior.

- Story: rename to "Typeable Trigger (deprecated)" and rewrite its doc comment
  as a deprecation notice linking the combobox input-as-trigger story.
- Fixture / test / browser-test: keep as focus-bounce regression coverage,
  reframe the JSDoc and describe names to the behavior under test (Radix-compat
  prevented-onOpenAutoFocus), keeping the KNO-14086 repro context.
- `Menu.tsx`: rewrite the bounce comment to describe permanent Radix-compat
  behavior instead of a shim pending an upstream `initialFocus` opt-out.
- Add a patch changeset.

Upstream housekeeping (close mui/base-ui#5189, delete the fork branch) is done
separately outside the repo.
kylemcd added a commit to knocklabs/telegraph that referenced this pull request Aug 27, 2026
…nce (KNO-14119)

Reframe the typeable-input-inside-`Menu.Trigger` composition as a deprecated
legacy recipe across the menu package, pointing new UI at `@telegraph/combobox`'s
input-as-trigger arrangement. No runtime change — the focus-bounce that keeps
focus in place when a consumer prevents `onOpenAutoFocus` is retained byte-for-
byte as permanent Radix-compat behavior.

- Story: rename to "Typeable Trigger (deprecated)" and rewrite its doc comment
  as a deprecation notice linking the combobox input-as-trigger story.
- Fixture / test / browser-test: keep as focus-bounce regression coverage,
  reframe the JSDoc and describe names to the behavior under test (Radix-compat
  prevented-onOpenAutoFocus), keeping the KNO-14086 repro context.
- `Menu.tsx`: rewrite the bounce comment to describe permanent Radix-compat
  behavior instead of a shim pending an upstream `initialFocus` opt-out.
- Add a patch changeset.

Upstream housekeeping (close mui/base-ui#5189, delete the fork branch) is done
separately outside the repo.
kylemcd added a commit to knocklabs/telegraph that referenced this pull request Aug 27, 2026
…nce (KNO-14119)

Reframe the typeable-input-inside-`Menu.Trigger` composition as a deprecated
legacy recipe across the menu package, pointing new UI at `@telegraph/combobox`'s
input-as-trigger arrangement. No runtime change — the focus-bounce that keeps
focus in place when a consumer prevents `onOpenAutoFocus` is retained byte-for-
byte as permanent Radix-compat behavior.

- Story: rename to "Typeable Trigger (deprecated)" and rewrite its doc comment
  as a deprecation notice linking the combobox input-as-trigger story.
- Fixture / test / browser-test: keep as focus-bounce regression coverage,
  reframe the JSDoc and describe names to the behavior under test (Radix-compat
  prevented-onOpenAutoFocus), keeping the KNO-14086 repro context.
- `Menu.tsx`: rewrite the bounce comment to describe permanent Radix-compat
  behavior instead of a shim pending an upstream `initialFocus` opt-out.
- Add a patch changeset.

Upstream housekeeping (close mui/base-ui#5189, delete the fork branch) is done
separately outside the repo.
kylemcd added a commit to knocklabs/telegraph that referenced this pull request Sep 1, 2026
…nce (KNO-14119) (#917)

* docs(menu): deprecate the typeable-trigger recipe, keep the focus-bounce (KNO-14119)

Reframe the typeable-input-inside-`Menu.Trigger` composition as a deprecated
legacy recipe across the menu package, pointing new UI at `@telegraph/combobox`'s
input-as-trigger arrangement. No runtime change — the focus-bounce that keeps
focus in place when a consumer prevents `onOpenAutoFocus` is retained byte-for-
byte as permanent Radix-compat behavior.

- Story: rename to "Typeable Trigger (deprecated)" and rewrite its doc comment
  as a deprecation notice linking the combobox input-as-trigger story.
- Fixture / test / browser-test: keep as focus-bounce regression coverage,
  reframe the JSDoc and describe names to the behavior under test (Radix-compat
  prevented-onOpenAutoFocus), keeping the KNO-14086 repro context.
- `Menu.tsx`: rewrite the bounce comment to describe permanent Radix-compat
  behavior instead of a shim pending an upstream `initialFocus` opt-out.
- Add a patch changeset.

Upstream housekeeping (close mui/base-ui#5189, delete the fork branch) is done
separately outside the repo.

* docs(menu): link deprecated trigger alternative

* fix(menu): support buttons outside menu roots

* docs(menu): mark rootless button fallback transitional

* refactor(menu): keep render props as data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: menu Changes related to the menu component.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants