-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Allow popovers to be closed via the Escape key #502
Conversation
This prevents some occasionally fuzzy looking popovers
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.
Two main issues:
- The visibility prop can be used to make this a controlled or uncontrolled component
- The keyboard listener should be specific to the popover that initiated it
@mavarius I'm gonna noodle on this more and see if I can find a way to only close a single popover at a time using the escape key |
While this is very unlikely to happen, it still looks horrible so this is a nice safegauard
// in order to enable escape key behavior | ||
useEffect(() => { | ||
if (dialogRef.current) { | ||
dialogRef.current.focus() |
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.
Could this inadvertently pull focus from an element within the dialog, like a button or input field?
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.
That's a good question... I'll try building an example of this in storybook
Shoudln't actually matter what element type is in focus for this to work. If we shipped this it would break if a custom element was in focus, aka a `div`
I updated |
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! Ship it
Closes #501
Changes
PopoverDialog
will make itself the browser's active element if nothing else is in focusvisible
is true it will supersede the escape key behavior in the interest of complete external controlScreenshots
Example of

PopoverDialog
deferring focus to an input withautofocus={true}
:Checklist
Check all that apply