Skip to content

[all components] Fire Space activation on keydown for composite widgets - #4053

Merged
atomiks merged 3 commits into
mui:masterfrom
atomiks:codex/composite-space-keydown
Mar 4, 2026
Merged

atomiks merged 3 commits into
mui:masterfrom
atomiks:codex/composite-space-keydown

Conversation

@atomiks

@atomiks atomiks commented Feb 12, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #4051 - matches macOS behavior for composite widgets
Closes #1746

@atomiks atomiks added type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. scope: all components Widespread work has an impact on almost all components. labels Feb 12, 2026
@pkg-pr-new

pkg-pr-new Bot commented Feb 12, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/@base-ui/react@4053
    
    pnpm add https://pkg.pr.new/@base-ui/utils@4053
    

commit: acc0dd1

@mui-bot

mui-bot commented Feb 12, 2026 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react 🔺+710B(+0.16%) 🔺+239B(+0.16%)

Details of bundle changes


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

@netlify

netlify Bot commented Feb 12, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 61995bd
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/69a7e1613eef310008eb9a4a
😎 Deploy Preview https://deploy-preview-4053--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@atomiks
atomiks force-pushed the codex/composite-space-keydown branch 5 times, most recently from 9c4a3b1 to 4eae91a Compare February 12, 2026 06:39
@atomiks
atomiks marked this pull request as ready for review February 13, 2026 08:41
@greptile-apps

greptile-apps Bot commented Feb 13, 2026

Copy link
Copy Markdown
Contributor

Greptile Overview

Greptile Summary

This PR changes Space key activation from keyup to keydown for composite widgets (menus, selects, comboboxes) to match macOS behavior. The implementation adds a composite prop to useButton that controls when Space activates a button, and updates the typeahead logic to prevent Space from activating items during typeahead sessions.

Key changes:

  • useButton now accepts a composite prop that makes Space fire on keydown instead of keyup
  • Menu items, select items, and combobox items now pass composite: true to useButton
  • Typeahead logic moved from keyup to keydown to work with the new activation timing
  • During typeahead, Space is prevented from triggering activation via event.preventDefault()
  • Comprehensive test coverage added for all scenarios

Confidence Score: 4/5

  • This PR is safe to merge with minor scrutiny needed for the complex keyboard event handling logic
  • The changes are well-tested and follow a clear pattern across components. The main complexity is in useButton.ts where the keydown/keyup logic needs careful review to ensure no edge cases were missed. The typeahead integration is sound.
  • Pay close attention to packages/react/src/use-button/useButton.ts - the keyboard event handling logic is complex with multiple conditionals

Important Files Changed

Filename Overview
packages/react/src/use-button/useButton.ts Adds composite prop to change Space key activation from keyup to keydown for composite widgets. Logic is complex but appears correct.
packages/react/src/menu/item/useMenuItem.ts Passes composite: true to useButton and prevents Space default during typeahead on keydown instead of keyup.
packages/react/src/select/item/SelectItem.tsx Passes composite: true to useButton and prevents Space default during typeahead on keydown.
packages/react/src/floating-ui-react/hooks/useTypeahead.ts Refactors Space key handling to work with keydown activation - moves logic from keyup to keydown handler.

Last reviewed commit: 4eae91a

@atomiks
atomiks force-pushed the codex/composite-space-keydown branch from 4eae91a to 264a1fe Compare February 18, 2026 06:30
@github-actions github-actions Bot added PR: out-of-date The pull request has merge conflicts and can't be merged. and removed PR: out-of-date The pull request has merge conflicts and can't be merged. labels Feb 19, 2026
@atomiks

atomiks commented Mar 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Codex Review

Overview

This branch moves composite-widget Space activation from keyup to keydown across useButton consumers (menu/select/combobox/link paths), and aligns typeahead behavior so active text navigation sessions can include spaces without accidental activation. The latest updates also centralize the menu typeahead Space guard and fix the toolbar switch regression by scoping the defaultPrevented suppression to text-navigation roles.

Findings (None)

No blocking issues found in this patch.

Confidence: 4/5

High confidence based on a full-branch review (upstream/master...head), targeted behavior checks of the updated keyboard paths, and focused verification of the prior CI failure mode.

Notes

  • Full branch scope reviewed, not only incremental commits.
  • The prior CI failure in ToolbarButton was addressed by narrowing composite Space suppression to text-navigation roles (menuitem*, option, gridcell) while preserving switch activation semantics.
  • Perf spot-check executed on representative old/new keydown decision paths (synthetic Node micro-check, 5,000,000 iterations): old=16.94ms, new=47.57ms (about 6.13ns additional work per dispatch in the check).

@atomiks
atomiks force-pushed the codex/composite-space-keydown branch from cf3fc97 to d97a48c Compare March 4, 2026 07:19
@atomiks
atomiks force-pushed the codex/composite-space-keydown branch from 10cf076 to 7080b28 Compare March 4, 2026 07:27
@atomiks
atomiks merged commit bf30969 into mui:master Mar 4, 2026
6 checks passed
@atomiks
atomiks deleted the codex/composite-space-keydown branch March 4, 2026 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: all components Widespread work has an impact on almost all components. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[composite] Fire Space key activation on keydown not keyup [menu] Should link menu items navigate to their href when pressing Space?

2 participants