-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
add focus-trap to popover #5670
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/keystonejs/keystone-next-docs/3rkp8DfaYdx4p3g3T2PfQ27U4S1d |
🦋 Changeset detectedLatest commit: 27f3171 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
@@ -194,6 +196,24 @@ type DialogProps = { | |||
export const PopoverDialog = forwardRef<HTMLDivElement, DialogProps>( | |||
({ isVisible, children, arrow, ...props }, consumerRef) => { | |||
const { elevation, radii, shadow, colors } = useTheme(); | |||
const focusTrapRef = useRef<HTMLDivElement | null>(null); |
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.
popper's provided ref is a function, and not a refObject, we create a refObject here for us to attach our focustrap to
<div data-popper-arrow ref={arrow.ref} className="tooltipArrow" {...arrow.props} /> | ||
|
||
{children} | ||
<div ref={focusTrapRef}> |
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.
Wrapping div to attach focus-trap to
|
||
useEffect(() => { | ||
if (focusTrap?.current) { | ||
if (isVisible) { |
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.
hook into isVisible to activate / deactivate the focustrap
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 27f3171:
|
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.
LGTM
Our popovers aren't keyboard friendly.
Previously we circumvented this in the admin-ui filter popover by autofocusing the select component.
This is a more robust fix, which adds focus-trap to our popover component.
I've opted for
focus-trap
overfocus-trap-react
here, as it:Porting this over to use focus-trap-react later is arbitrary.
Before:
focus-trap-befopre.mov
After:
focus-trap-after.mov