Skip to content

Commit

Permalink
Work around new nwsapi bug
Browse files Browse the repository at this point in the history
  • Loading branch information
connor-baer committed Dec 6, 2024
1 parent f1546d7 commit d7c911d
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions packages/circuit-ui/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,15 @@ export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(

const handleFocus: FocusEventHandler = useCallback(
(event) => {
// Vitest and Jest use nwsapi to mock the `Element.matches` API.
// Unfortunately, it doesn't support the `:focus-visible` selector yet.
// See https://github.com/dperini/nwsapi/issues/54
try {
if (event.currentTarget.matches(':focus-visible')) {
handleOpen();
}
} catch (_error) {
if (
event.currentTarget.matches(':focus-visible') ||
// Vitest and Jest use nwsapi to mock the `Element.matches` API.
// It has a bug where `:focus-visible` is not matched unless
// the element has the `autofocus` property set.
// https://github.com/dperini/nwsapi/issues/122
(process.env.NODE_ENV === 'test' &&
event.currentTarget.matches(':focus'))
) {
handleOpen();
}
},
Expand Down

0 comments on commit d7c911d

Please sign in to comment.