AlertDialog add support for `allowsKeyboardConfirmation` prop
See original GitHub issue🙋 Feature Request
AlertDialog is missing the feature allowsKeyboardConfirmation
as defined in the API at https://github.com/adobe/react-spectrum/blob/main/packages/%40react-types/dialog/src/index.d.ts#L83.
🤔 Expected Behavior
allowsKeyboardConfirmation
- Pressing the enter
key closes the AlertDialog as if primary action button was clicked, which would call onPrimaryAction()
. If the user has focused one of the dialog buttons or a text-area that component/element should handle the enter
key event, which in the case of the button, its usePress
hook will handle that.
😯 Current Behavior
Not implemented. You can see existing behavior AlertDialog behavior at https://react-spectrum.adobe.com/react-spectrum/AlertDialog.html
💁 Possible Solution
For similar functionality, the escape
key closing the AlertDialog is handled by this code in an aria hook https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/overlays/src/useOverlay.ts#L69-L75
🧢 Your Company/Team
RSP
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (6 by maintainers)
Right yeah I get that. This option is more for the situation where it is not the first focus event of the dialog. Maybe there are some form elements in a dialog such as a checkbox. In that case, hitting Enter would allow the user to “confirm” the dialog without having to keyboard focus the confirm button first.
I’d like to give this a try and looked a bit into the code the problem is that
AlertDialog
itself just usesDialog
so to implement this feature one would have to provide this feature somehow toDialog
because that’s where we’d have to attach theonKeyDown
event handler into the DOM-Nodes