Skip to content

Conversation

emplums
Copy link

@emplums emplums commented Dec 30, 2020

This PR refactors the Dialog component

  • Removes the @reach/dialog dependency which doesn't currently support React 17 and was bloating our bundle size.
  • All tests pass before adding new ones
  • Adds additional tests using testing-library/react
  • Adds four new props:
    • narrow and wide for easy setting of default widths
    • initialFocusRef to allow users to focus an item other than the close button when the Dialog is opened
    • returnFocusRef to return focus to the proper element when Dialog is closed
  • Adds ref forwarding
  • Conforms to WAI-ARIA best practices for modals: https://www.w3.org/TR/wai-aria-practices-1.2/#dialog_modal

Reduces our bundle size by about 19% (23% gzipped)! 🎉 🎉 🎉

Technically there are no breaking changes in this PR, but we are adding a new returnFocusRef that is used to ensure that focus is restored to the proper place when the Dialog is closed. This wasn't working before, so upgrading PRC to a release with these changes won't break anything, but going forward we'd like users to include a returnFocusRef. This prop won't be required (to accommodate applications that want to manage focus when the Dialog closes themselves) but highly recommended if you aren't managing focus yourself.

Closes #930

Merge checklist

  • Added or updated TypeScript definitions (index.d.ts) if necessary
  • Added/updated tests
  • Added/updated documentation
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.

@vercel
Copy link

vercel bot commented Dec 30, 2020

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/primer/primer-components/ka7rqpq3w
✅ Preview: https://primer-components-git-modal.primer.now.sh

@vercel vercel bot temporarily deployed to Preview December 30, 2020 19:13 Inactive
@vercel vercel bot temporarily deployed to Preview December 30, 2020 19:58 Inactive
@vercel vercel bot temporarily deployed to Preview December 30, 2020 20:01 Inactive
@vercel vercel bot temporarily deployed to Preview December 30, 2020 20:04 Inactive
@vercel vercel bot temporarily deployed to Preview December 30, 2020 20:07 Inactive
@vercel vercel bot temporarily deployed to Preview December 30, 2020 20:43 Inactive
@vercel vercel bot temporarily deployed to Preview December 30, 2020 20:47 Inactive
@vercel vercel bot temporarily deployed to Preview January 5, 2021 17:48 Inactive
@vercel vercel bot temporarily deployed to Preview January 5, 2021 17:51 Inactive
@vercel vercel bot temporarily deployed to Preview January 5, 2021 18:02 Inactive
@emplums emplums mentioned this pull request Jan 5, 2021
4 tasks
@colebemis
Copy link
Contributor

Loving this new direction! ❤️

I haven't finished reviewing all the code yet but looks like focus trapping isn't quite working. Clicking inside the dialog then tabbing leads to this:

Kapture.2021-01-05.at.14.27.06.mp4

@vercel vercel bot temporarily deployed to Preview January 5, 2021 23:49 Inactive
@emplums
Copy link
Author

emplums commented Jan 5, 2021

@colebemis nice catch, I added a negative tab index to the modal container and that seems to have fixed it 🙌

@vercel vercel bot temporarily deployed to Preview January 6, 2021 00:00 Inactive
Copy link
Contributor

@colebemis colebemis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

cursor: pointer;

&:focus {
box-shadow: 0 0 0 3px rgba(139, 148, 158, 0.3);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, where'd these focus styles come from?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm good question - I copied over the focus box shadow used in the close button in toasts, but those are on a dark background in light mode, which is why its grey. I would probably be better to used the primary box-shadow-focus here instead: https://github.com/primer/css/blob/master/src/support/variables/misc.scss#L23

Copy link
Author

@emplums emplums Jan 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The official Primer .button-close doesn't include a focus outline, but it probably should, so I'm going to use the default shadow here

@vercel vercel bot temporarily deployed to Preview January 12, 2021 02:01 Inactive
@vercel vercel bot temporarily deployed to Preview January 12, 2021 02:13 Inactive
@emplums emplums changed the base branch from main to major January 12, 2021 02:20
@vercel vercel bot temporarily deployed to Preview January 12, 2021 02:24 Inactive
@vercel vercel bot temporarily deployed to Preview January 12, 2021 02:43 Inactive
@vercel vercel bot temporarily deployed to Preview January 12, 2021 02:46 Inactive
Emily Plummer added 2 commits January 11, 2021 18:51
This reverts commit 092655e.
@vercel vercel bot temporarily deployed to Preview January 12, 2021 02:52 Inactive
@emplums emplums merged commit 3d14743 into major Jan 12, 2021
@emplums emplums deleted the modal branch January 12, 2021 23:29
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.

Custom Dialog component

3 participants