-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
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
[ButtonBase] Use fork of focus-visible polyfill #15484
Conversation
@material-ui/core: parsed: -0.12% 😍, gzip: -0.03% 😍 Details of bundle changes.Comparing: 8c5a1ca...7758875
|
export function teardown() { | ||
document.removeEventListener('keydown', handleKeyDown, true); | ||
document.removeEventListener('mousedown', handlePointerDown, true); | ||
document.removeEventListener('pointerdown', handlePointerDown, true); |
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.
Is the pointerdown event redundant with mousedown and touchstart?
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.
I haven't really looked into those. Not sure what other pointer types e.g. a pen would trigger in browsers that implement PointerEvents.
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.
Keeping it for now until we can verify that a pointerdown from a pen triggers either keydown or mousedown.
handleBlur = createRippleHandler(this, 'Blur', 'stop', () => { | ||
clearTimeout(this.focusVisibleTimeout); | ||
handleBlur = createRippleHandler(this, 'Blur', 'stop', event => { | ||
handleBlur(event); |
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.
Looking at the WIGC focus-visible.js, I think this handleBlur
call should either be moved inside the following if (this.state.focusVisible) {
or pass this.state.focusVisible
as an additional argument to handleBlur
. I don't think hadFocusVisibleRecently = true;
should occur unless this element had this.state.focusVisible
prior to the blur.
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.
Good call. I think we should rename the handleBlur from focusVisible.js to handleBlurVisible. Removing styling etc is the responsibility of the caller but focusVisible.js should manage the global state.
Make it clearer when handleBlur should be called
Forgot they won't work that well across windows
70da954
to
33e07e2
Compare
enzyme find cant pierce shadow dom
|
assert.strictEqual(getState().focusVisible, true); | ||
}); | ||
|
||
it('should ignore the keyboard after 1s', () => { |
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.
We changed the 1s
duration at some point, entropy 👋
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.
There's alot of behavior that isn't tested right now in our codebase. But this is a fork so it is actually tested somewhere. Just need to make sure we watch for releases of the base.
Let's keep it for now and see if the focus visible is useful elsewhere. It's a common a11y helper so I don't want it floating around in the code base under a name that doesn't fully apply.
It's one listener per document. The only issue is that we don't have automatic cleanup. Unless someone is re-creating documents during app lifetime it should be fine. |
I have edited my comment. It's useful. I remember somebody using a tooltip wrapping an input. |
@ryancogswell Oh my god it's so beautiful (needs 60fps video): |
😍 |
this.setState({ focusVisible: false }); | ||
} | ||
}); | ||
|
||
componentDidMount() { | ||
listenForFocusKeys(ownerWindow(this.getButtonNode())); | ||
|
||
prepareFocusVisible(this.getButtonNode().ownerDocument); |
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.
@eps1lon It does look like this is going to add a set of document listeners for each ButtonBase
mount. Should be able to short-circuit within focusVisible.js
prepare
function by tracking in a variable whether or not the listeners have already been added to the document.
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.
Should we handle it?
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.
It does look like this is going to add a set of document listeners for each ButtonBase mount.
addEventListener does not add duplicate listeners. Unless the focusVisible.js module is recreated for every ButtonBase instance they shouldn't be duplicated.
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 the education.
@oliviertassinari I'll take care of this later this week after this branch is merged. I tried to do this before -- intending to successfully verify it for the arrow keys and then have a failing test for the text navigation, but with the old focusVisible logic I was going to have to do some rather convoluted things to get a successful test for the arrow keys. It should be more straightforward after this branch is merged. I also noticed an issue with the text navigation for Select when playing with the netlify deploy from this branch. |
@ryancogswell Thanks for the follow-up. |
@eps1lon People report that Material-UI is slow, this change will greatly help. Really well done 🔥. Thank you for giving a fresh touch at this old logic! |
This is a draft. It doesn't use github drafts to get a netlify deploy.Prerequisite for #15398
Uses a fork of https://github.com/WICG/focus-visible instead of our own implementation which is quite unresponsive.
Playground:
TODO:
@ryancogswell You might be interested in this one.