react-aria 3.51.0 → 3.52.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exports/index.cjs +1 -0
- package/dist/exports/index.cjs.map +1 -1
- package/dist/exports/index.js +2 -2
- package/dist/exports/index.js.map +1 -1
- package/dist/exports/index.mjs +2 -2
- package/dist/exports/index.mjs.map +1 -1
- package/dist/exports/private/utils/domHelpers.cjs +1 -0
- package/dist/exports/private/utils/domHelpers.cjs.map +1 -1
- package/dist/exports/private/utils/domHelpers.js +2 -2
- package/dist/exports/private/utils/domHelpers.js.map +1 -1
- package/dist/exports/private/utils/domHelpers.mjs +2 -2
- package/dist/exports/private/utils/domHelpers.mjs.map +1 -1
- package/dist/exports/useFocusVisible.cjs +1 -0
- package/dist/exports/useFocusVisible.cjs.map +1 -1
- package/dist/exports/useFocusVisible.js +2 -2
- package/dist/exports/useFocusVisible.js.map +1 -1
- package/dist/exports/useFocusVisible.mjs +2 -2
- package/dist/exports/useFocusVisible.mjs.map +1 -1
- package/dist/private/actiongroup/useActionGroup.cjs +3 -1
- package/dist/private/actiongroup/useActionGroup.cjs.map +1 -1
- package/dist/private/actiongroup/useActionGroup.js +3 -1
- package/dist/private/actiongroup/useActionGroup.js.map +1 -1
- package/dist/private/actiongroup/useActionGroup.mjs +3 -1
- package/dist/private/actiongroup/useActionGroup.mjs.map +1 -1
- package/dist/private/calendar/useRangeCalendar.cjs +1 -1
- package/dist/private/calendar/useRangeCalendar.cjs.map +1 -1
- package/dist/private/calendar/useRangeCalendar.js +2 -2
- package/dist/private/calendar/useRangeCalendar.js.map +1 -1
- package/dist/private/calendar/useRangeCalendar.mjs +2 -2
- package/dist/private/calendar/useRangeCalendar.mjs.map +1 -1
- package/dist/private/color/useColorField.cjs +26 -4
- package/dist/private/color/useColorField.cjs.map +1 -1
- package/dist/private/color/useColorField.js +26 -4
- package/dist/private/color/useColorField.js.map +1 -1
- package/dist/private/color/useColorField.mjs +26 -4
- package/dist/private/color/useColorField.mjs.map +1 -1
- package/dist/private/combobox/useComboBox.cjs +1 -1
- package/dist/private/combobox/useComboBox.cjs.map +1 -1
- package/dist/private/combobox/useComboBox.js +1 -1
- package/dist/private/combobox/useComboBox.js.map +1 -1
- package/dist/private/combobox/useComboBox.mjs +1 -1
- package/dist/private/combobox/useComboBox.mjs.map +1 -1
- package/dist/private/focus/FocusScope.cjs +7 -2
- package/dist/private/focus/FocusScope.cjs.map +1 -1
- package/dist/private/focus/FocusScope.js +7 -2
- package/dist/private/focus/FocusScope.js.map +1 -1
- package/dist/private/focus/FocusScope.mjs +7 -2
- package/dist/private/focus/FocusScope.mjs.map +1 -1
- package/dist/private/interactions/useFocusVisible.cjs +15 -3
- package/dist/private/interactions/useFocusVisible.cjs.map +1 -1
- package/dist/private/interactions/useFocusVisible.js +15 -3
- package/dist/private/interactions/useFocusVisible.js.map +1 -1
- package/dist/private/interactions/useFocusVisible.mjs +15 -3
- package/dist/private/interactions/useFocusVisible.mjs.map +1 -1
- package/dist/private/interactions/utils.cjs +23 -13
- package/dist/private/interactions/utils.cjs.map +1 -1
- package/dist/private/interactions/utils.js +25 -15
- package/dist/private/interactions/utils.js.map +1 -1
- package/dist/private/interactions/utils.mjs +25 -15
- package/dist/private/interactions/utils.mjs.map +1 -1
- package/dist/private/overlays/calculatePosition.cjs +3 -2
- package/dist/private/overlays/calculatePosition.cjs.map +1 -1
- package/dist/private/overlays/calculatePosition.js +5 -2
- package/dist/private/overlays/calculatePosition.js.map +1 -1
- package/dist/private/overlays/calculatePosition.mjs +3 -2
- package/dist/private/overlays/calculatePosition.mjs.map +1 -1
- package/dist/private/overlays/useOverlayPosition.cjs +5 -0
- package/dist/private/overlays/useOverlayPosition.cjs.map +1 -1
- package/dist/private/overlays/useOverlayPosition.js +6 -1
- package/dist/private/overlays/useOverlayPosition.js.map +1 -1
- package/dist/private/overlays/useOverlayPosition.mjs +6 -1
- package/dist/private/overlays/useOverlayPosition.mjs.map +1 -1
- package/dist/private/overlays/usePreventScroll.cjs +27 -35
- package/dist/private/overlays/usePreventScroll.cjs.map +1 -1
- package/dist/private/overlays/usePreventScroll.js +27 -35
- package/dist/private/overlays/usePreventScroll.js.map +1 -1
- package/dist/private/overlays/usePreventScroll.mjs +27 -35
- package/dist/private/overlays/usePreventScroll.mjs.map +1 -1
- package/dist/private/selection/useSelectableCollection.cjs +1 -0
- package/dist/private/selection/useSelectableCollection.cjs.map +1 -1
- package/dist/private/selection/useSelectableCollection.js +1 -0
- package/dist/private/selection/useSelectableCollection.js.map +1 -1
- package/dist/private/selection/useSelectableCollection.mjs +1 -0
- package/dist/private/selection/useSelectableCollection.mjs.map +1 -1
- package/dist/private/tabs/TabsKeyboardDelegate.cjs +3 -1
- package/dist/private/tabs/TabsKeyboardDelegate.cjs.map +1 -1
- package/dist/private/tabs/TabsKeyboardDelegate.js +3 -1
- package/dist/private/tabs/TabsKeyboardDelegate.js.map +1 -1
- package/dist/private/tabs/TabsKeyboardDelegate.mjs +3 -1
- package/dist/private/tabs/TabsKeyboardDelegate.mjs.map +1 -1
- package/dist/private/tokenfield/useToken.cjs +19 -4
- package/dist/private/tokenfield/useToken.cjs.map +1 -1
- package/dist/private/tokenfield/useToken.js +20 -4
- package/dist/private/tokenfield/useToken.js.map +1 -1
- package/dist/private/tokenfield/useToken.mjs +19 -4
- package/dist/private/tokenfield/useToken.mjs.map +1 -1
- package/dist/private/tokenfield/useTokenField.cjs +118 -42
- package/dist/private/tokenfield/useTokenField.cjs.map +1 -1
- package/dist/private/tokenfield/useTokenField.js +121 -44
- package/dist/private/tokenfield/useTokenField.js.map +1 -1
- package/dist/private/tokenfield/useTokenField.mjs +119 -43
- package/dist/private/tokenfield/useTokenField.mjs.map +1 -1
- package/dist/private/utils/domHelpers.cjs +21 -0
- package/dist/private/utils/domHelpers.cjs.map +1 -1
- package/dist/private/utils/domHelpers.js +20 -1
- package/dist/private/utils/domHelpers.js.map +1 -1
- package/dist/private/utils/domHelpers.mjs +20 -1
- package/dist/private/utils/domHelpers.mjs.map +1 -1
- package/dist/private/utils/getMetaValue.cjs +36 -0
- package/dist/private/utils/getMetaValue.cjs.map +1 -0
- package/dist/private/utils/getMetaValue.js +31 -0
- package/dist/private/utils/getMetaValue.js.map +1 -0
- package/dist/private/utils/getMetaValue.mjs +31 -0
- package/dist/private/utils/getMetaValue.mjs.map +1 -0
- package/dist/private/utils/getNonce.cjs +6 -10
- package/dist/private/utils/getNonce.cjs.map +1 -1
- package/dist/private/utils/getNonce.js +7 -11
- package/dist/private/utils/getNonce.js.map +1 -1
- package/dist/private/utils/getNonce.mjs +7 -11
- package/dist/private/utils/getNonce.mjs.map +1 -1
- package/dist/private/utils/useEvent.cjs +7 -9
- package/dist/private/utils/useEvent.cjs.map +1 -1
- package/dist/private/utils/useEvent.js +7 -9
- package/dist/private/utils/useEvent.js.map +1 -1
- package/dist/private/utils/useEvent.mjs +7 -9
- package/dist/private/utils/useEvent.mjs.map +1 -1
- package/dist/types/exports/index.d.ts +2 -2
- package/dist/types/exports/private/utils/domHelpers.d.ts +1 -1
- package/dist/types/exports/useFocusVisible.d.ts +2 -1
- package/dist/types/src/tokenfield/useTokenField.d.ts +3 -2
- package/dist/types/src/utils/domHelpers.d.ts +6 -2
- package/dist/types/src/utils/getMetaValue.d.ts +7 -0
- package/dist/types/src/utils/useEvent.d.ts +2 -2
- package/dist/types/src/virtualizer/Virtualizer.d.ts +3 -3
- package/package.json +6 -5
|
@@ -87,12 +87,24 @@ function $d0df89f3abe2c2ca$var$handleClickEvent(e) {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
function $d0df89f3abe2c2ca$var$handleFocusEvent(e) {
|
|
90
|
+
if (0, $a9918c67a493892d$exports.ignoreFocusEvent) return;
|
|
91
|
+
let target = (0, $da02ee888921bc9e$exports.getEventTarget)(e);
|
|
92
|
+
let ownerWindow = (0, $49582955cc364b1c$exports.getOwnerWindow)(target);
|
|
93
|
+
let ownerDocument = (0, $49582955cc364b1c$exports.getOwnerDocument)(target);
|
|
94
|
+
// When the window regains focus, the browser restores focus to the element that was focused
|
|
95
|
+
// before, firing a focus event the user did not initiate. handleWindowBlur sets
|
|
96
|
+
// hasBlurredWindowRecently so restored focus doesn't switch to virtual modality below, but
|
|
97
|
+
// Safari fires the window/element focus pair twice when returning to a tab or app and the first
|
|
98
|
+
// element focus event clears the flag, so re-arm it whenever the window itself is focused.
|
|
99
|
+
// Like handleWindowBlur, this intentionally doesn't check isTrusted.
|
|
100
|
+
if (target === ownerWindow) {
|
|
101
|
+
$d0df89f3abe2c2ca$var$hasBlurredWindowRecently = true;
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
90
104
|
// Firefox fires two extra focus events when the user first clicks into an iframe:
|
|
91
105
|
// first on the window, then on the document. We ignore these events so they don't
|
|
92
106
|
// cause keyboard focus rings to appear.
|
|
93
|
-
|
|
94
|
-
let ownerDocument = (0, $49582955cc364b1c$exports.getOwnerDocument)((0, $da02ee888921bc9e$exports.getEventTarget)(e));
|
|
95
|
-
if ((0, $da02ee888921bc9e$exports.getEventTarget)(e) === ownerWindow || (0, $da02ee888921bc9e$exports.getEventTarget)(e) === ownerDocument || (0, $a9918c67a493892d$exports.ignoreFocusEvent) || !e.isTrusted) return;
|
|
107
|
+
if (target === ownerDocument || !e.isTrusted) return;
|
|
96
108
|
// If a focus event occurs without a preceding keyboard or pointer event, switch to virtual modality.
|
|
97
109
|
// This occurs, for example, when navigating a form with the next/previous buttons on iOS.
|
|
98
110
|
if (!$d0df89f3abe2c2ca$var$hasEventBeforeFocus && !$d0df89f3abe2c2ca$var$hasBlurredWindowRecently) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;;;;;;;AA6BlH,IAAI,wCAAmC;AACvC,IAAI,2CAAkC;AAC/B,MAAM,4CAAiB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ACjC,MAAM,oBACJ,OAAO,gBAAgB,cAAc,YAAY,gBAAgB,GAAG;IACtE,MAAM,uBACJ,OAAO,gBAAgB,cAAc,YAAY,mBAAmB,GAAG;IACzE,MAAM,eAAe,OAAO,gBAAgB,cAAc,YAAY,WAAW,GAAG;IACpF,MAAM,iBACJ,OAAO,gBAAgB,cAAc,YAAY,aAAa,GAAG;IAEnE,qKAAqK;IACrK,kIAAkI;IAClI,IAAI,gBAAgB,CAAA,GAAA,0CAAe,EAAE;IACrC,cACE,eACC,yBAAyB,qBAAqB,CAAC,wCAAkB,GAAG,CAAC,cAAc,IAAI,KACxF,yBAAyB,wBACxB,yBAAyB,gBAAgB,cAAc,iBAAiB;IAC3E,OAAO,CACL,CAAA,eACA,aAAa,cACb,aAAa,kBACb,CAAC,8CAAwB,CAAC,EAAE,GAAG,CAAC,AAAD;AAEnC;AAKO,SAAS,0CAAgB,QAA2B,CAAC,CAAC;IAC3D,IAAI,eAAC,WAAW,aAAE,SAAS,EAAC,GAAG;IAC/B,IAAI,CAAC,qBAAqB,gBAAgB,GAAG,CAAA,GAAA,qBAAO,EAAE,aAAa;IACnE,0CACE,CAAA;QACE,gBAAgB;IAClB,GACA;QAAC;KAAY,EACb;qBAAC;IAAW;IAGd,OAAO;QAAC,gBAAgB;IAAmB;AAC7C;AAKO,SAAS,0CACd,EAAuB,EACvB,IAAwB,EACxB,IAAiD;IAEjD;IAEA,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,MAAM,YAAY,OACpB;QAEF,IAAI,UAAU,CAAC,UAAoB;YACjC,0GAA0G;YAC1G,IAAI,CAAC,2CAAqB,CAAC,CAAC,MAAM,aAAa,UAAU,IACvD;YAEF,GAAG;QACL;QACA,0CAAe,GAAG,CAAC;QACnB,OAAO;YACL,0CAAe,MAAM,CAAC;QACxB;IACA,uDAAuD;IACzD,GAAG;AACL","sources":["packages/react-aria/src/interactions/useFocusVisible.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// Portions of the code in this file are based on code from react.\n// Original licensing for the following can be found in the\n// NOTICE file in the root directory of this source tree.\n// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions\n\nimport {getActiveElement, getEventTarget} from '../utils/shadowdom/DOMFunctions';\n\nimport {getOwnerDocument, getOwnerWindow} from '../utils/domHelpers';\nimport {ignoreFocusEvent} from './utils';\nimport {isMac} from '../utils/platform';\nimport {isVirtualClick} from '../utils/isVirtualEvent';\nimport {openLink} from '../utils/openLink';\nimport {PointerType} from '@react-types/shared';\nimport {useEffect, useState} from 'react';\nimport {useIsSSR} from '../ssr/SSRProvider';\n\nexport type Modality = 'keyboard' | 'pointer' | 'virtual';\ntype HandlerEvent = PointerEvent | MouseEvent | KeyboardEvent | FocusEvent | null;\ntype Handler = (modality: Modality, e: HandlerEvent) => void;\nexport type FocusVisibleHandler = (isFocusVisible: boolean) => void;\nexport interface FocusVisibleProps {\n /** Whether the element is a text input. */\n isTextInput?: boolean;\n /** Whether the element will be auto focused. */\n autoFocus?: boolean;\n}\n\nexport interface FocusVisibleResult {\n /** Whether keyboard focus is visible globally. */\n isFocusVisible: boolean;\n}\n\nlet currentModality: null | Modality = null;\nlet currentPointerType: PointerType = 'keyboard';\nexport const changeHandlers = new Set<Handler>();\ninterface GlobalListenerData {\n focus: () => void;\n}\nexport let hasSetupGlobalListeners: Map<Window, GlobalListenerData> = new Map<\n Window,\n GlobalListenerData\n>(); // We use a map here to support setting event listeners across multiple document objects.\nlet hasEventBeforeFocus = false;\nlet hasBlurredWindowRecently = false;\n\n// Only Tab or Esc keys will make focus visible on text input elements\nconst FOCUS_VISIBLE_INPUT_KEYS = {\n Tab: true,\n Escape: true\n};\n\nfunction triggerChangeHandlers(modality: Modality, e: HandlerEvent) {\n for (let handler of changeHandlers) {\n handler(modality, e);\n }\n}\n\n/**\n * Helper function to determine if a KeyboardEvent is unmodified and could make keyboard focus\n * styles visible.\n */\nfunction isValidKey(e: KeyboardEvent) {\n // Control and Shift keys trigger when navigating back to the tab with keyboard.\n return !(\n e.metaKey ||\n (!isMac() && e.altKey) ||\n e.ctrlKey ||\n e.key === 'Control' ||\n e.key === 'Shift' ||\n e.key === 'Meta'\n );\n}\n\nfunction handleKeyboardEvent(e: KeyboardEvent) {\n hasEventBeforeFocus = true;\n if (!(openLink as any).isOpening && isValidKey(e)) {\n currentModality = 'keyboard';\n currentPointerType = 'keyboard';\n triggerChangeHandlers('keyboard', e);\n }\n}\n\nfunction handlePointerEvent(e: PointerEvent | MouseEvent) {\n currentModality = 'pointer';\n currentPointerType = 'pointerType' in e ? (e.pointerType as PointerType) : 'mouse';\n if (e.type === 'mousedown' || e.type === 'pointerdown') {\n hasEventBeforeFocus = true;\n triggerChangeHandlers('pointer', e);\n }\n}\n\nfunction handleClickEvent(e: MouseEvent) {\n if (!(openLink as any).isOpening && isVirtualClick(e)) {\n hasEventBeforeFocus = true;\n currentModality = 'virtual';\n currentPointerType = 'virtual';\n }\n}\n\nfunction handleFocusEvent(e: FocusEvent) {\n // Firefox fires two extra focus events when the user first clicks into an iframe:\n // first on the window, then on the document. We ignore these events so they don't\n // cause keyboard focus rings to appear.\n let ownerWindow = getOwnerWindow(getEventTarget(e));\n let ownerDocument = getOwnerDocument(getEventTarget(e));\n if (\n getEventTarget(e) === ownerWindow ||\n getEventTarget(e) === ownerDocument ||\n ignoreFocusEvent ||\n !e.isTrusted\n ) {\n return;\n }\n\n // If a focus event occurs without a preceding keyboard or pointer event, switch to virtual modality.\n // This occurs, for example, when navigating a form with the next/previous buttons on iOS.\n if (!hasEventBeforeFocus && !hasBlurredWindowRecently) {\n currentModality = 'virtual';\n currentPointerType = 'virtual';\n triggerChangeHandlers('virtual', e);\n }\n\n hasEventBeforeFocus = false;\n hasBlurredWindowRecently = false;\n}\n\nfunction handleWindowBlur() {\n if (ignoreFocusEvent) {\n return;\n }\n\n // When the window is blurred, reset state. This is necessary when tabbing out of the window,\n // for example, since a subsequent focus event won't be fired.\n hasEventBeforeFocus = false;\n hasBlurredWindowRecently = true;\n}\n\n/**\n * Setup global event listeners to control when keyboard focus style should be visible.\n */\nfunction setupGlobalFocusEvents(element?: HTMLElement | null) {\n // eslint-disable-next-line no-restricted-globals\n if (typeof window === 'undefined' || typeof document === 'undefined') {\n return;\n }\n\n const windowObject = getOwnerWindow(element);\n const documentObject = getOwnerDocument(element);\n\n if (hasSetupGlobalListeners.get(windowObject)) {\n return;\n }\n\n // Programmatic focus() calls shouldn't affect the current input modality.\n // However, we need to detect other cases when a focus event occurs without\n // a preceding user event (e.g. screen reader focus). Overriding the focus\n // method on HTMLElement.prototype is a bit hacky, but works.\n // defineProperty (not assignment) so this works even if `focus` is currently\n // a getter-only accessor — e.g. when @testing-library/user-event's setup()\n // has instrumented it. Plain assignment throws in that case.\n let focus = windowObject.HTMLElement.prototype.focus;\n Reflect.defineProperty(windowObject.HTMLElement.prototype, 'focus', {\n configurable: true,\n writable: true,\n value: function () {\n hasEventBeforeFocus = true;\n focus.apply(this, arguments as unknown as [options?: FocusOptions | undefined]);\n }\n });\n\n documentObject.addEventListener('keydown', handleKeyboardEvent, true);\n documentObject.addEventListener('keyup', handleKeyboardEvent, true);\n documentObject.addEventListener('click', handleClickEvent, true);\n\n // Register focus events on the window so they are sure to happen\n // before React's event listeners (registered on the document).\n windowObject.addEventListener('focus', handleFocusEvent, true);\n windowObject.addEventListener('blur', handleWindowBlur, false);\n\n if (typeof PointerEvent !== 'undefined') {\n documentObject.addEventListener('pointerdown', handlePointerEvent, true);\n documentObject.addEventListener('pointermove', handlePointerEvent, true);\n documentObject.addEventListener('pointerup', handlePointerEvent, true);\n } else if (process.env.NODE_ENV === 'test') {\n documentObject.addEventListener('mousedown', handlePointerEvent, true);\n documentObject.addEventListener('mousemove', handlePointerEvent, true);\n documentObject.addEventListener('mouseup', handlePointerEvent, true);\n }\n\n // Add unmount handler\n windowObject.addEventListener(\n 'beforeunload',\n () => {\n tearDownWindowFocusTracking(element);\n },\n {once: true}\n );\n\n hasSetupGlobalListeners.set(windowObject, {focus});\n}\n\nconst tearDownWindowFocusTracking = (element, loadListener?: () => void) => {\n const windowObject = getOwnerWindow(element);\n const documentObject = getOwnerDocument(element);\n if (loadListener) {\n documentObject.removeEventListener('DOMContentLoaded', loadListener);\n }\n if (!hasSetupGlobalListeners.has(windowObject)) {\n return;\n }\n Reflect.defineProperty(windowObject.HTMLElement.prototype, 'focus', {\n configurable: true,\n writable: true,\n value: hasSetupGlobalListeners.get(windowObject)!.focus\n });\n\n documentObject.removeEventListener('keydown', handleKeyboardEvent, true);\n documentObject.removeEventListener('keyup', handleKeyboardEvent, true);\n documentObject.removeEventListener('click', handleClickEvent, true);\n\n windowObject.removeEventListener('focus', handleFocusEvent, true);\n windowObject.removeEventListener('blur', handleWindowBlur, false);\n\n if (typeof PointerEvent !== 'undefined') {\n documentObject.removeEventListener('pointerdown', handlePointerEvent, true);\n documentObject.removeEventListener('pointermove', handlePointerEvent, true);\n documentObject.removeEventListener('pointerup', handlePointerEvent, true);\n } else if (process.env.NODE_ENV === 'test') {\n documentObject.removeEventListener('mousedown', handlePointerEvent, true);\n documentObject.removeEventListener('mousemove', handlePointerEvent, true);\n documentObject.removeEventListener('mouseup', handlePointerEvent, true);\n }\n\n hasSetupGlobalListeners.delete(windowObject);\n};\n\n/**\n * EXPERIMENTAL\n * Adds a window (i.e. iframe) to the list of windows that are being tracked for focus visible.\n *\n * Sometimes apps render portions of their tree into an iframe. In this case, we cannot accurately\n * track if the focus is visible because we cannot see interactions inside the iframe. If you have\n * this in your application's architecture, then this function will attach event listeners inside\n * the iframe. You should call `addWindowFocusTracking` with an element from inside the window you\n * wish to add. We'll retrieve the relevant elements based on that. Note, you do not need to call\n * this for the default window, as we call it for you.\n *\n * When you are ready to stop listening, but you do not wish to unmount the iframe, you may call the\n * cleanup function returned by `addWindowFocusTracking`. Otherwise, when you unmount the iframe,\n * all listeners and state will be cleaned up automatically for you.\n *\n * @param element @default document.body - The element provided will be used to get the window to\n * add.\n * @returns A function to remove the event listeners and cleanup the state.\n */\nexport function addWindowFocusTracking(element?: HTMLElement | null): () => void {\n const documentObject = getOwnerDocument(element);\n let loadListener;\n if (documentObject.readyState !== 'loading') {\n setupGlobalFocusEvents(element);\n } else {\n loadListener = () => {\n setupGlobalFocusEvents(element);\n };\n documentObject.addEventListener('DOMContentLoaded', loadListener);\n }\n\n return () => tearDownWindowFocusTracking(element, loadListener);\n}\n\n// Server-side rendering does not have the document object defined\n// eslint-disable-next-line no-restricted-globals\nif (typeof document !== 'undefined') {\n addWindowFocusTracking();\n}\n\n/**\n * If true, keyboard focus is visible.\n */\nexport function isFocusVisible(): boolean {\n return currentModality !== 'pointer';\n}\n\nexport function getInteractionModality(): Modality | null {\n return currentModality;\n}\n\nexport function setInteractionModality(modality: Modality): void {\n currentModality = modality;\n currentPointerType = modality === 'pointer' ? 'mouse' : modality;\n triggerChangeHandlers(modality, null);\n}\n\n/** @private */\nexport function getPointerType(): PointerType {\n return currentPointerType;\n}\n\n/**\n * Keeps state of the current modality.\n */\nexport function useInteractionModality(): Modality | null {\n setupGlobalFocusEvents();\n\n let [modality, setModality] = useState(currentModality);\n useEffect(() => {\n let handler = () => {\n setModality(currentModality);\n };\n\n changeHandlers.add(handler);\n return () => {\n changeHandlers.delete(handler);\n };\n }, []);\n\n return useIsSSR() ? null : modality;\n}\n\nconst nonTextInputTypes = new Set([\n 'checkbox',\n 'radio',\n 'range',\n 'color',\n 'file',\n 'image',\n 'button',\n 'submit',\n 'reset'\n]);\n\n/**\n * If this is attached to text input component, return if the event is a focus event (Tab/Escape\n * keys pressed) so that focus visible style can be properly set.\n */\nfunction isKeyboardFocusEvent(isTextInput: boolean, modality: Modality, e: HandlerEvent) {\n let eventTarget = e ? (getEventTarget(e) as Element) : undefined;\n let ownerDocument = getOwnerDocument(eventTarget);\n let ownerWindow = getOwnerWindow(eventTarget);\n const IHTMLInputElement =\n typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLInputElement : HTMLInputElement;\n const IHTMLTextAreaElement =\n typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLTextAreaElement : HTMLTextAreaElement;\n const IHTMLElement = typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLElement : HTMLElement;\n const IKeyboardEvent =\n typeof ownerWindow !== 'undefined' ? ownerWindow.KeyboardEvent : KeyboardEvent;\n\n // For keyboard events that occur on a non-input element that will move focus into input element (aka ArrowLeft going from Datepicker button to the main input group)\n // we need to rely on the user passing isTextInput into here. This way we can skip toggling focus visiblity for said input element\n let activeElement = getActiveElement(ownerDocument);\n isTextInput =\n isTextInput ||\n (activeElement instanceof IHTMLInputElement && !nonTextInputTypes.has(activeElement.type)) ||\n activeElement instanceof IHTMLTextAreaElement ||\n (activeElement instanceof IHTMLElement && activeElement.isContentEditable);\n return !(\n isTextInput &&\n modality === 'keyboard' &&\n e instanceof IKeyboardEvent &&\n !FOCUS_VISIBLE_INPUT_KEYS[e.key]\n );\n}\n\n/**\n * Manages focus visible state for the page, and subscribes individual components for updates.\n */\nexport function useFocusVisible(props: FocusVisibleProps = {}): FocusVisibleResult {\n let {isTextInput, autoFocus} = props;\n let [isFocusVisibleState, setFocusVisible] = useState(autoFocus || isFocusVisible());\n useFocusVisibleListener(\n isFocusVisible => {\n setFocusVisible(isFocusVisible);\n },\n [isTextInput],\n {isTextInput}\n );\n\n return {isFocusVisible: isFocusVisibleState};\n}\n\n/**\n * Listens for trigger change and reports if focus is visible (i.e., modality is not pointer).\n */\nexport function useFocusVisibleListener(\n fn: FocusVisibleHandler,\n deps: ReadonlyArray<any>,\n opts?: {enabled?: boolean; isTextInput?: boolean}\n): void {\n setupGlobalFocusEvents();\n\n useEffect(() => {\n if (opts?.enabled === false) {\n return;\n }\n let handler = (modality: Modality, e: HandlerEvent) => {\n // We want to early return for any keyboard events that occur inside text inputs EXCEPT for Tab and Escape\n if (!isKeyboardFocusEvent(!!opts?.isTextInput, modality, e)) {\n return;\n }\n fn(isFocusVisible());\n };\n changeHandlers.add(handler);\n return () => {\n changeHandlers.delete(handler);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n}\n"],"names":[],"version":3,"file":"useFocusVisible.cjs.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;;;;;;;AA6BlH,IAAI,wCAAmC;AACvC,IAAI,2CAAkC;AAC/B,MAAM,4CAAiB,IAAI;AAI3B,IAAI,4CAA2D,IAAI,OAGrE,yFAAyF;AAC9F,IAAI,4CAAsB;AAC1B,IAAI,iDAA2B;AAE/B,sEAAsE;AACtE,MAAM,iDAA2B;IAC/B,KAAK;IACL,QAAQ;AACV;AAEA,SAAS,4CAAsB,QAAkB,EAAE,CAAe;IAChE,KAAK,IAAI,WAAW,0CAClB,QAAQ,UAAU;AAEtB;AAEA;;;CAGC,GACD,SAAS,iCAAW,CAAgB;IAClC,gFAAgF;IAChF,OAAO,CACL,CAAA,EAAE,OAAO,IACR,CAAC,CAAA,GAAA,+BAAI,OAAO,EAAE,MAAM,IACrB,EAAE,OAAO,IACT,EAAE,GAAG,KAAK,aACV,EAAE,GAAG,KAAK,WACV,EAAE,GAAG,KAAK,MAAK;AAEnB;AAEA,SAAS,0CAAoB,CAAgB;IAC3C,4CAAsB;IACtB,IAAI,CAAC,AAAC,CAAA,GAAA,kCAAO,EAAU,SAAS,IAAI,iCAAW,IAAI;QACjD,wCAAkB;QAClB,2CAAqB;QACrB,4CAAsB,YAAY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C3D,IAAI,eAAC,WAAW,aAAE,SAAS,EAAC,GAAG;IAC/B,IAAI,CAAC,qBAAqB,gBAAgB,GAAG,CAAA,GAAA,qBAAO,EAAE,aAAa;IACnE,0CACE,CAAA;QACE,gBAAgB;IAClB,GACA;QAAC;KAAY,EACb;qBAAC;IAAW;IAGd,OAAO;QAAC,gBAAgB;IAAmB;AAC7C;AAKO,SAAS,0CACd,EAAuB,EACvB,IAAwB,EACxB,IAAiD;IAEjD;IAEA,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,MAAM,YAAY,OACpB;QAEF,IAAI,UAAU,CAAC,UAAoB;YACjC,0GAA0G;YAC1G,IAAI,CAAC,2CAAqB,CAAC,CAAC,MAAM,aAAa,UAAU,IACvD;YAEF,GAAG;QACL;QACA,0CAAe,GAAG,CAAC;QACnB,OAAO;YACL,0CAAe,MAAM,CAAC;QACxB;IACA,uDAAuD;IACzD,GAAG;AACL","sources":["packages/react-aria/src/interactions/useFocusVisible.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// Portions of the code in this file are based on code from react.\n// Original licensing for the following can be found in the\n// NOTICE file in the root directory of this source tree.\n// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions\n\nimport {getActiveElement, getEventTarget} from '../utils/shadowdom/DOMFunctions';\n\nimport {getOwnerDocument, getOwnerWindow} from '../utils/domHelpers';\nimport {ignoreFocusEvent} from './utils';\nimport {isMac} from '../utils/platform';\nimport {isVirtualClick} from '../utils/isVirtualEvent';\nimport {openLink} from '../utils/openLink';\nimport {PointerType} from '@react-types/shared';\nimport {useEffect, useState} from 'react';\nimport {useIsSSR} from '../ssr/SSRProvider';\n\nexport type Modality = 'keyboard' | 'pointer' | 'virtual';\ntype HandlerEvent = PointerEvent | MouseEvent | KeyboardEvent | FocusEvent | null;\ntype Handler = (modality: Modality, e: HandlerEvent) => void;\nexport type FocusVisibleHandler = (isFocusVisible: boolean) => void;\nexport interface FocusVisibleProps {\n /** Whether the element is a text input. */\n isTextInput?: boolean;\n /** Whether the element will be auto focused. */\n autoFocus?: boolean;\n}\n\nexport interface FocusVisibleResult {\n /** Whether keyboard focus is visible globally. */\n isFocusVisible: boolean;\n}\n\nlet currentModality: null | Modality = null;\nlet currentPointerType: PointerType = 'keyboard';\nexport const changeHandlers = new Set<Handler>();\ninterface GlobalListenerData {\n focus: () => void;\n}\nexport let hasSetupGlobalListeners: Map<Window, GlobalListenerData> = new Map<\n Window,\n GlobalListenerData\n>(); // We use a map here to support setting event listeners across multiple document objects.\nlet hasEventBeforeFocus = false;\nlet hasBlurredWindowRecently = false;\n\n// Only Tab or Esc keys will make focus visible on text input elements\nconst FOCUS_VISIBLE_INPUT_KEYS = {\n Tab: true,\n Escape: true\n};\n\nfunction triggerChangeHandlers(modality: Modality, e: HandlerEvent) {\n for (let handler of changeHandlers) {\n handler(modality, e);\n }\n}\n\n/**\n * Helper function to determine if a KeyboardEvent is unmodified and could make keyboard focus\n * styles visible.\n */\nfunction isValidKey(e: KeyboardEvent) {\n // Control and Shift keys trigger when navigating back to the tab with keyboard.\n return !(\n e.metaKey ||\n (!isMac() && e.altKey) ||\n e.ctrlKey ||\n e.key === 'Control' ||\n e.key === 'Shift' ||\n e.key === 'Meta'\n );\n}\n\nfunction handleKeyboardEvent(e: KeyboardEvent) {\n hasEventBeforeFocus = true;\n if (!(openLink as any).isOpening && isValidKey(e)) {\n currentModality = 'keyboard';\n currentPointerType = 'keyboard';\n triggerChangeHandlers('keyboard', e);\n }\n}\n\nfunction handlePointerEvent(e: PointerEvent | MouseEvent) {\n currentModality = 'pointer';\n currentPointerType = 'pointerType' in e ? (e.pointerType as PointerType) : 'mouse';\n if (e.type === 'mousedown' || e.type === 'pointerdown') {\n hasEventBeforeFocus = true;\n triggerChangeHandlers('pointer', e);\n }\n}\n\nfunction handleClickEvent(e: MouseEvent) {\n if (!(openLink as any).isOpening && isVirtualClick(e)) {\n hasEventBeforeFocus = true;\n currentModality = 'virtual';\n currentPointerType = 'virtual';\n }\n}\n\nfunction handleFocusEvent(e: FocusEvent) {\n if (ignoreFocusEvent) {\n return;\n }\n\n let target = getEventTarget(e);\n let ownerWindow = getOwnerWindow(target);\n let ownerDocument = getOwnerDocument(target);\n\n // When the window regains focus, the browser restores focus to the element that was focused\n // before, firing a focus event the user did not initiate. handleWindowBlur sets\n // hasBlurredWindowRecently so restored focus doesn't switch to virtual modality below, but\n // Safari fires the window/element focus pair twice when returning to a tab or app and the first\n // element focus event clears the flag, so re-arm it whenever the window itself is focused.\n // Like handleWindowBlur, this intentionally doesn't check isTrusted.\n if (target === ownerWindow) {\n hasBlurredWindowRecently = true;\n return;\n }\n\n // Firefox fires two extra focus events when the user first clicks into an iframe:\n // first on the window, then on the document. We ignore these events so they don't\n // cause keyboard focus rings to appear.\n if (target === ownerDocument || !e.isTrusted) {\n return;\n }\n\n // If a focus event occurs without a preceding keyboard or pointer event, switch to virtual modality.\n // This occurs, for example, when navigating a form with the next/previous buttons on iOS.\n if (!hasEventBeforeFocus && !hasBlurredWindowRecently) {\n currentModality = 'virtual';\n currentPointerType = 'virtual';\n triggerChangeHandlers('virtual', e);\n }\n\n hasEventBeforeFocus = false;\n hasBlurredWindowRecently = false;\n}\n\nfunction handleWindowBlur() {\n if (ignoreFocusEvent) {\n return;\n }\n\n // When the window is blurred, reset state. This is necessary when tabbing out of the window,\n // for example, since a subsequent focus event won't be fired.\n hasEventBeforeFocus = false;\n hasBlurredWindowRecently = true;\n}\n\n/**\n * Setup global event listeners to control when keyboard focus style should be visible.\n */\nfunction setupGlobalFocusEvents(element?: HTMLElement | null) {\n // eslint-disable-next-line no-restricted-globals\n if (typeof window === 'undefined' || typeof document === 'undefined') {\n return;\n }\n\n const windowObject = getOwnerWindow(element);\n const documentObject = getOwnerDocument(element);\n\n if (hasSetupGlobalListeners.get(windowObject)) {\n return;\n }\n\n // Programmatic focus() calls shouldn't affect the current input modality.\n // However, we need to detect other cases when a focus event occurs without\n // a preceding user event (e.g. screen reader focus). Overriding the focus\n // method on HTMLElement.prototype is a bit hacky, but works.\n // defineProperty (not assignment) so this works even if `focus` is currently\n // a getter-only accessor — e.g. when @testing-library/user-event's setup()\n // has instrumented it. Plain assignment throws in that case.\n let focus = windowObject.HTMLElement.prototype.focus;\n Reflect.defineProperty(windowObject.HTMLElement.prototype, 'focus', {\n configurable: true,\n writable: true,\n value: function () {\n hasEventBeforeFocus = true;\n focus.apply(this, arguments as unknown as [options?: FocusOptions | undefined]);\n }\n });\n\n documentObject.addEventListener('keydown', handleKeyboardEvent, true);\n documentObject.addEventListener('keyup', handleKeyboardEvent, true);\n documentObject.addEventListener('click', handleClickEvent, true);\n\n // Register focus events on the window so they are sure to happen\n // before React's event listeners (registered on the document).\n windowObject.addEventListener('focus', handleFocusEvent, true);\n windowObject.addEventListener('blur', handleWindowBlur, false);\n\n if (typeof PointerEvent !== 'undefined') {\n documentObject.addEventListener('pointerdown', handlePointerEvent, true);\n documentObject.addEventListener('pointermove', handlePointerEvent, true);\n documentObject.addEventListener('pointerup', handlePointerEvent, true);\n } else if (process.env.NODE_ENV === 'test') {\n documentObject.addEventListener('mousedown', handlePointerEvent, true);\n documentObject.addEventListener('mousemove', handlePointerEvent, true);\n documentObject.addEventListener('mouseup', handlePointerEvent, true);\n }\n\n // Add unmount handler\n windowObject.addEventListener(\n 'beforeunload',\n () => {\n tearDownWindowFocusTracking(element);\n },\n {once: true}\n );\n\n hasSetupGlobalListeners.set(windowObject, {focus});\n}\n\nconst tearDownWindowFocusTracking = (element, loadListener?: () => void) => {\n const windowObject = getOwnerWindow(element);\n const documentObject = getOwnerDocument(element);\n if (loadListener) {\n documentObject.removeEventListener('DOMContentLoaded', loadListener);\n }\n if (!hasSetupGlobalListeners.has(windowObject)) {\n return;\n }\n Reflect.defineProperty(windowObject.HTMLElement.prototype, 'focus', {\n configurable: true,\n writable: true,\n value: hasSetupGlobalListeners.get(windowObject)!.focus\n });\n\n documentObject.removeEventListener('keydown', handleKeyboardEvent, true);\n documentObject.removeEventListener('keyup', handleKeyboardEvent, true);\n documentObject.removeEventListener('click', handleClickEvent, true);\n\n windowObject.removeEventListener('focus', handleFocusEvent, true);\n windowObject.removeEventListener('blur', handleWindowBlur, false);\n\n if (typeof PointerEvent !== 'undefined') {\n documentObject.removeEventListener('pointerdown', handlePointerEvent, true);\n documentObject.removeEventListener('pointermove', handlePointerEvent, true);\n documentObject.removeEventListener('pointerup', handlePointerEvent, true);\n } else if (process.env.NODE_ENV === 'test') {\n documentObject.removeEventListener('mousedown', handlePointerEvent, true);\n documentObject.removeEventListener('mousemove', handlePointerEvent, true);\n documentObject.removeEventListener('mouseup', handlePointerEvent, true);\n }\n\n hasSetupGlobalListeners.delete(windowObject);\n};\n\n/**\n * EXPERIMENTAL\n * Adds a window (i.e. iframe) to the list of windows that are being tracked for focus visible.\n *\n * Sometimes apps render portions of their tree into an iframe. In this case, we cannot accurately\n * track if the focus is visible because we cannot see interactions inside the iframe. If you have\n * this in your application's architecture, then this function will attach event listeners inside\n * the iframe. You should call `addWindowFocusTracking` with an element from inside the window you\n * wish to add. We'll retrieve the relevant elements based on that. Note, you do not need to call\n * this for the default window, as we call it for you.\n *\n * When you are ready to stop listening, but you do not wish to unmount the iframe, you may call the\n * cleanup function returned by `addWindowFocusTracking`. Otherwise, when you unmount the iframe,\n * all listeners and state will be cleaned up automatically for you.\n *\n * @param element @default document.body - The element provided will be used to get the window to\n * add.\n * @returns A function to remove the event listeners and cleanup the state.\n */\nexport function addWindowFocusTracking(element?: HTMLElement | null): () => void {\n const documentObject = getOwnerDocument(element);\n let loadListener;\n if (documentObject.readyState !== 'loading') {\n setupGlobalFocusEvents(element);\n } else {\n loadListener = () => {\n setupGlobalFocusEvents(element);\n };\n documentObject.addEventListener('DOMContentLoaded', loadListener);\n }\n\n return () => tearDownWindowFocusTracking(element, loadListener);\n}\n\n// Server-side rendering does not have the document object defined\n// eslint-disable-next-line no-restricted-globals\nif (typeof document !== 'undefined') {\n addWindowFocusTracking();\n}\n\n/**\n * If true, keyboard focus is visible.\n */\nexport function isFocusVisible(): boolean {\n return currentModality !== 'pointer';\n}\n\nexport function getInteractionModality(): Modality | null {\n return currentModality;\n}\n\nexport function setInteractionModality(modality: Modality): void {\n currentModality = modality;\n currentPointerType = modality === 'pointer' ? 'mouse' : modality;\n triggerChangeHandlers(modality, null);\n}\n\n/** @private */\nexport function getPointerType(): PointerType {\n return currentPointerType;\n}\n\n/**\n * Keeps state of the current modality.\n */\nexport function useInteractionModality(): Modality | null {\n setupGlobalFocusEvents();\n\n let [modality, setModality] = useState(currentModality);\n useEffect(() => {\n let handler = () => {\n setModality(currentModality);\n };\n\n changeHandlers.add(handler);\n return () => {\n changeHandlers.delete(handler);\n };\n }, []);\n\n return useIsSSR() ? null : modality;\n}\n\nconst nonTextInputTypes = new Set([\n 'checkbox',\n 'radio',\n 'range',\n 'color',\n 'file',\n 'image',\n 'button',\n 'submit',\n 'reset'\n]);\n\n/**\n * If this is attached to text input component, return if the event is a focus event (Tab/Escape\n * keys pressed) so that focus visible style can be properly set.\n */\nfunction isKeyboardFocusEvent(isTextInput: boolean, modality: Modality, e: HandlerEvent) {\n let eventTarget = e ? (getEventTarget(e) as Element) : undefined;\n let ownerDocument = getOwnerDocument(eventTarget);\n let ownerWindow = getOwnerWindow(eventTarget);\n const IHTMLInputElement =\n typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLInputElement : HTMLInputElement;\n const IHTMLTextAreaElement =\n typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLTextAreaElement : HTMLTextAreaElement;\n const IHTMLElement = typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLElement : HTMLElement;\n const IKeyboardEvent =\n typeof ownerWindow !== 'undefined' ? ownerWindow.KeyboardEvent : KeyboardEvent;\n\n // For keyboard events that occur on a non-input element that will move focus into input element (aka ArrowLeft going from Datepicker button to the main input group)\n // we need to rely on the user passing isTextInput into here. This way we can skip toggling focus visiblity for said input element\n let activeElement = getActiveElement(ownerDocument);\n isTextInput =\n isTextInput ||\n (activeElement instanceof IHTMLInputElement && !nonTextInputTypes.has(activeElement.type)) ||\n activeElement instanceof IHTMLTextAreaElement ||\n (activeElement instanceof IHTMLElement && activeElement.isContentEditable);\n return !(\n isTextInput &&\n modality === 'keyboard' &&\n e instanceof IKeyboardEvent &&\n !FOCUS_VISIBLE_INPUT_KEYS[e.key]\n );\n}\n\n/**\n * Manages focus visible state for the page, and subscribes individual components for updates.\n */\nexport function useFocusVisible(props: FocusVisibleProps = {}): FocusVisibleResult {\n let {isTextInput, autoFocus} = props;\n let [isFocusVisibleState, setFocusVisible] = useState(autoFocus || isFocusVisible());\n useFocusVisibleListener(\n isFocusVisible => {\n setFocusVisible(isFocusVisible);\n },\n [isTextInput],\n {isTextInput}\n );\n\n return {isFocusVisible: isFocusVisibleState};\n}\n\n/**\n * Listens for trigger change and reports if focus is visible (i.e., modality is not pointer).\n */\nexport function useFocusVisibleListener(\n fn: FocusVisibleHandler,\n deps: ReadonlyArray<any>,\n opts?: {enabled?: boolean; isTextInput?: boolean}\n): void {\n setupGlobalFocusEvents();\n\n useEffect(() => {\n if (opts?.enabled === false) {\n return;\n }\n let handler = (modality: Modality, e: HandlerEvent) => {\n // We want to early return for any keyboard events that occur inside text inputs EXCEPT for Tab and Escape\n if (!isKeyboardFocusEvent(!!opts?.isTextInput, modality, e)) {\n return;\n }\n fn(isFocusVisible());\n };\n changeHandlers.add(handler);\n return () => {\n changeHandlers.delete(handler);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n}\n"],"names":[],"version":3,"file":"useFocusVisible.cjs.map"}
|
|
@@ -74,12 +74,24 @@ function $b50b1cc8a843ace7$var$handleClickEvent(e) {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
function $b50b1cc8a843ace7$var$handleFocusEvent(e) {
|
|
77
|
+
if (0, $819bf6b2be9219ca$export$fda7da73ab5d4c48) return;
|
|
78
|
+
let target = (0, $d8ac7ed472840322$export$e58f029f0fbfdb29)(e);
|
|
79
|
+
let ownerWindow = (0, $cc3c3666b64debad$export$f21a1ffae260145a)(target);
|
|
80
|
+
let ownerDocument = (0, $cc3c3666b64debad$export$b204af158042fbac)(target);
|
|
81
|
+
// When the window regains focus, the browser restores focus to the element that was focused
|
|
82
|
+
// before, firing a focus event the user did not initiate. handleWindowBlur sets
|
|
83
|
+
// hasBlurredWindowRecently so restored focus doesn't switch to virtual modality below, but
|
|
84
|
+
// Safari fires the window/element focus pair twice when returning to a tab or app and the first
|
|
85
|
+
// element focus event clears the flag, so re-arm it whenever the window itself is focused.
|
|
86
|
+
// Like handleWindowBlur, this intentionally doesn't check isTrusted.
|
|
87
|
+
if (target === ownerWindow) {
|
|
88
|
+
$b50b1cc8a843ace7$var$hasBlurredWindowRecently = true;
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
77
91
|
// Firefox fires two extra focus events when the user first clicks into an iframe:
|
|
78
92
|
// first on the window, then on the document. We ignore these events so they don't
|
|
79
93
|
// cause keyboard focus rings to appear.
|
|
80
|
-
|
|
81
|
-
let ownerDocument = (0, $cc3c3666b64debad$export$b204af158042fbac)((0, $d8ac7ed472840322$export$e58f029f0fbfdb29)(e));
|
|
82
|
-
if ((0, $d8ac7ed472840322$export$e58f029f0fbfdb29)(e) === ownerWindow || (0, $d8ac7ed472840322$export$e58f029f0fbfdb29)(e) === ownerDocument || (0, $819bf6b2be9219ca$export$fda7da73ab5d4c48) || !e.isTrusted) return;
|
|
94
|
+
if (target === ownerDocument || !e.isTrusted) return;
|
|
83
95
|
// If a focus event occurs without a preceding keyboard or pointer event, switch to virtual modality.
|
|
84
96
|
// This occurs, for example, when navigating a form with the next/previous buttons on iOS.
|
|
85
97
|
if (!$b50b1cc8a843ace7$var$hasEventBeforeFocus && !$b50b1cc8a843ace7$var$hasBlurredWindowRecently) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;;;;;;;AA6BlH,IAAI,wCAAmC;AACvC,IAAI,2CAAkC;AAC/B,MAAM,4CAAiB,IAAI;AAI3B,IAAI,4CAA2D,IAAI,OAGrE,yFAAyF;AAC9F,IAAI,4CAAsB;AAC1B,IAAI,iDAA2B;AAE/B,sEAAsE;AACtE,MAAM,iDAA2B;IAC/B,KAAK;IACL,QAAQ;AACV;AAEA,SAAS,4CAAsB,QAAkB,EAAE,CAAe;IAChE,KAAK,IAAI,WAAW,0CAClB,QAAQ,UAAU;AAEtB;AAEA;;;CAGC,GACD,SAAS,iCAAW,CAAgB;IAClC,gFAAgF;IAChF,OAAO,CACL,CAAA,EAAE,OAAO,IACR,CAAC,CAAA,GAAA,yCAAI,OAAO,EAAE,MAAM,IACrB,EAAE,OAAO,IACT,EAAE,GAAG,KAAK,aACV,EAAE,GAAG,KAAK,WACV,EAAE,GAAG,KAAK,MAAK;AAEnB;AAEA,SAAS,0CAAoB,CAAgB;IAC3C,4CAAsB;IACtB,IAAI,CAAC,AAAC,CAAA,GAAA,yCAAO,EAAU,SAAS,IAAI,iCAAW,IAAI;QACjD,wCAAkB;QAClB,2CAAqB;QACrB,4CAAsB,YAAY;IACpC;AACF;AAEA,SAAS,yCAAmB,CAA4B;IACtD,wCAAkB;IAClB,2CAAqB,iBAAiB,IAAK,EAAE,WAAW,GAAmB;IAC3E,IAAI,EAAE,IAAI,KAAK,eAAe,EAAE,IAAI,KAAK,eAAe;QACtD,4CAAsB;QACtB,4CAAsB,WAAW;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,IAAiD;IAEjD;IAEA,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,CAAA,iBAAA,2BAAA,KAAM,OAAO,MAAK,OACpB;QAEF,IAAI,UAAU,CAAC,UAAoB;YACjC,0GAA0G;YAC1G,IAAI,CAAC,2CAAqB,CAAC,EAAC,iBAAA,2BAAA,KAAM,WAAW,GAAE,UAAU,IACvD;YAEF,GAAG;QACL;QACA,0CAAe,GAAG,CAAC;QACnB,OAAO;YACL,0CAAe,MAAM,CAAC;QACxB;IACA,uDAAuD;IACzD,GAAG;AACL","sources":["packages/react-aria/src/interactions/useFocusVisible.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// Portions of the code in this file are based on code from react.\n// Original licensing for the following can be found in the\n// NOTICE file in the root directory of this source tree.\n// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions\n\nimport {getActiveElement, getEventTarget} from '../utils/shadowdom/DOMFunctions';\n\nimport {getOwnerDocument, getOwnerWindow} from '../utils/domHelpers';\nimport {ignoreFocusEvent} from './utils';\nimport {isMac} from '../utils/platform';\nimport {isVirtualClick} from '../utils/isVirtualEvent';\nimport {openLink} from '../utils/openLink';\nimport {PointerType} from '@react-types/shared';\nimport {useEffect, useState} from 'react';\nimport {useIsSSR} from '../ssr/SSRProvider';\n\nexport type Modality = 'keyboard' | 'pointer' | 'virtual';\ntype HandlerEvent = PointerEvent | MouseEvent | KeyboardEvent | FocusEvent | null;\ntype Handler = (modality: Modality, e: HandlerEvent) => void;\nexport type FocusVisibleHandler = (isFocusVisible: boolean) => void;\nexport interface FocusVisibleProps {\n /** Whether the element is a text input. */\n isTextInput?: boolean;\n /** Whether the element will be auto focused. */\n autoFocus?: boolean;\n}\n\nexport interface FocusVisibleResult {\n /** Whether keyboard focus is visible globally. */\n isFocusVisible: boolean;\n}\n\nlet currentModality: null | Modality = null;\nlet currentPointerType: PointerType = 'keyboard';\nexport const changeHandlers = new Set<Handler>();\ninterface GlobalListenerData {\n focus: () => void;\n}\nexport let hasSetupGlobalListeners: Map<Window, GlobalListenerData> = new Map<\n Window,\n GlobalListenerData\n>(); // We use a map here to support setting event listeners across multiple document objects.\nlet hasEventBeforeFocus = false;\nlet hasBlurredWindowRecently = false;\n\n// Only Tab or Esc keys will make focus visible on text input elements\nconst FOCUS_VISIBLE_INPUT_KEYS = {\n Tab: true,\n Escape: true\n};\n\nfunction triggerChangeHandlers(modality: Modality, e: HandlerEvent) {\n for (let handler of changeHandlers) {\n handler(modality, e);\n }\n}\n\n/**\n * Helper function to determine if a KeyboardEvent is unmodified and could make keyboard focus\n * styles visible.\n */\nfunction isValidKey(e: KeyboardEvent) {\n // Control and Shift keys trigger when navigating back to the tab with keyboard.\n return !(\n e.metaKey ||\n (!isMac() && e.altKey) ||\n e.ctrlKey ||\n e.key === 'Control' ||\n e.key === 'Shift' ||\n e.key === 'Meta'\n );\n}\n\nfunction handleKeyboardEvent(e: KeyboardEvent) {\n hasEventBeforeFocus = true;\n if (!(openLink as any).isOpening && isValidKey(e)) {\n currentModality = 'keyboard';\n currentPointerType = 'keyboard';\n triggerChangeHandlers('keyboard', e);\n }\n}\n\nfunction handlePointerEvent(e: PointerEvent | MouseEvent) {\n currentModality = 'pointer';\n currentPointerType = 'pointerType' in e ? (e.pointerType as PointerType) : 'mouse';\n if (e.type === 'mousedown' || e.type === 'pointerdown') {\n hasEventBeforeFocus = true;\n triggerChangeHandlers('pointer', e);\n }\n}\n\nfunction handleClickEvent(e: MouseEvent) {\n if (!(openLink as any).isOpening && isVirtualClick(e)) {\n hasEventBeforeFocus = true;\n currentModality = 'virtual';\n currentPointerType = 'virtual';\n }\n}\n\nfunction handleFocusEvent(e: FocusEvent) {\n // Firefox fires two extra focus events when the user first clicks into an iframe:\n // first on the window, then on the document. We ignore these events so they don't\n // cause keyboard focus rings to appear.\n let ownerWindow = getOwnerWindow(getEventTarget(e));\n let ownerDocument = getOwnerDocument(getEventTarget(e));\n if (\n getEventTarget(e) === ownerWindow ||\n getEventTarget(e) === ownerDocument ||\n ignoreFocusEvent ||\n !e.isTrusted\n ) {\n return;\n }\n\n // If a focus event occurs without a preceding keyboard or pointer event, switch to virtual modality.\n // This occurs, for example, when navigating a form with the next/previous buttons on iOS.\n if (!hasEventBeforeFocus && !hasBlurredWindowRecently) {\n currentModality = 'virtual';\n currentPointerType = 'virtual';\n triggerChangeHandlers('virtual', e);\n }\n\n hasEventBeforeFocus = false;\n hasBlurredWindowRecently = false;\n}\n\nfunction handleWindowBlur() {\n if (ignoreFocusEvent) {\n return;\n }\n\n // When the window is blurred, reset state. This is necessary when tabbing out of the window,\n // for example, since a subsequent focus event won't be fired.\n hasEventBeforeFocus = false;\n hasBlurredWindowRecently = true;\n}\n\n/**\n * Setup global event listeners to control when keyboard focus style should be visible.\n */\nfunction setupGlobalFocusEvents(element?: HTMLElement | null) {\n // eslint-disable-next-line no-restricted-globals\n if (typeof window === 'undefined' || typeof document === 'undefined') {\n return;\n }\n\n const windowObject = getOwnerWindow(element);\n const documentObject = getOwnerDocument(element);\n\n if (hasSetupGlobalListeners.get(windowObject)) {\n return;\n }\n\n // Programmatic focus() calls shouldn't affect the current input modality.\n // However, we need to detect other cases when a focus event occurs without\n // a preceding user event (e.g. screen reader focus). Overriding the focus\n // method on HTMLElement.prototype is a bit hacky, but works.\n // defineProperty (not assignment) so this works even if `focus` is currently\n // a getter-only accessor — e.g. when @testing-library/user-event's setup()\n // has instrumented it. Plain assignment throws in that case.\n let focus = windowObject.HTMLElement.prototype.focus;\n Reflect.defineProperty(windowObject.HTMLElement.prototype, 'focus', {\n configurable: true,\n writable: true,\n value: function () {\n hasEventBeforeFocus = true;\n focus.apply(this, arguments as unknown as [options?: FocusOptions | undefined]);\n }\n });\n\n documentObject.addEventListener('keydown', handleKeyboardEvent, true);\n documentObject.addEventListener('keyup', handleKeyboardEvent, true);\n documentObject.addEventListener('click', handleClickEvent, true);\n\n // Register focus events on the window so they are sure to happen\n // before React's event listeners (registered on the document).\n windowObject.addEventListener('focus', handleFocusEvent, true);\n windowObject.addEventListener('blur', handleWindowBlur, false);\n\n if (typeof PointerEvent !== 'undefined') {\n documentObject.addEventListener('pointerdown', handlePointerEvent, true);\n documentObject.addEventListener('pointermove', handlePointerEvent, true);\n documentObject.addEventListener('pointerup', handlePointerEvent, true);\n } else if (process.env.NODE_ENV === 'test') {\n documentObject.addEventListener('mousedown', handlePointerEvent, true);\n documentObject.addEventListener('mousemove', handlePointerEvent, true);\n documentObject.addEventListener('mouseup', handlePointerEvent, true);\n }\n\n // Add unmount handler\n windowObject.addEventListener(\n 'beforeunload',\n () => {\n tearDownWindowFocusTracking(element);\n },\n {once: true}\n );\n\n hasSetupGlobalListeners.set(windowObject, {focus});\n}\n\nconst tearDownWindowFocusTracking = (element, loadListener?: () => void) => {\n const windowObject = getOwnerWindow(element);\n const documentObject = getOwnerDocument(element);\n if (loadListener) {\n documentObject.removeEventListener('DOMContentLoaded', loadListener);\n }\n if (!hasSetupGlobalListeners.has(windowObject)) {\n return;\n }\n Reflect.defineProperty(windowObject.HTMLElement.prototype, 'focus', {\n configurable: true,\n writable: true,\n value: hasSetupGlobalListeners.get(windowObject)!.focus\n });\n\n documentObject.removeEventListener('keydown', handleKeyboardEvent, true);\n documentObject.removeEventListener('keyup', handleKeyboardEvent, true);\n documentObject.removeEventListener('click', handleClickEvent, true);\n\n windowObject.removeEventListener('focus', handleFocusEvent, true);\n windowObject.removeEventListener('blur', handleWindowBlur, false);\n\n if (typeof PointerEvent !== 'undefined') {\n documentObject.removeEventListener('pointerdown', handlePointerEvent, true);\n documentObject.removeEventListener('pointermove', handlePointerEvent, true);\n documentObject.removeEventListener('pointerup', handlePointerEvent, true);\n } else if (process.env.NODE_ENV === 'test') {\n documentObject.removeEventListener('mousedown', handlePointerEvent, true);\n documentObject.removeEventListener('mousemove', handlePointerEvent, true);\n documentObject.removeEventListener('mouseup', handlePointerEvent, true);\n }\n\n hasSetupGlobalListeners.delete(windowObject);\n};\n\n/**\n * EXPERIMENTAL\n * Adds a window (i.e. iframe) to the list of windows that are being tracked for focus visible.\n *\n * Sometimes apps render portions of their tree into an iframe. In this case, we cannot accurately\n * track if the focus is visible because we cannot see interactions inside the iframe. If you have\n * this in your application's architecture, then this function will attach event listeners inside\n * the iframe. You should call `addWindowFocusTracking` with an element from inside the window you\n * wish to add. We'll retrieve the relevant elements based on that. Note, you do not need to call\n * this for the default window, as we call it for you.\n *\n * When you are ready to stop listening, but you do not wish to unmount the iframe, you may call the\n * cleanup function returned by `addWindowFocusTracking`. Otherwise, when you unmount the iframe,\n * all listeners and state will be cleaned up automatically for you.\n *\n * @param element @default document.body - The element provided will be used to get the window to\n * add.\n * @returns A function to remove the event listeners and cleanup the state.\n */\nexport function addWindowFocusTracking(element?: HTMLElement | null): () => void {\n const documentObject = getOwnerDocument(element);\n let loadListener;\n if (documentObject.readyState !== 'loading') {\n setupGlobalFocusEvents(element);\n } else {\n loadListener = () => {\n setupGlobalFocusEvents(element);\n };\n documentObject.addEventListener('DOMContentLoaded', loadListener);\n }\n\n return () => tearDownWindowFocusTracking(element, loadListener);\n}\n\n// Server-side rendering does not have the document object defined\n// eslint-disable-next-line no-restricted-globals\nif (typeof document !== 'undefined') {\n addWindowFocusTracking();\n}\n\n/**\n * If true, keyboard focus is visible.\n */\nexport function isFocusVisible(): boolean {\n return currentModality !== 'pointer';\n}\n\nexport function getInteractionModality(): Modality | null {\n return currentModality;\n}\n\nexport function setInteractionModality(modality: Modality): void {\n currentModality = modality;\n currentPointerType = modality === 'pointer' ? 'mouse' : modality;\n triggerChangeHandlers(modality, null);\n}\n\n/** @private */\nexport function getPointerType(): PointerType {\n return currentPointerType;\n}\n\n/**\n * Keeps state of the current modality.\n */\nexport function useInteractionModality(): Modality | null {\n setupGlobalFocusEvents();\n\n let [modality, setModality] = useState(currentModality);\n useEffect(() => {\n let handler = () => {\n setModality(currentModality);\n };\n\n changeHandlers.add(handler);\n return () => {\n changeHandlers.delete(handler);\n };\n }, []);\n\n return useIsSSR() ? null : modality;\n}\n\nconst nonTextInputTypes = new Set([\n 'checkbox',\n 'radio',\n 'range',\n 'color',\n 'file',\n 'image',\n 'button',\n 'submit',\n 'reset'\n]);\n\n/**\n * If this is attached to text input component, return if the event is a focus event (Tab/Escape\n * keys pressed) so that focus visible style can be properly set.\n */\nfunction isKeyboardFocusEvent(isTextInput: boolean, modality: Modality, e: HandlerEvent) {\n let eventTarget = e ? (getEventTarget(e) as Element) : undefined;\n let ownerDocument = getOwnerDocument(eventTarget);\n let ownerWindow = getOwnerWindow(eventTarget);\n const IHTMLInputElement =\n typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLInputElement : HTMLInputElement;\n const IHTMLTextAreaElement =\n typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLTextAreaElement : HTMLTextAreaElement;\n const IHTMLElement = typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLElement : HTMLElement;\n const IKeyboardEvent =\n typeof ownerWindow !== 'undefined' ? ownerWindow.KeyboardEvent : KeyboardEvent;\n\n // For keyboard events that occur on a non-input element that will move focus into input element (aka ArrowLeft going from Datepicker button to the main input group)\n // we need to rely on the user passing isTextInput into here. This way we can skip toggling focus visiblity for said input element\n let activeElement = getActiveElement(ownerDocument);\n isTextInput =\n isTextInput ||\n (activeElement instanceof IHTMLInputElement && !nonTextInputTypes.has(activeElement.type)) ||\n activeElement instanceof IHTMLTextAreaElement ||\n (activeElement instanceof IHTMLElement && activeElement.isContentEditable);\n return !(\n isTextInput &&\n modality === 'keyboard' &&\n e instanceof IKeyboardEvent &&\n !FOCUS_VISIBLE_INPUT_KEYS[e.key]\n );\n}\n\n/**\n * Manages focus visible state for the page, and subscribes individual components for updates.\n */\nexport function useFocusVisible(props: FocusVisibleProps = {}): FocusVisibleResult {\n let {isTextInput, autoFocus} = props;\n let [isFocusVisibleState, setFocusVisible] = useState(autoFocus || isFocusVisible());\n useFocusVisibleListener(\n isFocusVisible => {\n setFocusVisible(isFocusVisible);\n },\n [isTextInput],\n {isTextInput}\n );\n\n return {isFocusVisible: isFocusVisibleState};\n}\n\n/**\n * Listens for trigger change and reports if focus is visible (i.e., modality is not pointer).\n */\nexport function useFocusVisibleListener(\n fn: FocusVisibleHandler,\n deps: ReadonlyArray<any>,\n opts?: {enabled?: boolean; isTextInput?: boolean}\n): void {\n setupGlobalFocusEvents();\n\n useEffect(() => {\n if (opts?.enabled === false) {\n return;\n }\n let handler = (modality: Modality, e: HandlerEvent) => {\n // We want to early return for any keyboard events that occur inside text inputs EXCEPT for Tab and Escape\n if (!isKeyboardFocusEvent(!!opts?.isTextInput, modality, e)) {\n return;\n }\n fn(isFocusVisible());\n };\n changeHandlers.add(handler);\n return () => {\n changeHandlers.delete(handler);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n}\n"],"names":[],"version":3,"file":"useFocusVisible.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;;;;;;;AA6BlH,IAAI,wCAAmC;AACvC,IAAI,2CAAkC;AAC/B,MAAM,4CAAiB,IAAI;AAI3B,IAAI,4CAA2D,IAAI,OAGrE,yFAAyF;AAC9F,IAAI,4CAAsB;AAC1B,IAAI,iDAA2B;AAE/B,sEAAsE;AACtE,MAAM,iDAA2B;IAC/B,KAAK;IACL,QAAQ;AACV;AAEA,SAAS,4CAAsB,QAAkB,EAAE,CAAe;IAChE,KAAK,IAAI,WAAW,0CAClB,QAAQ,UAAU;AAEt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;IACpF,MAAM,iBACJ,OAAO,gBAAgB,cAAc,YAAY,aAAa,GAAG;IAEnE,qKAAqK;IACrK,kIAAkI;IAClI,IAAI,gBAAgB,CAAA,GAAA,yCAAe,EAAE;IACrC,cACE,eACC,yBAAyB,qBAAqB,CAAC,wCAAkB,GAAG,CAAC,cAAc,IAAI,KACxF,yBAAyB,wBACxB,yBAAyB,gBAAgB,cAAc,iBAAiB;IAC3E,OAAO,CACL,CAAA,eACA,aAAa,cACb,aAAa,kBACb,CAAC,8CAAwB,CAAC,EAAE,GAAG,CAAC,AAAD;AAEnC;AAKO,SAAS,0CAAgB,QAA2B,CAAC,CAAC;IAC3D,IAAI,eAAC,WAAW,aAAE,SAAS,EAAC,GAAG;IAC/B,IAAI,CAAC,qBAAqB,gBAAgB,GAAG,CAAA,GAAA,eAAO,EAAE,aAAa;IACnE,0CACE,CAAA;QACE,gBAAgB;IAClB,GACA;QAAC;KAAY,EACb;qBAAC;IAAW;IAGd,OAAO;QAAC,gBAAgB;IAAmB;AAC7C;AAKO,SAAS,0CACd,EAAuB,EACvB,IAAwB,EACxB,IAAiD;IAEjD;IAEA,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,CAAA,iBAAA,2BAAA,KAAM,OAAO,MAAK,OACpB;QAEF,IAAI,UAAU,CAAC,UAAoB;YACjC,0GAA0G;YAC1G,IAAI,CAAC,2CAAqB,CAAC,EAAC,iBAAA,2BAAA,KAAM,WAAW,GAAE,UAAU,IACvD;YAEF,GAAG;QACL;QACA,0CAAe,GAAG,CAAC;QACnB,OAAO;YACL,0CAAe,MAAM,CAAC;QACxB;IACA,uDAAuD;IACzD,GAAG;AACL","sources":["packages/react-aria/src/interactions/useFocusVisible.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// Portions of the code in this file are based on code from react.\n// Original licensing for the following can be found in the\n// NOTICE file in the root directory of this source tree.\n// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions\n\nimport {getActiveElement, getEventTarget} from '../utils/shadowdom/DOMFunctions';\n\nimport {getOwnerDocument, getOwnerWindow} from '../utils/domHelpers';\nimport {ignoreFocusEvent} from './utils';\nimport {isMac} from '../utils/platform';\nimport {isVirtualClick} from '../utils/isVirtualEvent';\nimport {openLink} from '../utils/openLink';\nimport {PointerType} from '@react-types/shared';\nimport {useEffect, useState} from 'react';\nimport {useIsSSR} from '../ssr/SSRProvider';\n\nexport type Modality = 'keyboard' | 'pointer' | 'virtual';\ntype HandlerEvent = PointerEvent | MouseEvent | KeyboardEvent | FocusEvent | null;\ntype Handler = (modality: Modality, e: HandlerEvent) => void;\nexport type FocusVisibleHandler = (isFocusVisible: boolean) => void;\nexport interface FocusVisibleProps {\n /** Whether the element is a text input. */\n isTextInput?: boolean;\n /** Whether the element will be auto focused. */\n autoFocus?: boolean;\n}\n\nexport interface FocusVisibleResult {\n /** Whether keyboard focus is visible globally. */\n isFocusVisible: boolean;\n}\n\nlet currentModality: null | Modality = null;\nlet currentPointerType: PointerType = 'keyboard';\nexport const changeHandlers = new Set<Handler>();\ninterface GlobalListenerData {\n focus: () => void;\n}\nexport let hasSetupGlobalListeners: Map<Window, GlobalListenerData> = new Map<\n Window,\n GlobalListenerData\n>(); // We use a map here to support setting event listeners across multiple document objects.\nlet hasEventBeforeFocus = false;\nlet hasBlurredWindowRecently = false;\n\n// Only Tab or Esc keys will make focus visible on text input elements\nconst FOCUS_VISIBLE_INPUT_KEYS = {\n Tab: true,\n Escape: true\n};\n\nfunction triggerChangeHandlers(modality: Modality, e: HandlerEvent) {\n for (let handler of changeHandlers) {\n handler(modality, e);\n }\n}\n\n/**\n * Helper function to determine if a KeyboardEvent is unmodified and could make keyboard focus\n * styles visible.\n */\nfunction isValidKey(e: KeyboardEvent) {\n // Control and Shift keys trigger when navigating back to the tab with keyboard.\n return !(\n e.metaKey ||\n (!isMac() && e.altKey) ||\n e.ctrlKey ||\n e.key === 'Control' ||\n e.key === 'Shift' ||\n e.key === 'Meta'\n );\n}\n\nfunction handleKeyboardEvent(e: KeyboardEvent) {\n hasEventBeforeFocus = true;\n if (!(openLink as any).isOpening && isValidKey(e)) {\n currentModality = 'keyboard';\n currentPointerType = 'keyboard';\n triggerChangeHandlers('keyboard', e);\n }\n}\n\nfunction handlePointerEvent(e: PointerEvent | MouseEvent) {\n currentModality = 'pointer';\n currentPointerType = 'pointerType' in e ? (e.pointerType as PointerType) : 'mouse';\n if (e.type === 'mousedown' || e.type === 'pointerdown') {\n hasEventBeforeFocus = true;\n triggerChangeHandlers('pointer', e);\n }\n}\n\nfunction handleClickEvent(e: MouseEvent) {\n if (!(openLink as any).isOpening && isVirtualClick(e)) {\n hasEventBeforeFocus = true;\n currentModality = 'virtual';\n currentPointerType = 'virtual';\n }\n}\n\nfunction handleFocusEvent(e: FocusEvent) {\n if (ignoreFocusEvent) {\n return;\n }\n\n let target = getEventTarget(e);\n let ownerWindow = getOwnerWindow(target);\n let ownerDocument = getOwnerDocument(target);\n\n // When the window regains focus, the browser restores focus to the element that was focused\n // before, firing a focus event the user did not initiate. handleWindowBlur sets\n // hasBlurredWindowRecently so restored focus doesn't switch to virtual modality below, but\n // Safari fires the window/element focus pair twice when returning to a tab or app and the first\n // element focus event clears the flag, so re-arm it whenever the window itself is focused.\n // Like handleWindowBlur, this intentionally doesn't check isTrusted.\n if (target === ownerWindow) {\n hasBlurredWindowRecently = true;\n return;\n }\n\n // Firefox fires two extra focus events when the user first clicks into an iframe:\n // first on the window, then on the document. We ignore these events so they don't\n // cause keyboard focus rings to appear.\n if (target === ownerDocument || !e.isTrusted) {\n return;\n }\n\n // If a focus event occurs without a preceding keyboard or pointer event, switch to virtual modality.\n // This occurs, for example, when navigating a form with the next/previous buttons on iOS.\n if (!hasEventBeforeFocus && !hasBlurredWindowRecently) {\n currentModality = 'virtual';\n currentPointerType = 'virtual';\n triggerChangeHandlers('virtual', e);\n }\n\n hasEventBeforeFocus = false;\n hasBlurredWindowRecently = false;\n}\n\nfunction handleWindowBlur() {\n if (ignoreFocusEvent) {\n return;\n }\n\n // When the window is blurred, reset state. This is necessary when tabbing out of the window,\n // for example, since a subsequent focus event won't be fired.\n hasEventBeforeFocus = false;\n hasBlurredWindowRecently = true;\n}\n\n/**\n * Setup global event listeners to control when keyboard focus style should be visible.\n */\nfunction setupGlobalFocusEvents(element?: HTMLElement | null) {\n // eslint-disable-next-line no-restricted-globals\n if (typeof window === 'undefined' || typeof document === 'undefined') {\n return;\n }\n\n const windowObject = getOwnerWindow(element);\n const documentObject = getOwnerDocument(element);\n\n if (hasSetupGlobalListeners.get(windowObject)) {\n return;\n }\n\n // Programmatic focus() calls shouldn't affect the current input modality.\n // However, we need to detect other cases when a focus event occurs without\n // a preceding user event (e.g. screen reader focus). Overriding the focus\n // method on HTMLElement.prototype is a bit hacky, but works.\n // defineProperty (not assignment) so this works even if `focus` is currently\n // a getter-only accessor — e.g. when @testing-library/user-event's setup()\n // has instrumented it. Plain assignment throws in that case.\n let focus = windowObject.HTMLElement.prototype.focus;\n Reflect.defineProperty(windowObject.HTMLElement.prototype, 'focus', {\n configurable: true,\n writable: true,\n value: function () {\n hasEventBeforeFocus = true;\n focus.apply(this, arguments as unknown as [options?: FocusOptions | undefined]);\n }\n });\n\n documentObject.addEventListener('keydown', handleKeyboardEvent, true);\n documentObject.addEventListener('keyup', handleKeyboardEvent, true);\n documentObject.addEventListener('click', handleClickEvent, true);\n\n // Register focus events on the window so they are sure to happen\n // before React's event listeners (registered on the document).\n windowObject.addEventListener('focus', handleFocusEvent, true);\n windowObject.addEventListener('blur', handleWindowBlur, false);\n\n if (typeof PointerEvent !== 'undefined') {\n documentObject.addEventListener('pointerdown', handlePointerEvent, true);\n documentObject.addEventListener('pointermove', handlePointerEvent, true);\n documentObject.addEventListener('pointerup', handlePointerEvent, true);\n } else if (process.env.NODE_ENV === 'test') {\n documentObject.addEventListener('mousedown', handlePointerEvent, true);\n documentObject.addEventListener('mousemove', handlePointerEvent, true);\n documentObject.addEventListener('mouseup', handlePointerEvent, true);\n }\n\n // Add unmount handler\n windowObject.addEventListener(\n 'beforeunload',\n () => {\n tearDownWindowFocusTracking(element);\n },\n {once: true}\n );\n\n hasSetupGlobalListeners.set(windowObject, {focus});\n}\n\nconst tearDownWindowFocusTracking = (element, loadListener?: () => void) => {\n const windowObject = getOwnerWindow(element);\n const documentObject = getOwnerDocument(element);\n if (loadListener) {\n documentObject.removeEventListener('DOMContentLoaded', loadListener);\n }\n if (!hasSetupGlobalListeners.has(windowObject)) {\n return;\n }\n Reflect.defineProperty(windowObject.HTMLElement.prototype, 'focus', {\n configurable: true,\n writable: true,\n value: hasSetupGlobalListeners.get(windowObject)!.focus\n });\n\n documentObject.removeEventListener('keydown', handleKeyboardEvent, true);\n documentObject.removeEventListener('keyup', handleKeyboardEvent, true);\n documentObject.removeEventListener('click', handleClickEvent, true);\n\n windowObject.removeEventListener('focus', handleFocusEvent, true);\n windowObject.removeEventListener('blur', handleWindowBlur, false);\n\n if (typeof PointerEvent !== 'undefined') {\n documentObject.removeEventListener('pointerdown', handlePointerEvent, true);\n documentObject.removeEventListener('pointermove', handlePointerEvent, true);\n documentObject.removeEventListener('pointerup', handlePointerEvent, true);\n } else if (process.env.NODE_ENV === 'test') {\n documentObject.removeEventListener('mousedown', handlePointerEvent, true);\n documentObject.removeEventListener('mousemove', handlePointerEvent, true);\n documentObject.removeEventListener('mouseup', handlePointerEvent, true);\n }\n\n hasSetupGlobalListeners.delete(windowObject);\n};\n\n/**\n * EXPERIMENTAL\n * Adds a window (i.e. iframe) to the list of windows that are being tracked for focus visible.\n *\n * Sometimes apps render portions of their tree into an iframe. In this case, we cannot accurately\n * track if the focus is visible because we cannot see interactions inside the iframe. If you have\n * this in your application's architecture, then this function will attach event listeners inside\n * the iframe. You should call `addWindowFocusTracking` with an element from inside the window you\n * wish to add. We'll retrieve the relevant elements based on that. Note, you do not need to call\n * this for the default window, as we call it for you.\n *\n * When you are ready to stop listening, but you do not wish to unmount the iframe, you may call the\n * cleanup function returned by `addWindowFocusTracking`. Otherwise, when you unmount the iframe,\n * all listeners and state will be cleaned up automatically for you.\n *\n * @param element @default document.body - The element provided will be used to get the window to\n * add.\n * @returns A function to remove the event listeners and cleanup the state.\n */\nexport function addWindowFocusTracking(element?: HTMLElement | null): () => void {\n const documentObject = getOwnerDocument(element);\n let loadListener;\n if (documentObject.readyState !== 'loading') {\n setupGlobalFocusEvents(element);\n } else {\n loadListener = () => {\n setupGlobalFocusEvents(element);\n };\n documentObject.addEventListener('DOMContentLoaded', loadListener);\n }\n\n return () => tearDownWindowFocusTracking(element, loadListener);\n}\n\n// Server-side rendering does not have the document object defined\n// eslint-disable-next-line no-restricted-globals\nif (typeof document !== 'undefined') {\n addWindowFocusTracking();\n}\n\n/**\n * If true, keyboard focus is visible.\n */\nexport function isFocusVisible(): boolean {\n return currentModality !== 'pointer';\n}\n\nexport function getInteractionModality(): Modality | null {\n return currentModality;\n}\n\nexport function setInteractionModality(modality: Modality): void {\n currentModality = modality;\n currentPointerType = modality === 'pointer' ? 'mouse' : modality;\n triggerChangeHandlers(modality, null);\n}\n\n/** @private */\nexport function getPointerType(): PointerType {\n return currentPointerType;\n}\n\n/**\n * Keeps state of the current modality.\n */\nexport function useInteractionModality(): Modality | null {\n setupGlobalFocusEvents();\n\n let [modality, setModality] = useState(currentModality);\n useEffect(() => {\n let handler = () => {\n setModality(currentModality);\n };\n\n changeHandlers.add(handler);\n return () => {\n changeHandlers.delete(handler);\n };\n }, []);\n\n return useIsSSR() ? null : modality;\n}\n\nconst nonTextInputTypes = new Set([\n 'checkbox',\n 'radio',\n 'range',\n 'color',\n 'file',\n 'image',\n 'button',\n 'submit',\n 'reset'\n]);\n\n/**\n * If this is attached to text input component, return if the event is a focus event (Tab/Escape\n * keys pressed) so that focus visible style can be properly set.\n */\nfunction isKeyboardFocusEvent(isTextInput: boolean, modality: Modality, e: HandlerEvent) {\n let eventTarget = e ? (getEventTarget(e) as Element) : undefined;\n let ownerDocument = getOwnerDocument(eventTarget);\n let ownerWindow = getOwnerWindow(eventTarget);\n const IHTMLInputElement =\n typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLInputElement : HTMLInputElement;\n const IHTMLTextAreaElement =\n typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLTextAreaElement : HTMLTextAreaElement;\n const IHTMLElement = typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLElement : HTMLElement;\n const IKeyboardEvent =\n typeof ownerWindow !== 'undefined' ? ownerWindow.KeyboardEvent : KeyboardEvent;\n\n // For keyboard events that occur on a non-input element that will move focus into input element (aka ArrowLeft going from Datepicker button to the main input group)\n // we need to rely on the user passing isTextInput into here. This way we can skip toggling focus visiblity for said input element\n let activeElement = getActiveElement(ownerDocument);\n isTextInput =\n isTextInput ||\n (activeElement instanceof IHTMLInputElement && !nonTextInputTypes.has(activeElement.type)) ||\n activeElement instanceof IHTMLTextAreaElement ||\n (activeElement instanceof IHTMLElement && activeElement.isContentEditable);\n return !(\n isTextInput &&\n modality === 'keyboard' &&\n e instanceof IKeyboardEvent &&\n !FOCUS_VISIBLE_INPUT_KEYS[e.key]\n );\n}\n\n/**\n * Manages focus visible state for the page, and subscribes individual components for updates.\n */\nexport function useFocusVisible(props: FocusVisibleProps = {}): FocusVisibleResult {\n let {isTextInput, autoFocus} = props;\n let [isFocusVisibleState, setFocusVisible] = useState(autoFocus || isFocusVisible());\n useFocusVisibleListener(\n isFocusVisible => {\n setFocusVisible(isFocusVisible);\n },\n [isTextInput],\n {isTextInput}\n );\n\n return {isFocusVisible: isFocusVisibleState};\n}\n\n/**\n * Listens for trigger change and reports if focus is visible (i.e., modality is not pointer).\n */\nexport function useFocusVisibleListener(\n fn: FocusVisibleHandler,\n deps: ReadonlyArray<any>,\n opts?: {enabled?: boolean; isTextInput?: boolean}\n): void {\n setupGlobalFocusEvents();\n\n useEffect(() => {\n if (opts?.enabled === false) {\n return;\n }\n let handler = (modality: Modality, e: HandlerEvent) => {\n // We want to early return for any keyboard events that occur inside text inputs EXCEPT for Tab and Escape\n if (!isKeyboardFocusEvent(!!opts?.isTextInput, modality, e)) {\n return;\n }\n fn(isFocusVisible());\n };\n changeHandlers.add(handler);\n return () => {\n changeHandlers.delete(handler);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n}\n"],"names":[],"version":3,"file":"useFocusVisible.js.map"}
|
|
@@ -74,12 +74,24 @@ function $8f5a2122b0992be3$var$handleClickEvent(e) {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
function $8f5a2122b0992be3$var$handleFocusEvent(e) {
|
|
77
|
+
if (0, $a92dc41f639950be$export$fda7da73ab5d4c48) return;
|
|
78
|
+
let target = (0, $23f2114a1b82827e$export$e58f029f0fbfdb29)(e);
|
|
79
|
+
let ownerWindow = (0, $d447af545b77c9f1$export$f21a1ffae260145a)(target);
|
|
80
|
+
let ownerDocument = (0, $d447af545b77c9f1$export$b204af158042fbac)(target);
|
|
81
|
+
// When the window regains focus, the browser restores focus to the element that was focused
|
|
82
|
+
// before, firing a focus event the user did not initiate. handleWindowBlur sets
|
|
83
|
+
// hasBlurredWindowRecently so restored focus doesn't switch to virtual modality below, but
|
|
84
|
+
// Safari fires the window/element focus pair twice when returning to a tab or app and the first
|
|
85
|
+
// element focus event clears the flag, so re-arm it whenever the window itself is focused.
|
|
86
|
+
// Like handleWindowBlur, this intentionally doesn't check isTrusted.
|
|
87
|
+
if (target === ownerWindow) {
|
|
88
|
+
$8f5a2122b0992be3$var$hasBlurredWindowRecently = true;
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
77
91
|
// Firefox fires two extra focus events when the user first clicks into an iframe:
|
|
78
92
|
// first on the window, then on the document. We ignore these events so they don't
|
|
79
93
|
// cause keyboard focus rings to appear.
|
|
80
|
-
|
|
81
|
-
let ownerDocument = (0, $d447af545b77c9f1$export$b204af158042fbac)((0, $23f2114a1b82827e$export$e58f029f0fbfdb29)(e));
|
|
82
|
-
if ((0, $23f2114a1b82827e$export$e58f029f0fbfdb29)(e) === ownerWindow || (0, $23f2114a1b82827e$export$e58f029f0fbfdb29)(e) === ownerDocument || (0, $a92dc41f639950be$export$fda7da73ab5d4c48) || !e.isTrusted) return;
|
|
94
|
+
if (target === ownerDocument || !e.isTrusted) return;
|
|
83
95
|
// If a focus event occurs without a preceding keyboard or pointer event, switch to virtual modality.
|
|
84
96
|
// This occurs, for example, when navigating a form with the next/previous buttons on iOS.
|
|
85
97
|
if (!$8f5a2122b0992be3$var$hasEventBeforeFocus && !$8f5a2122b0992be3$var$hasBlurredWindowRecently) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;;;;;;;AA6BlH,IAAI,wCAAmC;AACvC,IAAI,2CAAkC;AAC/B,MAAM,4CAAiB,IAAI;AAI3B,IAAI,4CAA2D,IAAI,OAGrE,yFAAyF;AAC9F,IAAI,4CAAsB;AAC1B,IAAI,iDAA2B;AAE/B,sEAAsE;AACtE,MAAM,iDAA2B;IAC/B,KAAK;IACL,QAAQ;AACV;AAEA,SAAS,4CAAsB,QAAkB,EAAE,CAAe;IAChE,KAAK,IAAI,WAAW,0CAClB,QAAQ,UAAU;AAEtB;AAEA;;;CAGC,GACD,SAAS,iCAAW,CAAgB;IAClC,gFAAgF;IAChF,OAAO,CACL,CAAA,EAAE,OAAO,IACR,CAAC,CAAA,GAAA,yCAAI,OAAO,EAAE,MAAM,IACrB,EAAE,OAAO,IACT,EAAE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,cAAc,iBAAiB;IAC3E,OAAO,CACL,CAAA,eACA,aAAa,cACb,aAAa,kBACb,CAAC,8CAAwB,CAAC,EAAE,GAAG,CAAC,AAAD;AAEnC;AAKO,SAAS,0CAAgB,QAA2B,CAAC,CAAC;IAC3D,IAAI,eAAC,WAAW,aAAE,SAAS,EAAC,GAAG;IAC/B,IAAI,CAAC,qBAAqB,gBAAgB,GAAG,CAAA,GAAA,eAAO,EAAE,aAAa;IACnE,0CACE,CAAA;QACE,gBAAgB;IAClB,GACA;QAAC;KAAY,EACb;qBAAC;IAAW;IAGd,OAAO;QAAC,gBAAgB;IAAmB;AAC7C;AAKO,SAAS,0CACd,EAAuB,EACvB,IAAwB,EACxB,IAAiD;IAEjD;IAEA,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,MAAM,YAAY,OACpB;QAEF,IAAI,UAAU,CAAC,UAAoB;YACjC,0GAA0G;YAC1G,IAAI,CAAC,2CAAqB,CAAC,CAAC,MAAM,aAAa,UAAU,IACvD;YAEF,GAAG;QACL;QACA,0CAAe,GAAG,CAAC;QACnB,OAAO;YACL,0CAAe,MAAM,CAAC;QACxB;IACA,uDAAuD;IACzD,GAAG;AACL","sources":["packages/react-aria/src/interactions/useFocusVisible.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// Portions of the code in this file are based on code from react.\n// Original licensing for the following can be found in the\n// NOTICE file in the root directory of this source tree.\n// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions\n\nimport {getActiveElement, getEventTarget} from '../utils/shadowdom/DOMFunctions';\n\nimport {getOwnerDocument, getOwnerWindow} from '../utils/domHelpers';\nimport {ignoreFocusEvent} from './utils';\nimport {isMac} from '../utils/platform';\nimport {isVirtualClick} from '../utils/isVirtualEvent';\nimport {openLink} from '../utils/openLink';\nimport {PointerType} from '@react-types/shared';\nimport {useEffect, useState} from 'react';\nimport {useIsSSR} from '../ssr/SSRProvider';\n\nexport type Modality = 'keyboard' | 'pointer' | 'virtual';\ntype HandlerEvent = PointerEvent | MouseEvent | KeyboardEvent | FocusEvent | null;\ntype Handler = (modality: Modality, e: HandlerEvent) => void;\nexport type FocusVisibleHandler = (isFocusVisible: boolean) => void;\nexport interface FocusVisibleProps {\n /** Whether the element is a text input. */\n isTextInput?: boolean;\n /** Whether the element will be auto focused. */\n autoFocus?: boolean;\n}\n\nexport interface FocusVisibleResult {\n /** Whether keyboard focus is visible globally. */\n isFocusVisible: boolean;\n}\n\nlet currentModality: null | Modality = null;\nlet currentPointerType: PointerType = 'keyboard';\nexport const changeHandlers = new Set<Handler>();\ninterface GlobalListenerData {\n focus: () => void;\n}\nexport let hasSetupGlobalListeners: Map<Window, GlobalListenerData> = new Map<\n Window,\n GlobalListenerData\n>(); // We use a map here to support setting event listeners across multiple document objects.\nlet hasEventBeforeFocus = false;\nlet hasBlurredWindowRecently = false;\n\n// Only Tab or Esc keys will make focus visible on text input elements\nconst FOCUS_VISIBLE_INPUT_KEYS = {\n Tab: true,\n Escape: true\n};\n\nfunction triggerChangeHandlers(modality: Modality, e: HandlerEvent) {\n for (let handler of changeHandlers) {\n handler(modality, e);\n }\n}\n\n/**\n * Helper function to determine if a KeyboardEvent is unmodified and could make keyboard focus\n * styles visible.\n */\nfunction isValidKey(e: KeyboardEvent) {\n // Control and Shift keys trigger when navigating back to the tab with keyboard.\n return !(\n e.metaKey ||\n (!isMac() && e.altKey) ||\n e.ctrlKey ||\n e.key === 'Control' ||\n e.key === 'Shift' ||\n e.key === 'Meta'\n );\n}\n\nfunction handleKeyboardEvent(e: KeyboardEvent) {\n hasEventBeforeFocus = true;\n if (!(openLink as any).isOpening && isValidKey(e)) {\n currentModality = 'keyboard';\n currentPointerType = 'keyboard';\n triggerChangeHandlers('keyboard', e);\n }\n}\n\nfunction handlePointerEvent(e: PointerEvent | MouseEvent) {\n currentModality = 'pointer';\n currentPointerType = 'pointerType' in e ? (e.pointerType as PointerType) : 'mouse';\n if (e.type === 'mousedown' || e.type === 'pointerdown') {\n hasEventBeforeFocus = true;\n triggerChangeHandlers('pointer', e);\n }\n}\n\nfunction handleClickEvent(e: MouseEvent) {\n if (!(openLink as any).isOpening && isVirtualClick(e)) {\n hasEventBeforeFocus = true;\n currentModality = 'virtual';\n currentPointerType = 'virtual';\n }\n}\n\nfunction handleFocusEvent(e: FocusEvent) {\n // Firefox fires two extra focus events when the user first clicks into an iframe:\n // first on the window, then on the document. We ignore these events so they don't\n // cause keyboard focus rings to appear.\n let ownerWindow = getOwnerWindow(getEventTarget(e));\n let ownerDocument = getOwnerDocument(getEventTarget(e));\n if (\n getEventTarget(e) === ownerWindow ||\n getEventTarget(e) === ownerDocument ||\n ignoreFocusEvent ||\n !e.isTrusted\n ) {\n return;\n }\n\n // If a focus event occurs without a preceding keyboard or pointer event, switch to virtual modality.\n // This occurs, for example, when navigating a form with the next/previous buttons on iOS.\n if (!hasEventBeforeFocus && !hasBlurredWindowRecently) {\n currentModality = 'virtual';\n currentPointerType = 'virtual';\n triggerChangeHandlers('virtual', e);\n }\n\n hasEventBeforeFocus = false;\n hasBlurredWindowRecently = false;\n}\n\nfunction handleWindowBlur() {\n if (ignoreFocusEvent) {\n return;\n }\n\n // When the window is blurred, reset state. This is necessary when tabbing out of the window,\n // for example, since a subsequent focus event won't be fired.\n hasEventBeforeFocus = false;\n hasBlurredWindowRecently = true;\n}\n\n/**\n * Setup global event listeners to control when keyboard focus style should be visible.\n */\nfunction setupGlobalFocusEvents(element?: HTMLElement | null) {\n // eslint-disable-next-line no-restricted-globals\n if (typeof window === 'undefined' || typeof document === 'undefined') {\n return;\n }\n\n const windowObject = getOwnerWindow(element);\n const documentObject = getOwnerDocument(element);\n\n if (hasSetupGlobalListeners.get(windowObject)) {\n return;\n }\n\n // Programmatic focus() calls shouldn't affect the current input modality.\n // However, we need to detect other cases when a focus event occurs without\n // a preceding user event (e.g. screen reader focus). Overriding the focus\n // method on HTMLElement.prototype is a bit hacky, but works.\n // defineProperty (not assignment) so this works even if `focus` is currently\n // a getter-only accessor — e.g. when @testing-library/user-event's setup()\n // has instrumented it. Plain assignment throws in that case.\n let focus = windowObject.HTMLElement.prototype.focus;\n Reflect.defineProperty(windowObject.HTMLElement.prototype, 'focus', {\n configurable: true,\n writable: true,\n value: function () {\n hasEventBeforeFocus = true;\n focus.apply(this, arguments as unknown as [options?: FocusOptions | undefined]);\n }\n });\n\n documentObject.addEventListener('keydown', handleKeyboardEvent, true);\n documentObject.addEventListener('keyup', handleKeyboardEvent, true);\n documentObject.addEventListener('click', handleClickEvent, true);\n\n // Register focus events on the window so they are sure to happen\n // before React's event listeners (registered on the document).\n windowObject.addEventListener('focus', handleFocusEvent, true);\n windowObject.addEventListener('blur', handleWindowBlur, false);\n\n if (typeof PointerEvent !== 'undefined') {\n documentObject.addEventListener('pointerdown', handlePointerEvent, true);\n documentObject.addEventListener('pointermove', handlePointerEvent, true);\n documentObject.addEventListener('pointerup', handlePointerEvent, true);\n } else if (process.env.NODE_ENV === 'test') {\n documentObject.addEventListener('mousedown', handlePointerEvent, true);\n documentObject.addEventListener('mousemove', handlePointerEvent, true);\n documentObject.addEventListener('mouseup', handlePointerEvent, true);\n }\n\n // Add unmount handler\n windowObject.addEventListener(\n 'beforeunload',\n () => {\n tearDownWindowFocusTracking(element);\n },\n {once: true}\n );\n\n hasSetupGlobalListeners.set(windowObject, {focus});\n}\n\nconst tearDownWindowFocusTracking = (element, loadListener?: () => void) => {\n const windowObject = getOwnerWindow(element);\n const documentObject = getOwnerDocument(element);\n if (loadListener) {\n documentObject.removeEventListener('DOMContentLoaded', loadListener);\n }\n if (!hasSetupGlobalListeners.has(windowObject)) {\n return;\n }\n Reflect.defineProperty(windowObject.HTMLElement.prototype, 'focus', {\n configurable: true,\n writable: true,\n value: hasSetupGlobalListeners.get(windowObject)!.focus\n });\n\n documentObject.removeEventListener('keydown', handleKeyboardEvent, true);\n documentObject.removeEventListener('keyup', handleKeyboardEvent, true);\n documentObject.removeEventListener('click', handleClickEvent, true);\n\n windowObject.removeEventListener('focus', handleFocusEvent, true);\n windowObject.removeEventListener('blur', handleWindowBlur, false);\n\n if (typeof PointerEvent !== 'undefined') {\n documentObject.removeEventListener('pointerdown', handlePointerEvent, true);\n documentObject.removeEventListener('pointermove', handlePointerEvent, true);\n documentObject.removeEventListener('pointerup', handlePointerEvent, true);\n } else if (process.env.NODE_ENV === 'test') {\n documentObject.removeEventListener('mousedown', handlePointerEvent, true);\n documentObject.removeEventListener('mousemove', handlePointerEvent, true);\n documentObject.removeEventListener('mouseup', handlePointerEvent, true);\n }\n\n hasSetupGlobalListeners.delete(windowObject);\n};\n\n/**\n * EXPERIMENTAL\n * Adds a window (i.e. iframe) to the list of windows that are being tracked for focus visible.\n *\n * Sometimes apps render portions of their tree into an iframe. In this case, we cannot accurately\n * track if the focus is visible because we cannot see interactions inside the iframe. If you have\n * this in your application's architecture, then this function will attach event listeners inside\n * the iframe. You should call `addWindowFocusTracking` with an element from inside the window you\n * wish to add. We'll retrieve the relevant elements based on that. Note, you do not need to call\n * this for the default window, as we call it for you.\n *\n * When you are ready to stop listening, but you do not wish to unmount the iframe, you may call the\n * cleanup function returned by `addWindowFocusTracking`. Otherwise, when you unmount the iframe,\n * all listeners and state will be cleaned up automatically for you.\n *\n * @param element @default document.body - The element provided will be used to get the window to\n * add.\n * @returns A function to remove the event listeners and cleanup the state.\n */\nexport function addWindowFocusTracking(element?: HTMLElement | null): () => void {\n const documentObject = getOwnerDocument(element);\n let loadListener;\n if (documentObject.readyState !== 'loading') {\n setupGlobalFocusEvents(element);\n } else {\n loadListener = () => {\n setupGlobalFocusEvents(element);\n };\n documentObject.addEventListener('DOMContentLoaded', loadListener);\n }\n\n return () => tearDownWindowFocusTracking(element, loadListener);\n}\n\n// Server-side rendering does not have the document object defined\n// eslint-disable-next-line no-restricted-globals\nif (typeof document !== 'undefined') {\n addWindowFocusTracking();\n}\n\n/**\n * If true, keyboard focus is visible.\n */\nexport function isFocusVisible(): boolean {\n return currentModality !== 'pointer';\n}\n\nexport function getInteractionModality(): Modality | null {\n return currentModality;\n}\n\nexport function setInteractionModality(modality: Modality): void {\n currentModality = modality;\n currentPointerType = modality === 'pointer' ? 'mouse' : modality;\n triggerChangeHandlers(modality, null);\n}\n\n/** @private */\nexport function getPointerType(): PointerType {\n return currentPointerType;\n}\n\n/**\n * Keeps state of the current modality.\n */\nexport function useInteractionModality(): Modality | null {\n setupGlobalFocusEvents();\n\n let [modality, setModality] = useState(currentModality);\n useEffect(() => {\n let handler = () => {\n setModality(currentModality);\n };\n\n changeHandlers.add(handler);\n return () => {\n changeHandlers.delete(handler);\n };\n }, []);\n\n return useIsSSR() ? null : modality;\n}\n\nconst nonTextInputTypes = new Set([\n 'checkbox',\n 'radio',\n 'range',\n 'color',\n 'file',\n 'image',\n 'button',\n 'submit',\n 'reset'\n]);\n\n/**\n * If this is attached to text input component, return if the event is a focus event (Tab/Escape\n * keys pressed) so that focus visible style can be properly set.\n */\nfunction isKeyboardFocusEvent(isTextInput: boolean, modality: Modality, e: HandlerEvent) {\n let eventTarget = e ? (getEventTarget(e) as Element) : undefined;\n let ownerDocument = getOwnerDocument(eventTarget);\n let ownerWindow = getOwnerWindow(eventTarget);\n const IHTMLInputElement =\n typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLInputElement : HTMLInputElement;\n const IHTMLTextAreaElement =\n typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLTextAreaElement : HTMLTextAreaElement;\n const IHTMLElement = typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLElement : HTMLElement;\n const IKeyboardEvent =\n typeof ownerWindow !== 'undefined' ? ownerWindow.KeyboardEvent : KeyboardEvent;\n\n // For keyboard events that occur on a non-input element that will move focus into input element (aka ArrowLeft going from Datepicker button to the main input group)\n // we need to rely on the user passing isTextInput into here. This way we can skip toggling focus visiblity for said input element\n let activeElement = getActiveElement(ownerDocument);\n isTextInput =\n isTextInput ||\n (activeElement instanceof IHTMLInputElement && !nonTextInputTypes.has(activeElement.type)) ||\n activeElement instanceof IHTMLTextAreaElement ||\n (activeElement instanceof IHTMLElement && activeElement.isContentEditable);\n return !(\n isTextInput &&\n modality === 'keyboard' &&\n e instanceof IKeyboardEvent &&\n !FOCUS_VISIBLE_INPUT_KEYS[e.key]\n );\n}\n\n/**\n * Manages focus visible state for the page, and subscribes individual components for updates.\n */\nexport function useFocusVisible(props: FocusVisibleProps = {}): FocusVisibleResult {\n let {isTextInput, autoFocus} = props;\n let [isFocusVisibleState, setFocusVisible] = useState(autoFocus || isFocusVisible());\n useFocusVisibleListener(\n isFocusVisible => {\n setFocusVisible(isFocusVisible);\n },\n [isTextInput],\n {isTextInput}\n );\n\n return {isFocusVisible: isFocusVisibleState};\n}\n\n/**\n * Listens for trigger change and reports if focus is visible (i.e., modality is not pointer).\n */\nexport function useFocusVisibleListener(\n fn: FocusVisibleHandler,\n deps: ReadonlyArray<any>,\n opts?: {enabled?: boolean; isTextInput?: boolean}\n): void {\n setupGlobalFocusEvents();\n\n useEffect(() => {\n if (opts?.enabled === false) {\n return;\n }\n let handler = (modality: Modality, e: HandlerEvent) => {\n // We want to early return for any keyboard events that occur inside text inputs EXCEPT for Tab and Escape\n if (!isKeyboardFocusEvent(!!opts?.isTextInput, modality, e)) {\n return;\n }\n fn(isFocusVisible());\n };\n changeHandlers.add(handler);\n return () => {\n changeHandlers.delete(handler);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n}\n"],"names":[],"version":3,"file":"useFocusVisible.mjs.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;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C,MAAM,aAAa,UAAU,IACvD;YAEF,GAAG;QACL;QACA,0CAAe,GAAG,CAAC;QACnB,OAAO;YACL,0CAAe,MAAM,CAAC;QACxB;IACA,uDAAuD;IACzD,GAAG;AACL","sources":["packages/react-aria/src/interactions/useFocusVisible.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// Portions of the code in this file are based on code from react.\n// Original licensing for the following can be found in the\n// NOTICE file in the root directory of this source tree.\n// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions\n\nimport {getActiveElement, getEventTarget} from '../utils/shadowdom/DOMFunctions';\n\nimport {getOwnerDocument, getOwnerWindow} from '../utils/domHelpers';\nimport {ignoreFocusEvent} from './utils';\nimport {isMac} from '../utils/platform';\nimport {isVirtualClick} from '../utils/isVirtualEvent';\nimport {openLink} from '../utils/openLink';\nimport {PointerType} from '@react-types/shared';\nimport {useEffect, useState} from 'react';\nimport {useIsSSR} from '../ssr/SSRProvider';\n\nexport type Modality = 'keyboard' | 'pointer' | 'virtual';\ntype HandlerEvent = PointerEvent | MouseEvent | KeyboardEvent | FocusEvent | null;\ntype Handler = (modality: Modality, e: HandlerEvent) => void;\nexport type FocusVisibleHandler = (isFocusVisible: boolean) => void;\nexport interface FocusVisibleProps {\n /** Whether the element is a text input. */\n isTextInput?: boolean;\n /** Whether the element will be auto focused. */\n autoFocus?: boolean;\n}\n\nexport interface FocusVisibleResult {\n /** Whether keyboard focus is visible globally. */\n isFocusVisible: boolean;\n}\n\nlet currentModality: null | Modality = null;\nlet currentPointerType: PointerType = 'keyboard';\nexport const changeHandlers = new Set<Handler>();\ninterface GlobalListenerData {\n focus: () => void;\n}\nexport let hasSetupGlobalListeners: Map<Window, GlobalListenerData> = new Map<\n Window,\n GlobalListenerData\n>(); // We use a map here to support setting event listeners across multiple document objects.\nlet hasEventBeforeFocus = false;\nlet hasBlurredWindowRecently = false;\n\n// Only Tab or Esc keys will make focus visible on text input elements\nconst FOCUS_VISIBLE_INPUT_KEYS = {\n Tab: true,\n Escape: true\n};\n\nfunction triggerChangeHandlers(modality: Modality, e: HandlerEvent) {\n for (let handler of changeHandlers) {\n handler(modality, e);\n }\n}\n\n/**\n * Helper function to determine if a KeyboardEvent is unmodified and could make keyboard focus\n * styles visible.\n */\nfunction isValidKey(e: KeyboardEvent) {\n // Control and Shift keys trigger when navigating back to the tab with keyboard.\n return !(\n e.metaKey ||\n (!isMac() && e.altKey) ||\n e.ctrlKey ||\n e.key === 'Control' ||\n e.key === 'Shift' ||\n e.key === 'Meta'\n );\n}\n\nfunction handleKeyboardEvent(e: KeyboardEvent) {\n hasEventBeforeFocus = true;\n if (!(openLink as any).isOpening && isValidKey(e)) {\n currentModality = 'keyboard';\n currentPointerType = 'keyboard';\n triggerChangeHandlers('keyboard', e);\n }\n}\n\nfunction handlePointerEvent(e: PointerEvent | MouseEvent) {\n currentModality = 'pointer';\n currentPointerType = 'pointerType' in e ? (e.pointerType as PointerType) : 'mouse';\n if (e.type === 'mousedown' || e.type === 'pointerdown') {\n hasEventBeforeFocus = true;\n triggerChangeHandlers('pointer', e);\n }\n}\n\nfunction handleClickEvent(e: MouseEvent) {\n if (!(openLink as any).isOpening && isVirtualClick(e)) {\n hasEventBeforeFocus = true;\n currentModality = 'virtual';\n currentPointerType = 'virtual';\n }\n}\n\nfunction handleFocusEvent(e: FocusEvent) {\n if (ignoreFocusEvent) {\n return;\n }\n\n let target = getEventTarget(e);\n let ownerWindow = getOwnerWindow(target);\n let ownerDocument = getOwnerDocument(target);\n\n // When the window regains focus, the browser restores focus to the element that was focused\n // before, firing a focus event the user did not initiate. handleWindowBlur sets\n // hasBlurredWindowRecently so restored focus doesn't switch to virtual modality below, but\n // Safari fires the window/element focus pair twice when returning to a tab or app and the first\n // element focus event clears the flag, so re-arm it whenever the window itself is focused.\n // Like handleWindowBlur, this intentionally doesn't check isTrusted.\n if (target === ownerWindow) {\n hasBlurredWindowRecently = true;\n return;\n }\n\n // Firefox fires two extra focus events when the user first clicks into an iframe:\n // first on the window, then on the document. We ignore these events so they don't\n // cause keyboard focus rings to appear.\n if (target === ownerDocument || !e.isTrusted) {\n return;\n }\n\n // If a focus event occurs without a preceding keyboard or pointer event, switch to virtual modality.\n // This occurs, for example, when navigating a form with the next/previous buttons on iOS.\n if (!hasEventBeforeFocus && !hasBlurredWindowRecently) {\n currentModality = 'virtual';\n currentPointerType = 'virtual';\n triggerChangeHandlers('virtual', e);\n }\n\n hasEventBeforeFocus = false;\n hasBlurredWindowRecently = false;\n}\n\nfunction handleWindowBlur() {\n if (ignoreFocusEvent) {\n return;\n }\n\n // When the window is blurred, reset state. This is necessary when tabbing out of the window,\n // for example, since a subsequent focus event won't be fired.\n hasEventBeforeFocus = false;\n hasBlurredWindowRecently = true;\n}\n\n/**\n * Setup global event listeners to control when keyboard focus style should be visible.\n */\nfunction setupGlobalFocusEvents(element?: HTMLElement | null) {\n // eslint-disable-next-line no-restricted-globals\n if (typeof window === 'undefined' || typeof document === 'undefined') {\n return;\n }\n\n const windowObject = getOwnerWindow(element);\n const documentObject = getOwnerDocument(element);\n\n if (hasSetupGlobalListeners.get(windowObject)) {\n return;\n }\n\n // Programmatic focus() calls shouldn't affect the current input modality.\n // However, we need to detect other cases when a focus event occurs without\n // a preceding user event (e.g. screen reader focus). Overriding the focus\n // method on HTMLElement.prototype is a bit hacky, but works.\n // defineProperty (not assignment) so this works even if `focus` is currently\n // a getter-only accessor — e.g. when @testing-library/user-event's setup()\n // has instrumented it. Plain assignment throws in that case.\n let focus = windowObject.HTMLElement.prototype.focus;\n Reflect.defineProperty(windowObject.HTMLElement.prototype, 'focus', {\n configurable: true,\n writable: true,\n value: function () {\n hasEventBeforeFocus = true;\n focus.apply(this, arguments as unknown as [options?: FocusOptions | undefined]);\n }\n });\n\n documentObject.addEventListener('keydown', handleKeyboardEvent, true);\n documentObject.addEventListener('keyup', handleKeyboardEvent, true);\n documentObject.addEventListener('click', handleClickEvent, true);\n\n // Register focus events on the window so they are sure to happen\n // before React's event listeners (registered on the document).\n windowObject.addEventListener('focus', handleFocusEvent, true);\n windowObject.addEventListener('blur', handleWindowBlur, false);\n\n if (typeof PointerEvent !== 'undefined') {\n documentObject.addEventListener('pointerdown', handlePointerEvent, true);\n documentObject.addEventListener('pointermove', handlePointerEvent, true);\n documentObject.addEventListener('pointerup', handlePointerEvent, true);\n } else if (process.env.NODE_ENV === 'test') {\n documentObject.addEventListener('mousedown', handlePointerEvent, true);\n documentObject.addEventListener('mousemove', handlePointerEvent, true);\n documentObject.addEventListener('mouseup', handlePointerEvent, true);\n }\n\n // Add unmount handler\n windowObject.addEventListener(\n 'beforeunload',\n () => {\n tearDownWindowFocusTracking(element);\n },\n {once: true}\n );\n\n hasSetupGlobalListeners.set(windowObject, {focus});\n}\n\nconst tearDownWindowFocusTracking = (element, loadListener?: () => void) => {\n const windowObject = getOwnerWindow(element);\n const documentObject = getOwnerDocument(element);\n if (loadListener) {\n documentObject.removeEventListener('DOMContentLoaded', loadListener);\n }\n if (!hasSetupGlobalListeners.has(windowObject)) {\n return;\n }\n Reflect.defineProperty(windowObject.HTMLElement.prototype, 'focus', {\n configurable: true,\n writable: true,\n value: hasSetupGlobalListeners.get(windowObject)!.focus\n });\n\n documentObject.removeEventListener('keydown', handleKeyboardEvent, true);\n documentObject.removeEventListener('keyup', handleKeyboardEvent, true);\n documentObject.removeEventListener('click', handleClickEvent, true);\n\n windowObject.removeEventListener('focus', handleFocusEvent, true);\n windowObject.removeEventListener('blur', handleWindowBlur, false);\n\n if (typeof PointerEvent !== 'undefined') {\n documentObject.removeEventListener('pointerdown', handlePointerEvent, true);\n documentObject.removeEventListener('pointermove', handlePointerEvent, true);\n documentObject.removeEventListener('pointerup', handlePointerEvent, true);\n } else if (process.env.NODE_ENV === 'test') {\n documentObject.removeEventListener('mousedown', handlePointerEvent, true);\n documentObject.removeEventListener('mousemove', handlePointerEvent, true);\n documentObject.removeEventListener('mouseup', handlePointerEvent, true);\n }\n\n hasSetupGlobalListeners.delete(windowObject);\n};\n\n/**\n * EXPERIMENTAL\n * Adds a window (i.e. iframe) to the list of windows that are being tracked for focus visible.\n *\n * Sometimes apps render portions of their tree into an iframe. In this case, we cannot accurately\n * track if the focus is visible because we cannot see interactions inside the iframe. If you have\n * this in your application's architecture, then this function will attach event listeners inside\n * the iframe. You should call `addWindowFocusTracking` with an element from inside the window you\n * wish to add. We'll retrieve the relevant elements based on that. Note, you do not need to call\n * this for the default window, as we call it for you.\n *\n * When you are ready to stop listening, but you do not wish to unmount the iframe, you may call the\n * cleanup function returned by `addWindowFocusTracking`. Otherwise, when you unmount the iframe,\n * all listeners and state will be cleaned up automatically for you.\n *\n * @param element @default document.body - The element provided will be used to get the window to\n * add.\n * @returns A function to remove the event listeners and cleanup the state.\n */\nexport function addWindowFocusTracking(element?: HTMLElement | null): () => void {\n const documentObject = getOwnerDocument(element);\n let loadListener;\n if (documentObject.readyState !== 'loading') {\n setupGlobalFocusEvents(element);\n } else {\n loadListener = () => {\n setupGlobalFocusEvents(element);\n };\n documentObject.addEventListener('DOMContentLoaded', loadListener);\n }\n\n return () => tearDownWindowFocusTracking(element, loadListener);\n}\n\n// Server-side rendering does not have the document object defined\n// eslint-disable-next-line no-restricted-globals\nif (typeof document !== 'undefined') {\n addWindowFocusTracking();\n}\n\n/**\n * If true, keyboard focus is visible.\n */\nexport function isFocusVisible(): boolean {\n return currentModality !== 'pointer';\n}\n\nexport function getInteractionModality(): Modality | null {\n return currentModality;\n}\n\nexport function setInteractionModality(modality: Modality): void {\n currentModality = modality;\n currentPointerType = modality === 'pointer' ? 'mouse' : modality;\n triggerChangeHandlers(modality, null);\n}\n\n/** @private */\nexport function getPointerType(): PointerType {\n return currentPointerType;\n}\n\n/**\n * Keeps state of the current modality.\n */\nexport function useInteractionModality(): Modality | null {\n setupGlobalFocusEvents();\n\n let [modality, setModality] = useState(currentModality);\n useEffect(() => {\n let handler = () => {\n setModality(currentModality);\n };\n\n changeHandlers.add(handler);\n return () => {\n changeHandlers.delete(handler);\n };\n }, []);\n\n return useIsSSR() ? null : modality;\n}\n\nconst nonTextInputTypes = new Set([\n 'checkbox',\n 'radio',\n 'range',\n 'color',\n 'file',\n 'image',\n 'button',\n 'submit',\n 'reset'\n]);\n\n/**\n * If this is attached to text input component, return if the event is a focus event (Tab/Escape\n * keys pressed) so that focus visible style can be properly set.\n */\nfunction isKeyboardFocusEvent(isTextInput: boolean, modality: Modality, e: HandlerEvent) {\n let eventTarget = e ? (getEventTarget(e) as Element) : undefined;\n let ownerDocument = getOwnerDocument(eventTarget);\n let ownerWindow = getOwnerWindow(eventTarget);\n const IHTMLInputElement =\n typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLInputElement : HTMLInputElement;\n const IHTMLTextAreaElement =\n typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLTextAreaElement : HTMLTextAreaElement;\n const IHTMLElement = typeof ownerWindow !== 'undefined' ? ownerWindow.HTMLElement : HTMLElement;\n const IKeyboardEvent =\n typeof ownerWindow !== 'undefined' ? ownerWindow.KeyboardEvent : KeyboardEvent;\n\n // For keyboard events that occur on a non-input element that will move focus into input element (aka ArrowLeft going from Datepicker button to the main input group)\n // we need to rely on the user passing isTextInput into here. This way we can skip toggling focus visiblity for said input element\n let activeElement = getActiveElement(ownerDocument);\n isTextInput =\n isTextInput ||\n (activeElement instanceof IHTMLInputElement && !nonTextInputTypes.has(activeElement.type)) ||\n activeElement instanceof IHTMLTextAreaElement ||\n (activeElement instanceof IHTMLElement && activeElement.isContentEditable);\n return !(\n isTextInput &&\n modality === 'keyboard' &&\n e instanceof IKeyboardEvent &&\n !FOCUS_VISIBLE_INPUT_KEYS[e.key]\n );\n}\n\n/**\n * Manages focus visible state for the page, and subscribes individual components for updates.\n */\nexport function useFocusVisible(props: FocusVisibleProps = {}): FocusVisibleResult {\n let {isTextInput, autoFocus} = props;\n let [isFocusVisibleState, setFocusVisible] = useState(autoFocus || isFocusVisible());\n useFocusVisibleListener(\n isFocusVisible => {\n setFocusVisible(isFocusVisible);\n },\n [isTextInput],\n {isTextInput}\n );\n\n return {isFocusVisible: isFocusVisibleState};\n}\n\n/**\n * Listens for trigger change and reports if focus is visible (i.e., modality is not pointer).\n */\nexport function useFocusVisibleListener(\n fn: FocusVisibleHandler,\n deps: ReadonlyArray<any>,\n opts?: {enabled?: boolean; isTextInput?: boolean}\n): void {\n setupGlobalFocusEvents();\n\n useEffect(() => {\n if (opts?.enabled === false) {\n return;\n }\n let handler = (modality: Modality, e: HandlerEvent) => {\n // We want to early return for any keyboard events that occur inside text inputs EXCEPT for Tab and Escape\n if (!isKeyboardFocusEvent(!!opts?.isTextInput, modality, e)) {\n return;\n }\n fn(isFocusVisible());\n };\n changeHandlers.add(handler);\n return () => {\n changeHandlers.delete(handler);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n}\n"],"names":[],"version":3,"file":"useFocusVisible.mjs.map"}
|
|
@@ -120,15 +120,25 @@ function $a9918c67a493892d$export$cabe61c495ee3649(target) {
|
|
|
120
120
|
skipVisibilityCheck: true
|
|
121
121
|
}))target = target.parentElement;
|
|
122
122
|
let ownerWindow = (0, $49582955cc364b1c$exports.getOwnerWindow)(target);
|
|
123
|
-
let activeElement = ownerWindow.document
|
|
123
|
+
let activeElement = (0, $da02ee888921bc9e$exports.getActiveElement)(ownerWindow.document);
|
|
124
124
|
if (!activeElement || activeElement === target) return;
|
|
125
|
+
// Listen on the target's root (document or shadow root) so we catch focus events inside
|
|
126
|
+
// shadow DOM; they do not reach the main window.
|
|
127
|
+
let targetRoot = target?.getRootNode();
|
|
128
|
+
let root = targetRoot != null && (0, $49582955cc364b1c$exports.isShadowRoot)(targetRoot) ? targetRoot : (0, $49582955cc364b1c$exports.getOwnerWindow)(target);
|
|
129
|
+
// Focus is "moving to target" when it moves to the button or to a descendant of the button
|
|
130
|
+
// (e.g. SVG icon)
|
|
131
|
+
let isFocusMovingToTarget = (focusTarget)=>focusTarget === target || focusTarget != null && (0, $da02ee888921bc9e$exports.nodeContains)(target, focusTarget);
|
|
132
|
+
// Blur/focusout events have their target as the element losing focus. Stop propagation when
|
|
133
|
+
// that is the previously focused element (activeElement) or a descendant (e.g. in shadow DOM).
|
|
134
|
+
let isBlurFromActiveElement = (eventTarget)=>eventTarget === activeElement || activeElement != null && eventTarget != null && (0, $da02ee888921bc9e$exports.nodeContains)(activeElement, eventTarget);
|
|
125
135
|
$a9918c67a493892d$export$fda7da73ab5d4c48 = true;
|
|
126
136
|
let isRefocusing = false;
|
|
127
137
|
let onBlur = (e)=>{
|
|
128
|
-
if ((0, $da02ee888921bc9e$exports.getEventTarget)(e)
|
|
138
|
+
if (isBlurFromActiveElement((0, $da02ee888921bc9e$exports.getEventTarget)(e)) || isRefocusing) e.stopImmediatePropagation();
|
|
129
139
|
};
|
|
130
140
|
let onFocusOut = (e)=>{
|
|
131
|
-
if ((0, $da02ee888921bc9e$exports.getEventTarget)(e)
|
|
141
|
+
if (isBlurFromActiveElement((0, $da02ee888921bc9e$exports.getEventTarget)(e)) || isRefocusing) {
|
|
132
142
|
e.stopImmediatePropagation();
|
|
133
143
|
// If there was no focusable ancestor, we don't expect a focus event.
|
|
134
144
|
// Re-focus the original active element here.
|
|
@@ -140,10 +150,10 @@ function $a9918c67a493892d$export$cabe61c495ee3649(target) {
|
|
|
140
150
|
}
|
|
141
151
|
};
|
|
142
152
|
let onFocus = (e)=>{
|
|
143
|
-
if ((0, $da02ee888921bc9e$exports.getEventTarget)(e)
|
|
153
|
+
if (isFocusMovingToTarget((0, $da02ee888921bc9e$exports.getEventTarget)(e)) || isRefocusing) e.stopImmediatePropagation();
|
|
144
154
|
};
|
|
145
155
|
let onFocusIn = (e)=>{
|
|
146
|
-
if ((0, $da02ee888921bc9e$exports.getEventTarget)(e)
|
|
156
|
+
if (isFocusMovingToTarget((0, $da02ee888921bc9e$exports.getEventTarget)(e)) || isRefocusing) {
|
|
147
157
|
e.stopImmediatePropagation();
|
|
148
158
|
if (!isRefocusing) {
|
|
149
159
|
isRefocusing = true;
|
|
@@ -152,16 +162,16 @@ function $a9918c67a493892d$export$cabe61c495ee3649(target) {
|
|
|
152
162
|
}
|
|
153
163
|
}
|
|
154
164
|
};
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
165
|
+
root.addEventListener('blur', onBlur, true);
|
|
166
|
+
root.addEventListener('focusout', onFocusOut, true);
|
|
167
|
+
root.addEventListener('focusin', onFocusIn, true);
|
|
168
|
+
root.addEventListener('focus', onFocus, true);
|
|
159
169
|
let cleanup = ()=>{
|
|
160
170
|
cancelAnimationFrame(raf);
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
171
|
+
root.removeEventListener('blur', onBlur, true);
|
|
172
|
+
root.removeEventListener('focusout', onFocusOut, true);
|
|
173
|
+
root.removeEventListener('focusin', onFocusIn, true);
|
|
174
|
+
root.removeEventListener('focus', onFocus, true);
|
|
165
175
|
$a9918c67a493892d$export$fda7da73ab5d4c48 = false;
|
|
166
176
|
isRefocusing = false;
|
|
167
177
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAWM,SAAS,yCAA+C,WAAkB;IAC/E,IAAI,QAAQ;IACZ,MAAM,WAAW,GAAG;IACpB,MAAM,kBAAkB,GAAG,IAAM,MAAM,gBAAgB;IACvD,2FAA2F;IAC3F,MAAM,oBAAoB,GAAG,IAAM,AAAC,MAAc,YAAY;IAC9D,MAAM,OAAO,GAAG,KAAO;IAC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AC;QACf,IAAI,CAAA,GAAA,wCAAa,EAAE,OAAO,UAAU,cAAc;YAChD,EAAE,wBAAwB;YAE1B,IAAI,CAAC,cAAc;gBACjB,eAAe;gBACf,CAAA,GAAA,+CAAoB,EAAE;gBACtB;YACF;QACF;IACF;IAEA,YAAY,gBAAgB,CAAC,QAAQ,QAAQ;IAC7C,YAAY,gBAAgB,CAAC,YAAY,YAAY;IACrD,YAAY,gBAAgB,CAAC,WAAW,WAAW;IACnD,YAAY,gBAAgB,CAAC,SAAS,SAAS;IAE/C,IAAI,UAAU;QACZ,qBAAqB;QACrB,YAAY,mBAAmB,CAAC,QAAQ,QAAQ;QAChD,YAAY,mBAAmB,CAAC,YAAY,YAAY;QACxD,YAAY,mBAAmB,CAAC,WAAW,WAAW;QACtD,YAAY,mBAAmB,CAAC,SAAS,SAAS;QAClD,4CAAmB;QACnB,eAAe;IACjB;IAEA,IAAI,MAAM,sBAAsB;IAChC,OAAO;AACT","sources":["packages/react-aria/src/interactions/utils.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {FocusableElement} from '@react-types/shared';\nimport {focusWithoutScrolling} from '../utils/focusWithoutScrolling';\nimport {getActiveElement, getEventTarget} from '../utils/shadowdom/DOMFunctions';\nimport {getOwnerWindow} from '../utils/domHelpers';\nimport {isFocusable} from '../utils/isFocusable';\nimport {FocusEvent as ReactFocusEvent, SyntheticEvent, useCallback, useRef} from 'react';\nimport {useLayoutEffect} from '../utils/useLayoutEffect';\n\n// Turn a native event into a React synthetic event.\nexport function createSyntheticEvent<E extends SyntheticEvent>(nativeEvent: Event): E {\n let event = nativeEvent as any as E;\n event.nativeEvent = nativeEvent;\n event.isDefaultPrevented = () => event.defaultPrevented;\n // cancelBubble is technically deprecated in the spec, but still supported in all browsers.\n event.isPropagationStopped = () => (event as any).cancelBubble;\n event.persist = () => {};\n return event;\n}\n\nexport function setEventTarget(event: Event, target: Element): void {\n Object.defineProperty(event, 'target', {value: target});\n Object.defineProperty(event, 'currentTarget', {value: target});\n}\n\nexport function useSyntheticBlurEvent<Target extends Element = Element>(\n onBlur: (e: ReactFocusEvent<Target>) => void\n): (e: ReactFocusEvent<Target>) => void {\n let stateRef = useRef({\n isFocused: false,\n observer: null as MutationObserver | null\n });\n\n // Clean up MutationObserver on unmount. See below.\n\n useLayoutEffect(() => {\n const state = stateRef.current;\n return () => {\n if (state.observer) {\n state.observer.disconnect();\n state.observer = null;\n }\n };\n }, []);\n\n // This function is called during a React onFocus event.\n return useCallback(\n (e: ReactFocusEvent<Target>) => {\n // React does not fire onBlur when an element is disabled. https://github.com/facebook/react/issues/9142\n // Most browsers fire a native focusout event in this case, except for Firefox. In that case, we use a\n // MutationObserver to watch for the disabled attribute, and dispatch these events ourselves.\n // For browsers that do, focusout fires before the MutationObserver, so onBlur should not fire twice.\n let eventTarget = getEventTarget(e);\n if (\n eventTarget instanceof HTMLButtonElement ||\n eventTarget instanceof HTMLInputElement ||\n eventTarget instanceof HTMLTextAreaElement ||\n eventTarget instanceof HTMLSelectElement\n ) {\n stateRef.current.isFocused = true;\n\n let target = eventTarget;\n let onBlurHandler: EventListenerOrEventListenerObject | null = e => {\n stateRef.current.isFocused = false;\n\n if (target.disabled) {\n // For backward compatibility, dispatch a (fake) React synthetic event.\n let event = createSyntheticEvent<ReactFocusEvent<Target>>(e);\n onBlur?.(event);\n }\n\n // We no longer need the MutationObserver once the target is blurred.\n if (stateRef.current.observer) {\n stateRef.current.observer.disconnect();\n stateRef.current.observer = null;\n }\n };\n\n target.addEventListener('focusout', onBlurHandler, {once: true});\n\n stateRef.current.observer = new MutationObserver(() => {\n if (stateRef.current.isFocused && target.disabled) {\n stateRef.current.observer?.disconnect();\n let relatedTargetEl = target === getActiveElement() ? null : getActiveElement();\n target.dispatchEvent(new FocusEvent('blur', {relatedTarget: relatedTargetEl}));\n target.dispatchEvent(\n new FocusEvent('focusout', {bubbles: true, relatedTarget: relatedTargetEl})\n );\n }\n });\n\n stateRef.current.observer.observe(target, {\n attributes: true,\n attributeFilter: ['disabled']\n });\n }\n },\n [onBlur]\n );\n}\n\nexport let ignoreFocusEvent = false;\n\n/**\n * This function prevents the next focus event fired on `target`, without using\n * `event.preventDefault()`. It works by waiting for the series of focus events to occur, and\n * reverts focus back to where it was before. It also makes these events mostly non-observable by\n * using a capturing listener on the window and stopping propagation.\n */\nexport function preventFocus(target: FocusableElement | null): (() => void) | undefined {\n // The browser will focus the nearest focusable ancestor of our target.\n while (target && !isFocusable(target, {skipVisibilityCheck: true})) {\n target = target.parentElement;\n }\n\n let ownerWindow = getOwnerWindow(target);\n let activeElement = ownerWindow.document.activeElement as FocusableElement | null;\n if (!activeElement || activeElement === target) {\n return;\n }\n\n ignoreFocusEvent = true;\n let isRefocusing = false;\n let onBlur = (e: FocusEvent) => {\n if (getEventTarget(e) === activeElement || isRefocusing) {\n e.stopImmediatePropagation();\n }\n };\n\n let onFocusOut = (e: FocusEvent) => {\n if (getEventTarget(e) === activeElement || isRefocusing) {\n e.stopImmediatePropagation();\n\n // If there was no focusable ancestor, we don't expect a focus event.\n // Re-focus the original active element here.\n if (!target && !isRefocusing) {\n isRefocusing = true;\n focusWithoutScrolling(activeElement);\n cleanup();\n }\n }\n };\n\n let onFocus = (e: FocusEvent) => {\n if (getEventTarget(e) === target || isRefocusing) {\n e.stopImmediatePropagation();\n }\n };\n\n let onFocusIn = (e: FocusEvent) => {\n if (getEventTarget(e) === target || isRefocusing) {\n e.stopImmediatePropagation();\n\n if (!isRefocusing) {\n isRefocusing = true;\n focusWithoutScrolling(activeElement);\n cleanup();\n }\n }\n };\n\n ownerWindow.addEventListener('blur', onBlur, true);\n ownerWindow.addEventListener('focusout', onFocusOut, true);\n ownerWindow.addEventListener('focusin', onFocusIn, true);\n ownerWindow.addEventListener('focus', onFocus, true);\n\n let cleanup = () => {\n cancelAnimationFrame(raf);\n ownerWindow.removeEventListener('blur', onBlur, true);\n ownerWindow.removeEventListener('focusout', onFocusOut, true);\n ownerWindow.removeEventListener('focusin', onFocusIn, true);\n ownerWindow.removeEventListener('focus', onFocus, true);\n ignoreFocusEvent = false;\n isRefocusing = false;\n };\n\n let raf = requestAnimationFrame(cleanup);\n return cleanup;\n}\n"],"names":[],"version":3,"file":"utils.cjs.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AAWM,SAAS,yCAA+C,WAAkB;IAC/E,IAAI,QAAQ;IACZ,MAAM,WAAW,GAAG;IACpB,MAAM,kBAAkB,GAAG,IAAM,MAAM,gBAAgB;IACvD,2FAA2F;IAC3F,MAAM,oBAAoB,GAAG,IAAM,AAAC,MAAc,YAAY;IAC9D,MAAM,OAAO,GAAG,KAAO;IACvB,OAAO;AACT;AAEO,SAAS,0CAAe,KAAY,EAAE,MAAe;IAC1D,OAAO,cAAc,CAAC,OAAO,UAAU;QAAC,OAAO;IAAM;IACrD,OAAO,cAAc,CAAC,OAAO,iBAAiB;QAAC,OAAO;IAAM;AAC9D;AAEO,SAAS,0CACd,MAA4C;IAE5C,IAAI,WAAW,CAAA,GAAA,mBAAK,EAAE;QACpB,WAAW;QACX,UAAU;IACZ;IAEA,mDAAmD;IAEnD,CAAA,GAAA,yCAAc,EAAE;QACd,MAAM,QAAQ,SAAS,OAAO;QAC9B,OAAO;YACL,IAAI,MAAM,QAAQ,EAAE;gBAClB,MAAM,QAAQ,CAAC,UAAU;gBACzB,MAAM,QAAQ,GAAG;YACnB;QACF;IACF,GAAG,EAAE;IAEL,wDAAwD;IACxD,OAAO,CAAA,GAAA,wBAAU,EACf,CAAC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B,IAAI,CAAC,cAAc;gBACjB,eAAe;gBACf,CAAA,GAAA,+CAAoB,EAAE;gBACtB;YACF;QACF;IACF;IAEA,KAAK,gBAAgB,CAAC,QAAQ,QAAQ;IACtC,KAAK,gBAAgB,CAAC,YAAY,YAAY;IAC9C,KAAK,gBAAgB,CAAC,WAAW,WAAW;IAC5C,KAAK,gBAAgB,CAAC,SAAS,SAAS;IAExC,IAAI,UAAU;QACZ,qBAAqB;QACrB,KAAK,mBAAmB,CAAC,QAAQ,QAAQ;QACzC,KAAK,mBAAmB,CAAC,YAAY,YAAY;QACjD,KAAK,mBAAmB,CAAC,WAAW,WAAW;QAC/C,KAAK,mBAAmB,CAAC,SAAS,SAAS;QAC3C,4CAAmB;QACnB,eAAe;IACjB;IAEA,IAAI,MAAM,sBAAsB;IAChC,OAAO;AACT","sources":["packages/react-aria/src/interactions/utils.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {FocusableElement} from '@react-types/shared';\nimport {focusWithoutScrolling} from '../utils/focusWithoutScrolling';\nimport {getActiveElement, getEventTarget, nodeContains} from '../utils/shadowdom/DOMFunctions';\nimport {getOwnerWindow, isShadowRoot} from '../utils/domHelpers';\nimport {isFocusable} from '../utils/isFocusable';\nimport {FocusEvent as ReactFocusEvent, SyntheticEvent, useCallback, useRef} from 'react';\nimport {useLayoutEffect} from '../utils/useLayoutEffect';\n\n// Turn a native event into a React synthetic event.\nexport function createSyntheticEvent<E extends SyntheticEvent>(nativeEvent: Event): E {\n let event = nativeEvent as any as E;\n event.nativeEvent = nativeEvent;\n event.isDefaultPrevented = () => event.defaultPrevented;\n // cancelBubble is technically deprecated in the spec, but still supported in all browsers.\n event.isPropagationStopped = () => (event as any).cancelBubble;\n event.persist = () => {};\n return event;\n}\n\nexport function setEventTarget(event: Event, target: Element): void {\n Object.defineProperty(event, 'target', {value: target});\n Object.defineProperty(event, 'currentTarget', {value: target});\n}\n\nexport function useSyntheticBlurEvent<Target extends Element = Element>(\n onBlur: (e: ReactFocusEvent<Target>) => void\n): (e: ReactFocusEvent<Target>) => void {\n let stateRef = useRef({\n isFocused: false,\n observer: null as MutationObserver | null\n });\n\n // Clean up MutationObserver on unmount. See below.\n\n useLayoutEffect(() => {\n const state = stateRef.current;\n return () => {\n if (state.observer) {\n state.observer.disconnect();\n state.observer = null;\n }\n };\n }, []);\n\n // This function is called during a React onFocus event.\n return useCallback(\n (e: ReactFocusEvent<Target>) => {\n // React does not fire onBlur when an element is disabled. https://github.com/facebook/react/issues/9142\n // Most browsers fire a native focusout event in this case, except for Firefox. In that case, we use a\n // MutationObserver to watch for the disabled attribute, and dispatch these events ourselves.\n // For browsers that do, focusout fires before the MutationObserver, so onBlur should not fire twice.\n let eventTarget = getEventTarget(e);\n if (\n eventTarget instanceof HTMLButtonElement ||\n eventTarget instanceof HTMLInputElement ||\n eventTarget instanceof HTMLTextAreaElement ||\n eventTarget instanceof HTMLSelectElement\n ) {\n stateRef.current.isFocused = true;\n\n let target = eventTarget;\n let onBlurHandler: EventListenerOrEventListenerObject | null = e => {\n stateRef.current.isFocused = false;\n\n if (target.disabled) {\n // For backward compatibility, dispatch a (fake) React synthetic event.\n let event = createSyntheticEvent<ReactFocusEvent<Target>>(e);\n onBlur?.(event);\n }\n\n // We no longer need the MutationObserver once the target is blurred.\n if (stateRef.current.observer) {\n stateRef.current.observer.disconnect();\n stateRef.current.observer = null;\n }\n };\n\n target.addEventListener('focusout', onBlurHandler, {once: true});\n\n stateRef.current.observer = new MutationObserver(() => {\n if (stateRef.current.isFocused && target.disabled) {\n stateRef.current.observer?.disconnect();\n let relatedTargetEl = target === getActiveElement() ? null : getActiveElement();\n target.dispatchEvent(new FocusEvent('blur', {relatedTarget: relatedTargetEl}));\n target.dispatchEvent(\n new FocusEvent('focusout', {bubbles: true, relatedTarget: relatedTargetEl})\n );\n }\n });\n\n stateRef.current.observer.observe(target, {\n attributes: true,\n attributeFilter: ['disabled']\n });\n }\n },\n [onBlur]\n );\n}\n\nexport let ignoreFocusEvent = false;\n\n/**\n * This function prevents the next focus event fired on `target`, without using\n * `event.preventDefault()`. It works by waiting for the series of focus events to occur, and\n * reverts focus back to where it was before. It also makes these events mostly non-observable by\n * using a capturing listener on the window and stopping propagation.\n */\nexport function preventFocus(target: FocusableElement | null): (() => void) | undefined {\n // The browser will focus the nearest focusable ancestor of our target.\n while (target && !isFocusable(target, {skipVisibilityCheck: true})) {\n target = target.parentElement;\n }\n\n let ownerWindow = getOwnerWindow(target);\n let activeElement = getActiveElement(ownerWindow.document) as FocusableElement | null;\n if (!activeElement || activeElement === target) {\n return;\n }\n\n // Listen on the target's root (document or shadow root) so we catch focus events inside\n // shadow DOM; they do not reach the main window.\n let targetRoot = target?.getRootNode();\n let root = targetRoot != null && isShadowRoot(targetRoot) ? targetRoot : getOwnerWindow(target);\n\n // Focus is \"moving to target\" when it moves to the button or to a descendant of the button\n // (e.g. SVG icon)\n let isFocusMovingToTarget = (focusTarget: Element | null) =>\n focusTarget === target || (focusTarget != null && nodeContains(target, focusTarget));\n // Blur/focusout events have their target as the element losing focus. Stop propagation when\n // that is the previously focused element (activeElement) or a descendant (e.g. in shadow DOM).\n let isBlurFromActiveElement = (eventTarget: Element | null) =>\n eventTarget === activeElement ||\n (activeElement != null && eventTarget != null && nodeContains(activeElement, eventTarget));\n\n ignoreFocusEvent = true;\n let isRefocusing = false;\n let onBlur: EventListener = e => {\n if (isBlurFromActiveElement(getEventTarget(e) as Element) || isRefocusing) {\n e.stopImmediatePropagation();\n }\n };\n\n let onFocusOut: EventListener = e => {\n if (isBlurFromActiveElement(getEventTarget(e) as Element) || isRefocusing) {\n e.stopImmediatePropagation();\n\n // If there was no focusable ancestor, we don't expect a focus event.\n // Re-focus the original active element here.\n if (!target && !isRefocusing) {\n isRefocusing = true;\n focusWithoutScrolling(activeElement);\n cleanup();\n }\n }\n };\n\n let onFocus: EventListener = e => {\n if (isFocusMovingToTarget(getEventTarget(e) as Element) || isRefocusing) {\n e.stopImmediatePropagation();\n }\n };\n\n let onFocusIn: EventListener = e => {\n if (isFocusMovingToTarget(getEventTarget(e) as Element) || isRefocusing) {\n e.stopImmediatePropagation();\n\n if (!isRefocusing) {\n isRefocusing = true;\n focusWithoutScrolling(activeElement);\n cleanup();\n }\n }\n };\n\n root.addEventListener('blur', onBlur, true);\n root.addEventListener('focusout', onFocusOut, true);\n root.addEventListener('focusin', onFocusIn, true);\n root.addEventListener('focus', onFocus, true);\n\n let cleanup = () => {\n cancelAnimationFrame(raf);\n root.removeEventListener('blur', onBlur, true);\n root.removeEventListener('focusout', onFocusOut, true);\n root.removeEventListener('focusin', onFocusIn, true);\n root.removeEventListener('focus', onFocus, true);\n ignoreFocusEvent = false;\n isRefocusing = false;\n };\n\n let raf = requestAnimationFrame(cleanup);\n return cleanup;\n}\n"],"names":[],"version":3,"file":"utils.cjs.map"}
|