MCPcopy Create free account
hub / github.com/ReactTooltip/react-tooltip / shouldOpenOnVisibleFocus

Function shouldOpenOnVisibleFocus

src/components/Tooltip/focus-open.ts:149–173  ·  view source on GitHub ↗
(event: Event)

Source from the content-addressed store, hash-verified

147}
148
149export function shouldOpenOnVisibleFocus(event: Event): boolean {
150 const { target } = event
151 const relatedTarget = event instanceof FocusEvent ? event.relatedTarget : null
152
153 if (isMacSafari() && !relatedTarget) {
154 if (!lastInputWasKeyboard && !isTypeableElement(target)) {
155 return false
156 }
157 return true
158 }
159
160 if (!(target instanceof Element)) {
161 return false
162 }
163 // JSDOM parses :focus-visible but never matches it, which would hide every
164 // keyboard tooltip under test. Old browsers that reject the selector throw.
165 if (isJSDOM()) {
166 return true
167 }
168 try {
169 return target.matches(':focus-visible')
170 } catch {
171 return true
172 }
173}
174
175export function resetFocusOpenGuards(): void {
176 session += 1

Callers 1

useTooltipEventsFunction · 0.90

Calls 3

isMacSafariFunction · 0.85
isTypeableElementFunction · 0.85
isJSDOMFunction · 0.85

Tested by

no test coverage detected