Skip to content

Conversation

camchenry
Copy link
Contributor

@camchenry camchenry commented Sep 12, 2025

Adds the ability to change the button that is initially focused when using ConfirmationDialog or useConfirm. The majority of the time the current default behavior is desirable: focus the confirm button unless the action is dangerous. However, there are some cases where we want to automatically focus the dangerous action button to remove friction from actions that are done repeatedly. Otherwise, the user needs to press RightArrow or Tab before every action which is tedious. This behavior should rarely be overridden, but the API should support changing this to make some actions easier for keyboard users.

CleanShot.2025-09-12.at.11.55.29.mp4

Changelog

New

  • Adds a overrideButtonFocus prop to ConfirmationDialog/useConfirm to change the button that is initially focused, overriding the default focus behavior

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

Nothing in particular: I've added an automated test for this behavior, and I've also manually validated the behavior in Storybook.

Merge checklist

Copy link

changeset-bot bot commented Sep 12, 2025

🦋 Changeset detected

Latest commit: e002671

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

This PR includes changesets to release 2 packages
Name Type
@primer/react Minor
@primer/styled-react Major

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

Copy link
Contributor

👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks!

@github-actions github-actions bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Sep 12, 2025
Copy link
Contributor

github-actions bot commented Sep 12, 2025

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 89.47 KB (-0.17% 🔽)
packages/react/dist/browser.umd.js 89.58 KB (+0.02% 🔺)

@github-actions github-actions bot temporarily deployed to storybook-preview-6843 September 12, 2025 16:24 Inactive
@camchenry camchenry marked this pull request as ready for review September 12, 2025 16:25
@camchenry camchenry requested a review from a team as a code owner September 12, 2025 16:25
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for customizing the initially focused button in ConfirmationDialog and useConfirm. By default, the confirm button is focused unless it's a dangerous action (in which case the cancel button is focused). The new feature allows overriding this behavior to improve keyboard user experience for repetitive actions.

  • Adds initialButtonFocus/initialFocusButton prop to override default focus behavior
  • Updates focus logic to use the new prop when provided
  • Adds comprehensive test coverage for the new functionality

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/react/src/ConfirmationDialog/ConfirmationDialog.tsx Adds initialFocusButton prop and updates focus logic to use it
packages/react/src/ConfirmationDialog/ConfirmationDialog.test.tsx Adds test for overriding dangerous button focus behavior
packages/react/src/ConfirmationDialog/ConfirmationDialog.docs.json Documents the new initialButtonFocus prop
packages/react/src/ConfirmationDialog/useConfirm.hookDocs.json Documents the new initialButtonFocus option for the hook
.changeset/wet-terms-argue.md Adds changeset entry for the minor release

@github-actions github-actions bot requested a deployment to storybook-preview-6843 September 15, 2025 13:49 Abandoned
Copy link
Member

@TylerJDev TylerJDev left a comment

Choose a reason for hiding this comment

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

LGTM!

@camchenry camchenry added this pull request to the merge queue Sep 15, 2025
github-merge-queue bot pushed a commit that referenced this pull request Sep 15, 2025
Merged via the queue into main with commit f082c77 Sep 15, 2025
42 of 43 checks passed
@camchenry camchenry deleted the camchenry/confirm-dialog-initial-focus-button branch September 15, 2025 20:01
@primer primer bot mentioned this pull request Sep 15, 2025
pksjce added a commit that referenced this pull request Sep 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants