-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Tooltip: no-op when nested inside another Tooltip component #57202
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
Conversation
|
Before moving any further, I'd like to get a quick check from @diegohaz on the chosen approach. Diego, here is a quick recap:
Please let me know if this approach makes sense to you, or if there are better ways to handle this in |
|
I believe that's reasonable. If I'm interpreting the solution correctly, the only issue I foresee is if users typically display portaled content within those buttons. For example: <Tooltip>
<Button />
<Modal>
<Tooltip>
<Button />
</Tooltip>
</Modal>
</Tooltip>If this scenario is unlikely, then I think it's perfectly fine. |
e566abd to
bd859de
Compare
This comment was marked as outdated.
This comment was marked as outdated.
bd859de to
ac7c722
Compare
|
Size Change: +50 B (0%) Total Size: 1.69 MB
ℹ️ View Unchanged
|
02f9835 to
447c945
Compare
447c945 to
0e24ae4
Compare
|
|
||
| function UnconnectedTooltip( | ||
| props: WordPressComponentProps< TooltipProps, 'div', false >, | ||
| ref: React.ForwardedRef< any > |
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.
For the nesting to work correctly, Tooltip needs to forward the ref down to its anchor.
|
Rebased and marked as ready for review after #57345 got merged. |
packages/editor/src/components/post-saved-state/test/__snapshots__/index.js.snap
Outdated
Show resolved
Hide resolved
| showTimeout: delay, | ||
| } ); | ||
|
|
||
| if ( isNestedInParentTooltip ) { |
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.
Any potential core use cases with nested behavior that could be affected by this change?
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 can't think of any, if anything because, prior to this PR, I don't think that nesting Tooltip components would not work correctly.
| showTimeout: delay, | ||
| } ); | ||
|
|
||
| if ( isNestedInParentTooltip ) { |
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.
Did we also mean to trigger a console warning in that scenario (as per your earlier suggestion)?
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 thought about it, and then I decided not to add a warning as it has the potential to pollute the browser's console‚ especially if we're going to implement the solution proposed in #56490, which purposefully makes use of this nested tooltip logic.
0e24ae4 to
7fbfcbe
Compare
tyxla
left a comment
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.
Nothing further from me on this one. Great work 🚀
7fbfcbe to
b9ef9ad
Compare
|
Rebased to include the latest updated to |
Requires #57345
Pre-requisite for #56490
What?
Allow nesting 2 or more
Tooltipcomponents without breaking the tooltip functionality. The contents of the tooltip will be the ones defined in the outer-mostTooltipinstance.Why?
In #56490, we're trying to fix an issue where
Buttoncould trash and re-create its children when the internal tooltip logic flips from showing to hiding the tootlip (or vice-versa).The solution proposed in #56490 involves always rendering (in the react sense) the
Tooltipcomponent insideButton. But doing so would cause breakages, since theTooltipcomponent doesn't support that scenario.This PR allows that scenario to work without causing breakages.
How?
By using the internal context system to inform instances of
Tooltipwhether they are being rendered inside another instance ofTooltip. When that happens, theTooltipcomponent only renders the anchor and ignores the tooltip part.Testing Instructions