Skip to content

fix(Button, IconButton, ToggleButton): a held Enter key is one press - #9997

Open
HelloOjasMutreja wants to merge 1 commit into
meta:mainfrom
HelloOjasMutreja:fix/button-enter-repeat
Open

HelloOjasMutreja wants to merge 1 commit into
meta:mainfrom
HelloOjasMutreja:fix/button-enter-repeat

Conversation

@HelloOjasMutreja

Copy link
Copy Markdown
Contributor

Fixes #8944

User impact

Holding Enter on a Button, IconButton or ToggleButton activates it once per keyboard auto-repeat, because a native <button> clicks on every repeated Enter keydown. A held Enter on a ToggleButton flips it about 30 times a second and leaves it in whichever state the key comes up on. On a Button it runs onClick or an interruptible clickAction many times, which can add rows, step a counter or send a message more than once.

Problem and solution fit

Button had no check for KeyboardEvent.repeat. Its only key handler ran when the button was aria-disabled, and the click path cannot tell a repeat from a press. IconButton and ToggleButton render Button, so one change covers all three. Button now cancels an Enter keydown with repeat set, after the caller's own onKeyDown has seen it.

Expected behavior and authority

A held key is one press. Astryx already rejects auto-repeat activation elsewhere: DropdownMenu and ContextMenu ignore repeated keys, and Table activation states "Keyboard auto-repeat never activates" in useTableActivation.spec.md FR8. This applies the same rule to the Button family.

Smallest restoration

Only Button.tsx changes. The key handler is always attached now (it was attached only while aria-disabled), and the aria-disabled behavior is unchanged: Enter and Space are still suppressed and other keys still reach the caller. For a button that is not aria-disabled the handler calls the caller's onKeyDown first, then cancels an Enter repeat. Space is untouched because a native button clicks on its key-up. No new props or API.

Evidence

  • Reproduction before the change: the issue's held-Enter repro. In Chromium, holding Enter on a plain native <button> (Playwright, one key-down then nine auto-repeated key-downs, then the key-up) produced 10 clicks.
  • Result after the change: the same page with an onkeydown that calls preventDefault() on an Enter repeat produced 1 click.
  • Representative unchanged path: a caller onKeyDown still receives every keydown including the repeats, a non-Enter repeat such as ArrowDown is not cancelled, and the aria-disabled tests for Enter and Space still pass.
  • Regression test or other mutation-sensitive proof: five new cases in Button.test.tsx and ToggleButton.test.tsx. Three of them (the button, the link and the ToggleButton cases) fail on current main and pass here.

Scope

  • One defect is restored.
  • Separable contradictory or unsettled tagalongs were removed or split.
  • No new public API, visual representation, default, or interaction model is hidden under the bug-fix label.
  • Public text and artifacts contain no internal Meta context.

Testing

  • npx vitest run packages/core/src/Button packages/core/src/ToggleButton packages/core/src/IconButton: 6 files, 228 tests pass. ButtonGroup, Toolbar, SegmentedControl and Pagination: 7 files, 317 tests pass.
  • npx tsc --noEmit -p packages/core/tsconfig.json and strict ESLint on the changed files: clean.
  • The Chromium check above ran against a plain native <button> with the same guard, not against the built Astryx component, so it shows the mechanism (cancelling the repeat keydown stops the repeated click). The unit tests exercise the real component through fireEvent, whose return value is false when the keydown's default was prevented.

@vercel

vercel Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 9, 2026 11:03am UTC

Request Review

@github-actions github-actions Bot added community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge labels Nov 4, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 4, 2026
@astracat-bot

astracat-bot Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
❓ Needs maintainer input (for maintainers only) Nov 11, 2026, 8:13 AM UTC

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 99a9e1c

Storybook · Sandbox · built from this PR's head

Modified components

