Skip to content

fix: prevent disabled Button rendered as an anchor from firing onClick - #5413

Open
zigzagdev wants to merge 2 commits into
uber:mainfrom
zigzagdev:fix/button-disabled-anchor-keyboard
Open

fix: prevent disabled Button rendered as an anchor from firing onClick#5413
zigzagdev wants to merge 2 commits into
uber:mainfrom
zigzagdev:fix/button-disabled-anchor-keyboard

Conversation

@zigzagdev

Copy link
Copy Markdown
Contributor

Description

internalOnClick only checked isLoading before invoking the user's onClick handler.
When Button is rendered as an <a href> (by passing href) with disabled set, it stays keyboard-operable — native <a> elements ignore the disabled attribute entirely (unlike <button>), so Tab + Enter (or a click) still fired onClick and followed the link.
Guard on disabled the same way isLoading is already guarded, preventing the default action and skipping the handler.

Scope

Patch: Bug Fix

internalOnClick only checked isLoading before invoking the user's
onClick handler. A Button rendered as an <a href> with disabled set
stays keyboard-operable (native <a> elements ignore the disabled
attribute), so Tab + Enter still fired onClick and navigated. Guard
on disabled the same way isLoading is guarded, preventing the default
action and skipping the handler.
Regression test for a disabled Button rendered as <a href> — clicking
it (which is how Tab + Enter activates an anchor) must not call the
provided onClick handler.
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.

1 participant