Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/react-aria-components/src/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ function TooltipInner(
style={
{
...overlayProps.style,
visibility: !placement && !state.isOpen ? 'hidden' : undefined,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definitely an interesting approach

some other approaches I'd had:

  • delay opening a tooltip on focus until setTimeout(0) and check that focus is still there
  • fire a custom event that tells a TooltipTrigger that focus will just be passing through, don't bother opening a tooltip

I'm not yet sure which approach I like best, so it's a question for the team.

'--trigger-anchor-point': triggerAnchorPoint
? `${triggerAnchorPoint.x}px ${triggerAnchorPoint.y}px`
: undefined,
Expand Down
12 changes: 12 additions & 0 deletions packages/react-aria-components/test/Tooltip.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -381,4 +381,16 @@ describe('Tooltip', () => {
let button = getByRole('button');
expect(button).toHaveAttribute('tabindex', '0');
});

it('hides unmeasured tooltips during exit animation', () => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is pretty specific to the implementation, probably better to reproduce the actual user flow in the test with mocked timers if possible

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I agree the test should cover the actual focus flow rather than asserting the visibility style directly. I'll hold off on changing the test until we settle on the implementation approach.

let {getByRole} = render(
<TooltipTrigger isOpen={false}>
<Button>Trigger</Button>
<Tooltip isExiting>Unmeasured tooltip</Tooltip>
</TooltipTrigger>
);

let tooltip = getByRole('tooltip', {hidden: true});
expect(tooltip).toHaveStyle('visibility: hidden');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we do the either of the suggestions I had instead, we could instead listen to onOpenChange in TooltipTrigger and assert it was never called

});
});