Component Size LoC Visual · A11y · RTL
Button · Storybook 60.4 kB (not measured) · 10.0 kB CSS (not measured) 691 (not measured) ✓ · ✓ · ✗
AlertDialog 105.6 kB (not measured) · 14.6 kB CSS (not measured) — — · — · —
AppShell 91.0 kB (not measured) · 13.5 kB CSS (not measured) — — · — · —
73 more components
Component Size LoC Visual · A11y · RTL
Banner 62.4 kB (not measured) · 10.5 kB CSS (not measured) — — · — · —
BaseTypeahead 71.2 kB (not measured) · 10.9 kB CSS (not measured) — — · — · —
BreadcrumbItem 84.8 kB (not measured) · 12.1 kB CSS (not measured) — — · — · —
Calendar 71.4 kB (not measured) · 10.6 kB CSS (not measured) — — · — · —
Carousel 70.0 kB (not measured) · 10.9 kB CSS (not measured) — — · — · —
ChatComposer 78.4 kB (not measured) · 12.0 kB CSS (not measured) — — · — · —
ChatComposerInput 76.0 kB (not measured) · 11.3 kB CSS (not measured) — — · — · —
ChatComposerTokenElement 76.0 kB (not measured) · 11.3 kB CSS (not measured) — — · — · —
ChatDictationButton 61.0 kB (not measured) · 10.0 kB CSS (not measured) — — · — · —
ChatLayout 83.0 kB (not measured) · 10.5 kB CSS (not measured) — — · — · —
ChatLayoutScrollButton 60.9 kB (not measured) · 10.2 kB CSS (not measured) — — · — · —
ChatSendButton 60.8 kB (not measured) · 10.0 kB CSS (not measured) — — · — · —
CodeBlock 75.4 kB (not measured) · 11.3 kB CSS (not measured) — — · — · —
ComplexSelector 71.1 kB (not measured) · 11.8 kB CSS (not measured) — — · — · —
ContextMenu 108.4 kB (not measured) · 17.4 kB CSS (not measured) — — · — · —
DateInput 186.9 kB (not measured) · 17.0 kB CSS (not measured) — — · — · —
DateRangeInput 92.8 kB (not measured) · 12.5 kB CSS (not measured) — — · — · —
DateTimeInput 208.6 kB (not measured) · 18.7 kB CSS (not measured) — — · — · —
DialogHeader 63.2 kB (not measured) · 11.5 kB CSS (not measured) — — · — · —
DrawerHeader 63.4 kB (not measured) · 12.9 kB CSS (not measured) — — · — · —
DropdownMenu 97.3 kB (not measured) · 17.6 kB CSS (not measured) — — · — · —
FileInput 69.3 kB (not measured) · 10.9 kB CSS (not measured) — — · — · —
IconButton 60.5 kB (not measured) · 10.0 kB CSS (not measured) — — · — · —
Lightbox 122.6 kB (not measured) · 10.6 kB CSS (not measured) — — · — · —
Markdown 187.6 kB (not measured) · 20.6 kB CSS (not measured) — — · — · —
MobileNav 70.7 kB (not measured) · 10.6 kB CSS (not measured) — — · — · —
MobileNavToggle 60.7 kB (not measured) · 10.0 kB CSS (not measured) — — · — · —
MoreMenu 97.5 kB (not measured) · 17.6 kB CSS (not measured) — — · — · —
MultiSelector 94.9 kB (not measured) · 16.8 kB CSS (not measured) — — · — · —
NumberInput 71.9 kB (not measured) · 11.4 kB CSS (not measured) — — · — · —
Pagination 110.0 kB (not measured) · 17.8 kB CSS (not measured) — — · — · —
Popover 91.1 kB (not measured) · 14.2 kB CSS (not measured) — — · — · —
PowerSearch 287.2 kB (not measured) · 24.1 kB CSS (not measured) — — · — · —
Selector 99.9 kB (not measured) · 17.4 kB CSS (not measured) — — · — · —
SideNav 114.2 kB (not measured) · 11.4 kB CSS (not measured) — — · — · —
SideNavCollapseButton 61.3 kB (not measured) · 10.0 kB CSS (not measured) — — · — · —
SideNavHeading 75.7 kB (not measured) · 11.3 kB CSS (not measured) — — · — · —
SideNavItem 70.6 kB (not measured) · 11.1 kB CSS (not measured) — — · — · —
Stepper 62.0 kB (not measured) · 10.1 kB CSS (not measured) — — · — · —
Table 124.9 kB (not measured) · 18.3 kB CSS (not measured) — — · — · —
TableCell 109.7 kB (not measured) · 17.9 kB CSS (not measured) — — · — · —
TableHeaderCell 109.2 kB (not measured) · 17.7 kB CSS (not measured) — — · — · —
TableSelectionToolbar 70.7 kB (not measured) · 13.2 kB CSS (not measured) — — · — · —
TabMenu 71.9 kB (not measured) · 11.1 kB CSS (not measured) — — · — · —
TextInput 67.9 kB (not measured) · 11.2 kB CSS (not measured) — — · — · —
Thumbnail 64.8 kB (not measured) · 11.6 kB CSS (not measured) — — · — · —
TimeInput 162.4 kB (not measured) · 16.0 kB CSS (not measured) — — · — · —
Timestamp 33.2 kB (not measured) · 10.2 kB CSS (not measured) — — · — · —
Toast 98.3 kB (not measured) · 10.3 kB CSS (not measured) — — · — · —
ToggleButton 86.8 kB (not measured) · 10.1 kB CSS (not measured) — ✓ · ✓ · —
ToggleButtonGroup 39.2 kB (not measured) · 3.7 kB CSS (not measured) — ✓ · ✓ · ✓
Tokenizer 91.6 kB (not measured) · 18.8 kB CSS (not measured) — — · — · —
TopNav 72.4 kB (not measured) · 10.9 kB CSS (not measured) — — · — · —
TopNavHeading 75.3 kB (not measured) · 11.2 kB CSS (not measured) — — · — · —
TopNavMegaMenu 69.9 kB (not measured) · 11.8 kB CSS (not measured) — — · — · —
TopNavMenu 74.7 kB (not measured) · 11.2 kB CSS (not measured) — — · — · —
Typeahead 79.8 kB (not measured) · 12.4 kB CSS (not measured) — — · — · —
lab/ChatEmojiPicker 106.1 kB (not measured) · 773 B CSS (not measured) — — · — · —
lab/ChatReactionBar 107.2 kB (not measured) · 1.1 kB CSS (not measured) — — · — · —
lab/CommentComposer 151.9 kB (not measured) · 1.9 kB CSS (not measured) — — · — · —
lab/Comments 351.0 kB (not measured) · 2.5 kB CSS (not measured) — — · — · —
lab/CommentThread 344.1 kB (not measured) · 2.4 kB CSS (not measured) — — · — · —
lab/DialogHeroHeader 83.4 kB (not measured) · 372 B CSS (not measured) — — · — · —
lab/DiffViewer 87.4 kB (not measured) · 2.1 kB CSS (not measured) — — · — · —
lab/EmojiPicker 87.0 kB (not measured) · 751 B CSS (not measured) — — · — · —
lab/ListInput 88.4 kB (not measured) · 922 B CSS (not measured) — — · — · —
lab/Schedule 106.2 kB (not measured) · 3.9 kB CSS (not measured) — — · — · —
lab/TourStep 97.4 kB (not measured) · 590 B CSS (not measured) — — · — · —
lab/TransferList 101.7 kB (not measured) · 1.2 kB CSS (not measured) — — · — · —
lab/TransferListSelector 109.2 kB (not measured) · 1.4 kB CSS (not measured) — — · — · —
richtext/RichTextEditor 297.5 kB (not measured) · 2.6 kB CSS (not measured) — — · — · —
richtext/RichTextEditorToolbar 278.2 kB (not measured) · 454 B CSS (not measured) — — · — · —
richtext/RichTextView 276.4 kB (not measured) · 2.3 kB CSS (not measured) — — · — · —

