-
Notifications
You must be signed in to change notification settings - Fork 1.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
fix: controlled tooltips are not close properly #6418
fix: controlled tooltips are not close properly #6418
Conversation
} else if (!closeTimeout.current) { | ||
closeTimeout.current = setTimeout(() => { | ||
closeTimeout.current = null; | ||
close(); | ||
closeCallback.current(); |
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.
no need to change this line of code (it has no bug), but changed it for consistency.
use close callback only from ref
Thanks for the PR! Mind signing the Adobe CLA? |
Done |
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 PR!
@@ -119,6 +120,10 @@ export function useTooltipTriggerState(props: TooltipTriggerProps = {}): Tooltip | |||
} | |||
}; | |||
|
|||
useEffect(() => { |
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 can use useEffectEvent
instead of managing this ref ourselves
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.
Are you sure, that's a good idea?
From the doc
Effect Events are very limited in how you can use them:
**Only call them from inside Effects.**
Never pass them to other components or Hooks.
we call 'close' not inside effect
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 have one from before those limitations were involved and because we have to support it all the way back to react 16, https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/utils/src/useEffectEvent.ts which I think is doing the same thing as you've done here
but no worries, can replace later
Also, if it's not too hard, would you mind adding a unit test? |
18e1642
to
2782534
Compare
@@ -196,4 +213,45 @@ describe('useTooltipTriggerState', function () { | |||
expect(onOpenChange).toHaveBeenCalledWith(false); | |||
}); | |||
}); | |||
|
|||
describe('multiple controlled tooltips', () => { | |||
it('closes previus tooltip when opening a new one', () => { |
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 test fails without fix and passes after fix
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 so much for writing the test!
@@ -119,6 +120,10 @@ export function useTooltipTriggerState(props: TooltipTriggerProps = {}): Tooltip | |||
} | |||
}; | |||
|
|||
useEffect(() => { |
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 have one from before those limitations were involved and because we have to support it all the way back to react 16, https://github.com/adobe/react-spectrum/blob/main/packages/%40react-aria/utils/src/useEffectEvent.ts which I think is doing the same thing as you've done here
but no worries, can replace later
GET_BUILD |
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.
Verified the behavior before and after the fix, LGTM thanks!
## API Changes
unknown top level export { type: 'any' } |
That's great! May I ask when this fix will be published? |
It'll be in our next release. Sometime in the next couple weeks most likely |
Closes #6233
✅ Pull Request Checklist:
📝 Test Instructions:
You can check this fix at storybook page.
http://localhost:9003/?path=/story/tooltiptrigger--controlled-multiple-tooltips&providerSwitcher-express=false&strict=true
before: the first tooltip doesn't close, when the second opens
after: the first tooltip closes, when the second opens
🧢 Your Project: