Skip to content
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

Merged
merged 1 commit into from
Nov 18, 2020
Merged

Conversation

JoshuaKGoldberg
Copy link
Collaborator

@JoshuaKGoldberg JoshuaKGoldberg commented Nov 17, 2020

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

@JoshuaKGoldberg JoshuaKGoldberg requested a review from a team as a code owner November 17, 2020 20:53
@codecov
Copy link

codecov bot commented Nov 17, 2020

Codecov Report

Merging #1164 (87b69b6) into main (b0e7c81) will decrease coverage by 0.07%.
The diff coverage is 100.00%.

@@            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              
Impacted Files Coverage Δ
...ages/gamut-labs/src/experimental/Popover/index.tsx 100.00% <100.00%> (+2.43%) ⬆️

@JoshuaKGoldberg JoshuaKGoldberg changed the title feat: added focus trap to Popover... feat: added focus trap to Popover Nov 17, 2020
@codecademydev
Copy link
Collaborator

📬Published Alpha Packages:

@codecademy/gamut-labs@5.4.0-alpha.87b69b.0

@codecademydev
Copy link
Collaborator

🚀 Styleguide deploy preview ready!

https://5fb43c537e2c830c5a81d661--gamut-preview.netlify.app

Deploy Logs

@@ -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);
Copy link
Collaborator Author

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...

Copy link
Contributor

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]);
Copy link
Collaborator Author

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.

@JoshuaKGoldberg JoshuaKGoldberg merged commit dd8958f into main Nov 18, 2020
@JoshuaKGoldberg JoshuaKGoldberg deleted the jg-popover-focus-trap branch November 18, 2020 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants