-
Notifications
You must be signed in to change notification settings - Fork 30
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: added focus trap to Popover #1164
Conversation
Codecov Report
@@ Coverage Diff @@
## main #1164 +/- ##
==========================================
- Coverage 68.45% 68.38% -0.08%
==========================================
Files 280 280
Lines 2184 2176 -8
Branches 759 754 -5
==========================================
- Hits 1495 1488 -7
+ Misses 678 677 -1
Partials 11 11
|
85fc214
to
2a7f1e2
Compare
2a7f1e2
to
87b69b6
Compare
📬Published Alpha Packages:@codecademy/gamut-labs@5.4.0-alpha.87b69b.0 |
🚀 Styleguide deploy preview ready! |
@@ -91,7 +91,7 @@ describe('Popover', () => { | |||
isOpen: true, | |||
onRequestClose, | |||
}); | |||
fireEvent.keyDown(baseElement, { key: 'Escape', keyCode: 27 }); | |||
fireEvent.keyDown(baseElement, { key: 'escape', keyCode: 27 }); | |||
expect(onRequestClose).toBeCalledTimes(1); |
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.
Fun fact: I think this unit test wasn't actually testing what it thought it was, because the key was incorrect case...
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.
thanks for catching that!
@@ -109,32 +99,37 @@ export const Popover: React.FC<PopoverProps> = ({ | |||
}, [targetRect, isInViewport, onRequestClose]); | |||
|
|||
const popoverRef = useRef<HTMLDivElement>(null); | |||
useClickAway(popoverRef, handleClickOutside); | |||
useHotkeys('escape', handleClickOutside, {}, [targetRect]); |
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.
This stuff is handled by the focus trap for us now.
Overview
PR Checklist
Description
This adds in a little bit of the work we'd worked on in #846: specifically the usage of the focus trap. I've been trying to get the Reach UI components because they're quite a bit more accessible, but won't have them ready in time for the engagement team being able to launch this week.
There are two parallel investigations I tried out today:
I would like to continue pushing forward on them later, but need to unblock 🥚 friends. So here we/you go, at long last, the exact thing we/you wanted in #851 and I was super adamant about trying to avoid. 🙃 . Putting a co-authored-by tag because this really is partially what was coded there already...
Co-authored-by: Sooin Chung sooin@codecademy.com, Hasan Afzal hasan@codecademy.com