-
Notifications
You must be signed in to change notification settings - Fork 598
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Focus the primary action in 'ConfirmationDialog' #1471
Conversation
🦋 Changeset detectedLatest commit: 96a667c The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
size-limit report 📦
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍 Thanks, @smockle!
Can you add a changeset?
Is there a way we can write a test to check if the confirm button is focused when the dialog is opened? It be nice to catch any accidental regressions in CI. |
From @colebemis in #1471 (comment):
Yes there is! Added tests in 3abb636. Check it out—the #1471 CI check passed, and the #1472 CI check failed—the new tests catch the problem with #1472! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good. For reference, I'm fairly certain that @T-Hugs set it up this way intentionally. If I remember correctly (it's been a while), the mindset was to not have users accidentally trigger the submit button, but instead require them to move focus to it and then trigger it. Maybe he will weigh in since this is OSS 😁. In any case, I'm fine with making the change as it does match the behavior of most confirmation dialogs out there in the world.
Indeed, the old behavior was intentional for the reason @dgreif stated. That said, I was never passionate about this particular choice one way or the other! |
It was removed in #1473
Alternative to #1472. This PR makes
focusTrap
’sinitialFocus
handle action focus and retains the hack inDialog.Buttons
which handles action focus in nestedfocusTrap
s (such as the one inShorthandHookFromActionMenu
).Fixes https://github.com/github/primer/issues/313
ℹ️ You might wonder–“Why wasn’t moving the
autoFocus
attribute fromcancelButton
toconfirmButton
inConfirmationDialog.tsx
sufficient?” Great question! I wondered the same thing at first. It turns out that this special case infocusTrap
causes the primary-action button (confirmButton
) to receivetabIndex: -1
, so the secondary-action button (cancelButton
) still receives focus, even ifautoFocus: true
is moved toconfirmButton
.Screenshots
Screen recording demonstrating the primary action is focused when a 'ConfirmationDialog' opens:

We generally follow platform conventions, and primary-action-focus is the default in macOS confirmation dialogs (screen recording of Pages below):

Merge checklist
Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.