Skip to content

Token: respect canceled keyboard removal events - #8659

Open
wBaob wants to merge 1 commit into
primer:mainfrom
wBaob:fix/token-canceled-keyboard-removal
Open

wBaob wants to merge 1 commit into
primer:mainfrom
wBaob:fix/token-canceled-keyboard-removal

Conversation

@wBaob

@wBaob wBaob commented Nov 1, 2026

Copy link
Copy Markdown

TokenBase calls the consumer's onKeyDown handler before handling Backspace and Delete, but still calls onRemove when that handler cancels the event. Consumers therefore cannot intercept either key without also removing the token.

Return when the event is defaultPrevented. The shared fix covers Token and IssueLabelToken and includes a patch changeset.

Changelog

Changed

  • Respect canceled Backspace and Delete events before removing a Token or IssueLabelToken.

Rollout strategy

  • Not sure (open-source contributor)

Testing & Reviewing

  • Token suite: 35 tests pass in Chromium. Four cancellation regressions fail on main and pass with the fix; companion cases verify that uncanceled keys still remove tokens.
  • Package and root TypeScript checks, scoped ESLint, Prettier, and git diff --check pass.
  • Local browser tests used the existing Chromium installation through an uncommitted runner config.

No visual styles change. To reproduce, provide both onRemove and an onKeyDown handler that calls event.preventDefault(), then press Backspace or Delete on the token.

Copilot AI balanced review requested due to automatic review settings November 1, 2026 17:04
@wBaob
wBaob requested a review from a team as a code owner November 1, 2026 17:04
@wBaob
wBaob requested a review from liuliu-dev November 1, 2026 17:04
@changeset-bot

changeset-bot Bot commented Nov 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 79c5a03

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch was successfully deployed

1 active deployment
github-pages — 79c5a03a Deployed Nov 1, 2026 by wBaob via deploy-preview #30296
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.

2 participants