Skip to content

fix: prevent useTooltipTrigger from setting tabIndex #8622

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

Merged
merged 3 commits into from
Aug 4, 2025
Merged
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
6 changes: 3 additions & 3 deletions packages/@react-aria/tooltip/src/useTooltipTrigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ export function useTooltipTrigger(props: TooltipTriggerProps, state: TooltipTrig
'aria-describedby': state.isOpen ? tooltipId : undefined,
...mergeProps(focusableProps, hoverProps, {
onPointerDown: onPressStart,
onKeyDown: onPressStart,
tabIndex: undefined
})
onKeyDown: onPressStart
}),
tabIndex: undefined
Copy link
Member

Choose a reason for hiding this comment

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

why is the undefined needed here at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the focusableProps here include a tabIndex, which then gets passed into FocusableContext. for the component consuming that context via useFocusable, the props from context (interactionProps) take precedence over the tabIndex determined by excludeFromTabOrder/isDisabled

another potential fix is to have useFocusable's calculated tabIndex take precedence over the props coming from the context, but that may be a riskier change

Copy link
Member

Choose a reason for hiding this comment

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

Ok. I'm actually unsure why useTooltipTrigger calls useFocusable at all, since it is meant to pass the trigger props down to an element that already calls that (e.g. button). But looks like it's been there for 5+ years 🤷

},
tooltipProps: {
id: tooltipId
Expand Down
28 changes: 28 additions & 0 deletions packages/react-aria-components/test/Tooltip.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,4 +312,32 @@ describe('Tooltip', () => {
let tooltip = getByRole('tooltip');
expect(tooltip).toBeInTheDocument();
});

it('should not override child properties for excludeFromTabOrder', async () => {
let {getByRole} = render(
<TooltipTrigger>
<Button excludeFromTabOrder>
Check my tabindex
</Button>
<Tooltip>hello world</Tooltip>
</TooltipTrigger>
);

let button = getByRole('button');
expect(button).toHaveAttribute('tabindex', '-1');
});

it('should not override child properties', async () => {
let {getByRole} = render(
<TooltipTrigger>
<Button>
Check my tabindex
</Button>
<Tooltip>hello world</Tooltip>
</TooltipTrigger>
);

let button = getByRole('button');
expect(button).toHaveAttribute('tabindex', '0');
});
});