Skip to content

Commit

Permalink
Fix regression for :focus-visible matcher in unit tests (#2827)
Browse files Browse the repository at this point in the history
  • Loading branch information
connor-baer authored Dec 11, 2024
1 parent 2c22271 commit dc6aa83
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/strong-mayflies-kneel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sumup-oss/circuit-ui': patch
---

Fixed a regression that [breaks Jest and Vitest tests](https://github.com/dperini/nwsapi/issues?q=sort%3Aupdated-desc+is%3Aissue+focus-visible+) when [matching elements](https://developer.mozilla.org/en-US/docs/Web/API/Element/matches) using the `:focus-visible` selector.
6 changes: 3 additions & 3 deletions packages/circuit-ui/components/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,13 @@ export const Tooltip = forwardRef<HTMLDivElement, TooltipProps>(
const handleFocus: FocusEventHandler = useCallback(
(event) => {
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'))
process.env.NODE_ENV === 'test'
? event.currentTarget.matches(':focus')
: event.currentTarget.matches(':focus-visible')
) {
handleOpen();
}
Expand Down

0 comments on commit dc6aa83

Please sign in to comment.