Skip to content

Allow changing initially focused button in ConfirmationDialog - #6843

Merged
camchenry merged 8 commits into
mainfrom
camchenry/confirm-dialog-initial-focus-button
Sep 15, 2025
Merged

Allow changing initially focused button in ConfirmationDialog#6843
camchenry merged 8 commits into
mainfrom
camchenry/confirm-dialog-initial-focus-button

Conversation

@camchenry

@camchenrycamchenry commented Sep 12, 2025

Copy link
Copy Markdown
Contributor

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

@changeset-bot

changeset-botBot commented Sep 12, 2025

Copy link
Copy Markdown

🦋 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
NameType
@primer/reactMinor
@primer/styled-reactMajor

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

@github-actions

Copy link
Copy Markdown
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-actionsgithub-actionsBot 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
@github-actions

github-actionsBot commented Sep 12, 2025

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize
packages/react/dist/browser.esm.js89.47 KB (-0.17% 🔽)
packages/react/dist/browser.umd.js89.58 KB (+0.02% 🔺)

@github-actions
github-actionsBottemporarily 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 ownerSeptember 12, 2025 16:25

CopilotAI 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.

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
FileDescription
packages/react/src/ConfirmationDialog/ConfirmationDialog.tsxAdds initialFocusButton prop and updates focus logic to use it
packages/react/src/ConfirmationDialog/ConfirmationDialog.test.tsxAdds test for overriding dangerous button focus behavior
packages/react/src/ConfirmationDialog/ConfirmationDialog.docs.jsonDocuments the new initialButtonFocus prop
packages/react/src/ConfirmationDialog/useConfirm.hookDocs.jsonDocuments the new initialButtonFocus option for the hook
.changeset/wet-terms-argue.mdAdds changeset entry for the minor release

@github-actions
github-actionsBot requested a deployment to storybook-preview-6843 September 15, 2025 13:49 Abandoned
Comment threadpackages/react/src/ConfirmationDialog/useConfirm.hookDocs.json Outdated

@TylerJDevTylerJDev left a comment

Copy link
Copy Markdown
Member

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 queueSep 15, 2025
github-merge-queueBot pushed a commit that referenced this pull request Sep 15, 2025
Co-authored-by: Pavithra Kodmad <pksjce@github.com>
Merged via the queue into main with commit f082c77Sep 15, 2025
42 of 43 checks passed
@camchenry
camchenry deleted the camchenry/confirm-dialog-initial-focus-button branch September 15, 2025 20:01
@primerprimerBot mentioned this pull request Sep 15, 2025
pksjce added a commit that referenced this pull request Sep 18, 2025
Co-authored-by: Pavithra Kodmad <pksjce@github.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-tests: recommendedThis 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.

4 participants

@camchenry@pksjce@TylerJDev