Skip to content
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

Merged
merged 3 commits into from
May 23, 2024

Conversation

igorman007
Copy link
Contributor

@igorman007 igorman007 commented May 20, 2024

Closes #6233

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 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:

} else if (!closeTimeout.current) {
closeTimeout.current = setTimeout(() => {
closeTimeout.current = null;
close();
closeCallback.current();
Copy link
Contributor Author

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

@yihuiliao
Copy link
Member

Thanks for the PR! Mind signing the Adobe CLA?

@igorman007 igorman007 closed this May 20, 2024
@igorman007 igorman007 reopened this May 20, 2024
@igorman007
Copy link
Contributor Author

Thanks for the PR! Mind signing the Adobe CLA?

Done

Copy link
Member

@snowystinger snowystinger left a 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(() => {
Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Member

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

@snowystinger
Copy link
Member

Also, if it's not too hard, would you mind adding a unit test?

@igorman007 igorman007 force-pushed the fixUseTooltipControlledMultiple branch from 18e1642 to 2782534 Compare May 22, 2024 18:52
@@ -196,4 +213,45 @@ describe('useTooltipTriggerState', function () {
expect(onOpenChange).toHaveBeenCalledWith(false);
});
});

describe('multiple controlled tooltips', () => {
it('closes previus tooltip when opening a new one', () => {
Copy link
Contributor Author

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

Copy link
Member

@snowystinger snowystinger left a 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(() => {
Copy link
Member

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

@LFDanLu
Copy link
Member

LFDanLu commented May 23, 2024

GET_BUILD

Copy link
Member

@LFDanLu LFDanLu left a 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!

@rspbot
Copy link

rspbot commented May 23, 2024

@rspbot
Copy link

rspbot commented May 23, 2024

## API Changes

unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any', access: 'private' }
unknown top level export { type: 'any', access: 'private' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'identifier', name: 'Column' }
unknown top level export { type: 'identifier', name: 'Column' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown type { type: 'link' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }
unknown top level export { type: 'any' }

@LFDanLu LFDanLu merged commit 379e8d6 into adobe:main May 23, 2024
26 checks passed
@GuoXiaoyang
Copy link

That's great! May I ask when this fix will be published?

@snowystinger
Copy link
Member

It'll be in our next release. Sometime in the next couple weeks most likely

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
6 participants