-
Notifications
You must be signed in to change notification settings - Fork 4.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
useFocusOutside: rewrite hook to TypeScript, rewrite tests to model RTL and user-event #45317
Conversation
923f415
to
1f298d9
Compare
Size Change: 0 B Total Size: 1.28 MB ℹ️ View Unchanged
|
This looks good. I appreciate the improvements to the unit tests. Though it looks like these tests need more scrutiny because I can try breaking them by removing the hook and 4/5 still pass. I came across it accidentally while working on a fix for #40912 on another branch. The screenshot is from testing this branch. I'm finding it a bit hard to believe so it'd be great if anyone can try and reproduce it. Not sure if we'd have to address it with this PR because I think it's the same on trunk. UPDATE: |
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.
This looks awesome 💯
Left a few nits and minor suggestions, but I think it's good to go already 🚀
@@ -4,7 +4,8 @@ | |||
|
|||
### Internal | |||
|
|||
- `useDisabled`: Refactor the component to rely on the HTML `inert` attribute. | |||
- `useDisabled`: Refactor the component to rely on the HTML `inert` attribute ([#44865](https://github.com/WordPress/gutenberg/pull/44865)). |
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 adding the missing PR link 👍
* | ||
* @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus | ||
* | ||
* @param eventTarget The target from a mouse or touch 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.
Missing the param type?
* @param eventTarget The target from a mouse or touch event. | |
* @param {EventTarget} eventTarget The target from a mouse or touch 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.
In the past, I've usually avoided having types in JSDocs in TypeScript files, as the code itself is already typed. The only exceptions have been for when the JSDoc types where necessary for automatic doc generation.
Adding types here would also require us to add back a lot of JSDoc extra type def (see the code deletions in this file)
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 generally agree, just wanted to pick your thoughts 👍 Happy to keep it as you suggested.
b952b3b
to
6309e63
Compare
Thank you both @tyxla and @stokesman for the reviews! I've addressed all minor feedback, but I'll wait before merging until we have an agreement on #45317 (comment).
Interesting, would be curious to see what you're approach is about. I've opened a draft PR but I'm not sure it's a good approach. |
I think we agree there already, so you have my green light ✅ |
What?
While trying to fix #40912 I got to rewrite the hook to TypeScript and the tests to modern RTL techniques (including
user-event
)Why?
Better tests and TypeScript as a more solid foundation for working on a tricky problem (which I haven't solved, but I thought I'd push these improvements anyway)
How?
Tests:
user-event
instead offireEvent
(or even imperative events called on each element) where possibledocument.hasFocus
TestComponent
wrapperHook:
FocusEventHandler
etc)useDialog
Testing Instructions
Check the
Modal
Storybook example (and modals around the codebase) and make sure that they behave as currently ontrunk
Code changes can reviewed more easily when approached commit-by-commit