Skip to content

[useButton] Avoid checking disabled twice in onKeyDown and onKeyUp - #4132

Merged
flaviendelangle merged 4 commits into
mui:masterfrom
flaviendelangle:useButton-onKeyDown
Feb 19, 2026
Merged

flaviendelangle merged 4 commits into
mui:masterfrom
flaviendelangle:useButton-onKeyDown

Conversation

@flaviendelangle

@flaviendelangle flaviendelangle commented Feb 18, 2026 •

Copy link
Copy Markdown
Member

Tiny improvements on useButton:

  • Do not compute isSpaceKey and isEnterKey if shouldClick is false
  • Add early return in onKeyDown and onKeyUp when disabled is true since there is no behavior applied anyway
  • Remove a useStableCallback that was only used in one place and didn't access any thing in the scope except a ref

@flaviendelangle flaviendelangle self-assigned this Feb 18, 2026
@flaviendelangle flaviendelangle added component: button Changes related to the button component. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. labels Feb 18, 2026
@pkg-pr-new

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

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

  • vite-css-base-ui-example

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

commit: 02a00cc

@flaviendelangle flaviendelangle changed the title [useButton] Avoid checking disabled twice in onKeyDown [useButton] Avoid checking disabled twice in onKeyDown and onKeyUp Feb 18, 2026
@mui-bot

mui-bot commented Feb 18, 2026 •

Copy link
Copy Markdown

Bundle size report

Bundle Parsed size Gzip size
@base-ui/react ▼-19B(0.00%) 0B(0.00%)

Details of bundle changes


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

@netlify

netlify Bot commented Feb 18, 2026

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit f9eaea6
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6995a794b60e6300094e73f7
😎 Deploy Preview https://deploy-preview-4132--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.

@netlify

netlify Bot commented Feb 18, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 02a00cc
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6995a93f5ca6a900089e075d
😎 Deploy Preview https://deploy-preview-4132--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.

// Keyboard accessibility for non interactive elements
const shouldClick =
event.target === event.currentTarget &&
!isNativeButton &&

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Is this check really needed since we throw an error when isNativeButton is true and the element is actually a link. 👀

@flaviendelangle
flaviendelangle marked this pull request as ready for review February 18, 2026 12:02
@flaviendelangle
flaviendelangle merged commit 377b88b into mui:master Feb 19, 2026
7 checks passed
@flaviendelangle
flaviendelangle deleted the useButton-onKeyDown branch February 19, 2026 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: button Changes related to the button component. 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.

3 participants