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

Do some cleanup on some internal functions #380

Merged
merged 3 commits into from
Jul 12, 2022

Conversation

mxmason
Copy link
Contributor

@mxmason mxmason commented Jul 9, 2022

Summary

Just trying to shave mere bytes off of the amount of code we ship.

Copy link
Contributor Author

@mxmason mxmason left a comment

Choose a reason for hiding this comment

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

Some explanations 🙇🏻

// This is an escape hatch in case there are nested dialogs,
// so the keypresses are only reacted to for the most recent one
if (!this.$el.contains(document.activeElement)) return

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🔍 This is no longer necessary if we bind this event listener specifically to this.%el, instead of to the document

Copy link
Owner

Choose a reason for hiding this comment

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

Can you double check with the nested dialogs fixture that it still works okay?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It does seem to work ok. I did some manual testing and Cypress is still happy.

// If the dialog is shown and the ESC key is pressed, prevent any further
// effects from the ESC key and hide the dialog, unless its role is
// `alertdialog`, which should be modal
if (
this.shown &&
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🔍 Checking for this.shown is redundant here because this listener is bound and unbound when we show and hide, right?

Copy link
Owner

Choose a reason for hiding this comment

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

Right, I think that makes sense yes.

@@ -209,12 +204,8 @@ export default class A11yDialog {
* See: https://github.com/KittyGiraudel/a11y-dialog/issues/177
*/
private maintainFocus = (event: FocusEvent) => {
if (!this.shown) return
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🔍 Same as bindKeypress – checking for shown is redundant, right?

Copy link
Owner

Choose a reason for hiding this comment

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

I guess so yes.

@mxmason mxmason marked this pull request as ready for review July 9, 2022 18:50
@@ -98,7 +98,7 @@ export default class A11yDialog {
// stays trapped inside the dialog while open, and start listening for some
// specific key presses (TAB and ESC)
document.body.addEventListener('focus', this.maintainFocus, true)
document.addEventListener('keydown', this.bindKeypress)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🔍 Listening for this event during the capturing phase is just a little 🤏🏻 faster, since the capturing phase runs first

Copy link
Owner

Choose a reason for hiding this comment

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

Heh that’s fair enough. I guess we really only need to listen to TAB keys in the container itself. It shouldn’t break anything.

@mxmason mxmason force-pushed the ej/chore/clean-up-internals branch from 44a6dca to 9107fdf Compare July 9, 2022 20:35
@KittyGiraudel KittyGiraudel merged commit ba50eda into KittyGiraudel:main Jul 12, 2022
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.

2 participants