-
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
compose: Add types to useFocusReturn
#31949
Conversation
Size Change: +3.04 kB (0%) Total Size: 1.62 MB
ℹ️ View Unchanged
|
const isFocused = ref.current.contains( | ||
ref.current.ownerDocument.activeElement | ||
const isFocused = ref.current?.contains( | ||
ref.current?.ownerDocument.activeElement ?? null |
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.
Can we pass null
to Node.contains()
? In any case this case feels weird.
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.
You can, it accepts Node | null
but not undefined
.
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.
👍 Gotcha. Checking if a node contains null
sounds like an oxymoron to me, but that's beyond the scale of this PR anyway.
focusedBeforeMount.current = node.ownerDocument.activeElement; | ||
focusedBeforeMount.current = | ||
/** @type {HTMLElement | null} */ ( node.ownerDocument | ||
.activeElement ) || undefined; |
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 there a reason to prefer || undefined
here than ?? undefined
? Also, why prefer undefined
than potentially null
here?
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.
None, I can change it to ??
just fine.
I used undefined
because it matches the original default value on line 34. We could change it to null
if we change the default value to null
as well. Do you think that would be better?
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.
After speaking to @ciampo I'm going to go ahead and make the change to the default value of null
instead of using undefined here. Should clean up the code a bit 🙂
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, I like that 👍
9ac5467
to
487570f
Compare
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 have anything to add here, this looks good 👍
@ciampo did you want to add anything before we 🚢 ?
Just added a minor comment but otherwise, I don't have anything else to add PS: looks like the CI checks are not running? |
Co-authored-by: Marco Ciampini <[email protected]>
…-take-2 * trunk: (57 commits) Image block: fix cover transform and excessive re-rendering (#32102) compose: Add types to useMergeRefs (#31939) Navigation: Fix collapsing regression. (#32081) components: Promote Elevation (#31614) compose: Add types to useReducedMotion and useMediaQuery (#31941) Update the graphic that appears in the Template Editor welcome guide (#32055) Block Navigation: use CSS for indentation with known max indent instead of spacer divs (#32063) Fix broken template part converter modal styles. (#32097) compose: Add types to `usePrevious` (#31944) components: Add ZStack (#31613) components: Fix Shortcut polymorphism (#31555) compose: Add types to `useFocusReturn` (#31949) compose: Add types to `useDebounce` (#32015) List View: Simplify the BlockNavigation component (#31290) Remove query context leftovers (#32093) Remove filter_var from blocks (#32046) Templates: Remove now-obsolete gutenberg_get_template_paths() (#32066) [RNMobile] Enable reusable block only in WP.com sites (#31744) Rename ViewOwnProps to PolymorphicComponentProps (#32053) Rich text: remove inline display warning (#32013) ...
Description
Adds types to
useFocusReturn
.It's a little messy I think and I'm unsure of the return type, whether it should be
HTMLElement
or potentially even just generic. I don't think it can beNode
though otherwise you'll get a type error when you actually try to apply theref
that's returned 🤔Part of #18838
How has this been tested?
Type checks pass. Also tested inline with a component that just uses the function and it works fine:
The above produces no errors when typechecked.
Types of changes
New feature
Checklist:
*.native.js
files for terms that need renaming or removal).