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

Function subscribeFocusOpenGuards

src/components/Tooltip/focus-open.ts:105–131  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

103}
104
105export function subscribeFocusOpenGuards(): () => void {
106 const subscribedSession = session
107 subscribers += 1
108 if (!listening && typeof window !== 'undefined') {
109 listening = true
110 window.addEventListener('blur', onWindowBlur)
111 window.addEventListener('focus', onWindowFocus)
112 // Only Mac Safari reads this, and only when :focus-visible is wrong.
113 // Other browsers must not pay for a listener on every key and click.
114 if (isMacSafari()) {
115 window.addEventListener('keydown', onKeyDown, true)
116 window.addEventListener('pointerdown', onPointerDown, true)
117 modalityListening = true
118 }
119 }
120
121 return () => {
122 if (subscribedSession !== session) {
123 return
124 }
125 subscribers -= 1
126 if (subscribers <= 0) {
127 subscribers = 0
128 detach()
129 }
130 }
131}
132
133export function isWindowRestoredFocus(target: EventTarget | null): boolean {
134 if (!(target instanceof Node) || restoredFocusElement === null) {

Callers 1

useTooltipEventsFunction · 0.90

Calls 2

isMacSafariFunction · 0.85
detachFunction · 0.85

Tested by

no test coverage detected