Package size: measured; main has no measurement of the merge base to compare yet.

API changes: not compared: no built surface of the merge base; unknown: cli, core, theme-butter, theme-y2k

Touched components checked; add ci:run-visual, ci:run-a11y or ci:run-rtl to run the full suites.


Generated by PR Enrichment workflow | View full report

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approval waits on one engineering-owner decision; no code changes are requested.

  • No current Button-family spec says a held Enter is one press: component:Button AR2 and family:buttons FR2 only say Enter activates, and the no-repeat rule is written only for DropdownMenu, ContextMenu and Table row activation.
  • An engineering owner decides whether Button, and IconButton and ToggleButton through it (link mode included), takes that rule, which also makes Calendar, Carousel, Pagination and Stepper controls step once under a held Enter; they record it by commenting /approve-spec followed by the full head commit SHA on this pull request (the author may do so if they are an engineering owner).

The fix itself does what it says: the three new cancel tests fail on main and pass here, and in Chromium a held Enter now toggles a ToggleButton once instead of ten times. CI has not run yet; a maintainer adds the ci:run label so it runs.

[Automated review]

Comment thread packages/core/src/Button/Button.tsx Resolved
@HelloOjasMutreja

Copy link
Copy Markdown
Contributor Author

Could a maintainer add the ci:run label so CI runs on this head (8fa33be)? The four failing checks (lint, test, build, docsite-test) are the "Waiting for a maintainer's ci:run label" gate, not a failure in the change.

