-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add a useDialog hook and replace the duplicated PopoverWrapper #27643
Conversation
Size Change: +730 B (0%) Total Size: 1.28 MB
ℹ️ View Unchanged
|
It looks like it wouldn't be impossible now to replace all that logic with Reakit: https://reakit.io/docs/dialog/ Just saying 😃 |
Indeed, we're getting closer to reakit which is good. We're not there yet though. |
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.
Great work here and in all the other PRs to achieve this final one 💯 !
I tested it and works as expected. Code wise looks good as well - just left a minor comment about the documentation and you'll have to replace your comment about mousedown
.
Test failure is unrelated and unfortunately axe-core
need to be checked again, separately of course.
Having said that, I'd like some other folks with more experience on focus and accessibility to green light it, in case I missed some use case..
Since this doesn't add a new stable API and doesn't change the existing behavior (just moves it to a hook) I'm going to merge it. Happy to address follow-ups. |
That's great @youknowriad! I wonder what's the reason for returning a tuple of Also, is it possible to |
The main reason is that I want to remove the props and only return the ref. We can't that right now because of useFocusOutside. I believe @talldan has some ideas on how to do that.
I'm not sure I understand the question 100%. Right now, you just apply useDialog returned value to an element. You can do so in two ways:
or if your portal "node" is rendered in React, you can also apply the same hook on it. |
} | ||
}, 0 ); | ||
|
||
return () => clearTimeout( focusTimeout ); | ||
}, [] ); | ||
}, [ node ] ); |
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.
If you add a dependency here, the promise of only focussing on mount is broken.
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 don't think so, I'm focusing only when the "node" is mounted, not the component.
import { __experimentalUseDialog as useDialog } from '@wordpress/compose'; | ||
|
||
const MyDialog = () => { | ||
const [ ref, extraProps ] = useDialog( { |
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.
Why is ref separate? Ref is also a prop that can be spread?
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.
That's still subject to change, my hope is that we can remove the props entirely and just return the ref. more explanations here #27643 (comment)
This is a follow up to #26355 and the different PRs refactoring our a11y HoCs to hooks.
This PR adds an experimental useDialog to apply all the a11y behaviors required for a popover using a single hook.
I'm marking it experimental because it users the experimental useFocusOutside. Ideally, it would just return a ref (without extra props).