Verified locally at this head: the Button, ToggleButton and IconButton suites (228 tests), ButtonGroup, Toolbar, SegmentedControl and Pagination (317 tests), typecheck, and strict lint on the changed files.

…eta#8944)

A native button clicks on every auto-repeated Enter keydown, so a held Enter flipped a ToggleButton about 30 times a second and ran a Button's onClick or clickAction repeatedly. Button now cancels keydowns with repeat set for Enter after the caller's own onKeyDown has seen them.
@HelloOjasMutreja

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (99a9e1c), which had generalized the disabled-key handler to buttonDisabled. The held-Enter rule now sits in that same handler: a disabled button still cancels Enter and Space, every other keydown reaches the caller's onKeyDown first, and an auto-repeated Enter is cancelled after that. The diff against main is still the four files it was. Button, ToggleButton and IconButton suites pass (294 tests) and strict lint is clean for the changed files.

Approval still waits on an engineering owner's decision that a held Enter is one press, and CI needs a maintainer to add ci:run for this head.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approval waits on one engineering-owner decision; no code changes are requested.

  • No current Button-family spec says a held Enter is one press: component:Button AR2 and family:buttons FR2 only say Enter activates, and the no-repeat rule is written only for DropdownMenu, ContextMenu and Table row activation.
  • An engineering owner decides whether Button, and IconButton and ToggleButton through it (link mode included), takes that rule, which also makes Calendar, Pagination, Carousel and Stepper controls step once under a held Enter; they record it by commenting /approve-spec followed by the full head commit SHA on this pull request (the author may do so if they are an engineering owner).

After the rebase the fix still does what it says: the three new cancel tests fail on main and pass here, and in a real browser a held Enter now toggles a ToggleButton once instead of ten times. One non-blocking suggestion, a shorter code comment, is inline. CI has not run on this head yet; a maintainer adds the ci:run label so it runs.

[Automated review]

Comment on lines +815 to +817
// Otherwise a held Enter is one press: a native button clicks on every
// auto-repeated keydown, so the repeats are cancelled after the caller has
// seen them.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Non-blocking (comment style): this sentence runs 26 words, uses the passive "the repeats are cancelled", and carries two topics. A shorter version that keeps only the browser quirk and the reason:

// A native button clicks on each auto-repeated Enter keydown. Cancel each
// repeat after the caller's handler, so a held Enter is one press.

@cixzhang cixzhang added the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 11, 2026
@cixzhang
cixzhang marked this pull request as draft November 11, 2026 08:13
@cixzhang
cixzhang marked this pull request as ready for review November 11, 2026 08:14
@cixzhang cixzhang removed the ci:run A maintainer lets this outside contributor's pull request run CI (AST-030 FR17) label Nov 11, 2026

This branch was successfully deployed

1 active deployment
Preview — 99a9e1c4 Deployed Nov 9, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot. community Authored by a community contributor (not on the eng/design team) needs:code-review High-risk change (new package/component/API) — needs human code review before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Button, IconButton, ToggleButton: holding Enter activates once per key repeat

2 participants