@react-aria/interactions 3.22.5 → 3.24.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.
Files changed (90) hide show
  1. package/dist/Pressable.main.js +28 -4
  2. package/dist/Pressable.main.js.map +1 -1
  3. package/dist/Pressable.mjs +30 -6
  4. package/dist/Pressable.module.js +30 -6
  5. package/dist/Pressable.module.js.map +1 -1
  6. package/dist/createEventHandler.main.js +5 -1
  7. package/dist/createEventHandler.main.js.map +1 -1
  8. package/dist/createEventHandler.mjs +5 -1
  9. package/dist/createEventHandler.module.js +5 -1
  10. package/dist/createEventHandler.module.js.map +1 -1
  11. package/dist/focusSafely.main.js +40 -0
  12. package/dist/focusSafely.main.js.map +1 -0
  13. package/dist/focusSafely.mjs +35 -0
  14. package/dist/focusSafely.module.js +35 -0
  15. package/dist/focusSafely.module.js.map +1 -0
  16. package/dist/import.mjs +5 -1
  17. package/dist/main.js +9 -0
  18. package/dist/main.js.map +1 -1
  19. package/dist/module.js +5 -1
  20. package/dist/module.js.map +1 -1
  21. package/dist/textSelection.main.js +5 -3
  22. package/dist/textSelection.main.js.map +1 -1
  23. package/dist/textSelection.mjs +5 -3
  24. package/dist/textSelection.module.js +5 -3
  25. package/dist/textSelection.module.js.map +1 -1
  26. package/dist/types.d.ts +59 -25
  27. package/dist/types.d.ts.map +1 -1
  28. package/dist/useFocus.main.js +2 -1
  29. package/dist/useFocus.main.js.map +1 -1
  30. package/dist/useFocus.mjs +3 -2
  31. package/dist/useFocus.module.js +3 -2
  32. package/dist/useFocus.module.js.map +1 -1
  33. package/dist/useFocusVisible.main.js +9 -3
  34. package/dist/useFocusVisible.main.js.map +1 -1
  35. package/dist/useFocusVisible.mjs +9 -3
  36. package/dist/useFocusVisible.module.js +9 -3
  37. package/dist/useFocusVisible.module.js.map +1 -1
  38. package/dist/useFocusWithin.main.js +33 -4
  39. package/dist/useFocusWithin.main.js.map +1 -1
  40. package/dist/useFocusWithin.mjs +34 -5
  41. package/dist/useFocusWithin.module.js +34 -5
  42. package/dist/useFocusWithin.module.js.map +1 -1
  43. package/dist/useFocusable.main.js +112 -0
  44. package/dist/useFocusable.main.js.map +1 -0
  45. package/dist/useFocusable.mjs +100 -0
  46. package/dist/useFocusable.module.js +100 -0
  47. package/dist/useFocusable.module.js.map +1 -0
  48. package/dist/useHover.main.js +18 -3
  49. package/dist/useHover.main.js.map +1 -1
  50. package/dist/useHover.mjs +18 -3
  51. package/dist/useHover.module.js +18 -3
  52. package/dist/useHover.module.js.map +1 -1
  53. package/dist/useInteractOutside.main.js +6 -1
  54. package/dist/useInteractOutside.main.js.map +1 -1
  55. package/dist/useInteractOutside.mjs +6 -1
  56. package/dist/useInteractOutside.module.js +6 -1
  57. package/dist/useInteractOutside.module.js.map +1 -1
  58. package/dist/useLongPress.main.js +2 -0
  59. package/dist/useLongPress.main.js.map +1 -1
  60. package/dist/useLongPress.mjs +3 -1
  61. package/dist/useLongPress.module.js +3 -1
  62. package/dist/useLongPress.module.js.map +1 -1
  63. package/dist/usePress.main.js +97 -94
  64. package/dist/usePress.main.js.map +1 -1
  65. package/dist/usePress.mjs +98 -95
  66. package/dist/usePress.module.js +98 -95
  67. package/dist/usePress.module.js.map +1 -1
  68. package/dist/utils.main.js +57 -1
  69. package/dist/utils.main.js.map +1 -1
  70. package/dist/utils.mjs +55 -2
  71. package/dist/utils.module.js +55 -2
  72. package/dist/utils.module.js.map +1 -1
  73. package/package.json +7 -5
  74. package/src/Pressable.tsx +66 -6
  75. package/src/createEventHandler.ts +8 -1
  76. package/src/focusSafely.ts +45 -0
  77. package/src/index.ts +3 -0
  78. package/src/textSelection.ts +6 -4
  79. package/src/useFocus.ts +3 -3
  80. package/src/useFocusVisible.ts +14 -4
  81. package/src/useFocusWithin.ts +34 -5
  82. package/src/useFocusable.tsx +183 -0
  83. package/src/useHover.ts +17 -3
  84. package/src/useInteractOutside.ts +9 -3
  85. package/src/useLongPress.ts +8 -2
  86. package/src/usePress.ts +132 -131
  87. package/src/utils.ts +80 -1
  88. package/src/DOMPropsContext.ts +0 -39
  89. package/src/DOMPropsResponder.tsx +0 -47
  90. package/src/useDOMPropsResponder.ts +0 -27
@@ -1,3 +1,4 @@
1
+ import {ignoreFocusEvent as $8a9cb279dc87e130$export$fda7da73ab5d4c48} from "./utils.module.js";
1
2
  import {isMac as $28AnR$isMac, isVirtualClick as $28AnR$isVirtualClick, getOwnerWindow as $28AnR$getOwnerWindow, getOwnerDocument as $28AnR$getOwnerDocument} from "@react-aria/utils";
2
3
  import {useState as $28AnR$useState, useEffect as $28AnR$useEffect} from "react";
3
4
  import {useIsSSR as $28AnR$useIsSSR} from "@react-aria/ssr";
@@ -19,6 +20,7 @@ import {useIsSSR as $28AnR$useIsSSR} from "@react-aria/ssr";
19
20
 
20
21
 
21
22
 
23
+
22
24
  let $507fabe10e71c6fb$var$currentModality = null;
23
25
  let $507fabe10e71c6fb$var$changeHandlers = new Set();
24
26
  let $507fabe10e71c6fb$export$d90243b58daecda7 = new Map(); // We use a map here to support setting event listeners across multiple document objects.
@@ -62,7 +64,7 @@ function $507fabe10e71c6fb$var$handleFocusEvent(e) {
62
64
  // Firefox fires two extra focus events when the user first clicks into an iframe:
63
65
  // first on the window, then on the document. We ignore these events so they don't
64
66
  // cause keyboard focus rings to appear.
65
- if (e.target === window || e.target === document) return;
67
+ if (e.target === window || e.target === document || (0, $8a9cb279dc87e130$export$fda7da73ab5d4c48) || !e.isTrusted) return;
66
68
  // If a focus event occurs without a preceding keyboard or pointer event, switch to virtual modality.
67
69
  // This occurs, for example, when navigating a form with the next/previous buttons on iOS.
68
70
  if (!$507fabe10e71c6fb$var$hasEventBeforeFocus && !$507fabe10e71c6fb$var$hasBlurredWindowRecently) {
@@ -73,6 +75,7 @@ function $507fabe10e71c6fb$var$handleFocusEvent(e) {
73
75
  $507fabe10e71c6fb$var$hasBlurredWindowRecently = false;
74
76
  }
75
77
  function $507fabe10e71c6fb$var$handleWindowBlur() {
78
+ if (0, $8a9cb279dc87e130$export$fda7da73ab5d4c48) return;
76
79
  // When the window is blurred, reset state. This is necessary when tabbing out of the window,
77
80
  // for example, since a subsequent focus event won't be fired.
78
81
  $507fabe10e71c6fb$var$hasEventBeforeFocus = false;
@@ -195,12 +198,14 @@ const $507fabe10e71c6fb$var$nonTextInputTypes = new Set([
195
198
  * If this is attached to text input component, return if the event is a focus event (Tab/Escape keys pressed) so that
196
199
  * focus visible style can be properly set.
197
200
  */ function $507fabe10e71c6fb$var$isKeyboardFocusEvent(isTextInput, modality, e) {
198
- var _e_target;
201
+ let document1 = (0, $28AnR$getOwnerDocument)(e === null || e === void 0 ? void 0 : e.target);
199
202
  const IHTMLInputElement = typeof window !== 'undefined' ? (0, $28AnR$getOwnerWindow)(e === null || e === void 0 ? void 0 : e.target).HTMLInputElement : HTMLInputElement;
200
203
  const IHTMLTextAreaElement = typeof window !== 'undefined' ? (0, $28AnR$getOwnerWindow)(e === null || e === void 0 ? void 0 : e.target).HTMLTextAreaElement : HTMLTextAreaElement;
201
204
  const IHTMLElement = typeof window !== 'undefined' ? (0, $28AnR$getOwnerWindow)(e === null || e === void 0 ? void 0 : e.target).HTMLElement : HTMLElement;
202
205
  const IKeyboardEvent = typeof window !== 'undefined' ? (0, $28AnR$getOwnerWindow)(e === null || e === void 0 ? void 0 : e.target).KeyboardEvent : KeyboardEvent;
203
- isTextInput = isTextInput || (e === null || e === void 0 ? void 0 : e.target) instanceof IHTMLInputElement && !$507fabe10e71c6fb$var$nonTextInputTypes.has(e === null || e === void 0 ? void 0 : (_e_target = e.target) === null || _e_target === void 0 ? void 0 : _e_target.type) || (e === null || e === void 0 ? void 0 : e.target) instanceof IHTMLTextAreaElement || (e === null || e === void 0 ? void 0 : e.target) instanceof IHTMLElement && (e === null || e === void 0 ? void 0 : e.target.isContentEditable);
206
+ // 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)
207
+ // we need to rely on the user passing isTextInput into here. This way we can skip toggling focus visiblity for said input element
208
+ isTextInput = isTextInput || document1.activeElement instanceof IHTMLInputElement && !$507fabe10e71c6fb$var$nonTextInputTypes.has(document1.activeElement.type) || document1.activeElement instanceof IHTMLTextAreaElement || document1.activeElement instanceof IHTMLElement && document1.activeElement.isContentEditable;
204
209
  return !(isTextInput && modality === 'keyboard' && e instanceof IKeyboardEvent && !$507fabe10e71c6fb$var$FOCUS_VISIBLE_INPUT_KEYS[e.key]);
205
210
  }
206
211
  function $507fabe10e71c6fb$export$ffd9e5021c1fb2d6(props = {}) {
@@ -221,6 +226,7 @@ function $507fabe10e71c6fb$export$ec71b4b83ac08ec3(fn, deps, opts) {
221
226
  $507fabe10e71c6fb$var$setupGlobalFocusEvents();
222
227
  (0, $28AnR$useEffect)(()=>{
223
228
  let handler = (modality, e)=>{
229
+ // We want to early return for any keyboard events that occur inside text inputs EXCEPT for Tab and Escape
224
230
  if (!$507fabe10e71c6fb$var$isKeyboardFocusEvent(!!(opts === null || opts === void 0 ? void 0 : opts.isTextInput), modality, e)) return;
225
231
  fn($507fabe10e71c6fb$export$b9b3dfddab17db27());
226
232
  };
@@ -1 +1 @@
1
- {"mappings":";;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;;AAsBlH,IAAI,wCAAmC;AACvC,IAAI,uCAAiB,IAAI;AAIlB,IAAI,4CAA0B,IAAI,OAAmC,yFAAyF;AACrK,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,qCAClB,QAAQ,UAAU;AAEtB;AAEA;;CAEC,GACD,SAAS,iCAAW,CAAgB;IAClC,gFAAgF;IAChF,OAAO,CAAE,CAAA,EAAE,OAAO,IAAK,CAAC,CAAA,GAAA,YAAI,OAAO,EAAE,MAAM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,KAAM,WAAW,GAAG,UAAU,IACzD;YAEF,GAAG;QACL;QACA,qCAAe,GAAG,CAAC;QACnB,OAAO;YACL,qCAAe,MAAM,CAAC;QACxB;IACF,uDAAuD;IACvD,GAAG;AACL","sources":["packages/@react-aria/interactions/src/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 {getOwnerDocument, getOwnerWindow, isMac, isVirtualClick} from '@react-aria/utils';\nimport {useEffect, useState} from 'react';\nimport {useIsSSR} from '@react-aria/ssr';\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 changeHandlers = new Set<Handler>();\ninterface GlobalListenerData {\n focus: () => void\n}\nexport let hasSetupGlobalListeners = new Map<Window, GlobalListenerData>(); // 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 styles visible.\n */\nfunction isValidKey(e: KeyboardEvent) {\n // Control and Shift keys trigger when navigating back to the tab with keyboard.\n return !(e.metaKey || (!isMac() && e.altKey) || e.ctrlKey || e.key === 'Control' || e.key === 'Shift' || e.key === 'Meta');\n}\n\n\nfunction handleKeyboardEvent(e: KeyboardEvent) {\n hasEventBeforeFocus = true;\n if (isValidKey(e)) {\n currentModality = 'keyboard';\n triggerChangeHandlers('keyboard', e);\n }\n}\n\nfunction handlePointerEvent(e: PointerEvent | MouseEvent) {\n currentModality = 'pointer';\n if (e.type === 'mousedown' || e.type === 'pointerdown') {\n hasEventBeforeFocus = true;\n triggerChangeHandlers('pointer', e);\n }\n}\n\nfunction handleClickEvent(e: MouseEvent) {\n if (isVirtualClick(e)) {\n hasEventBeforeFocus = true;\n currentModality = '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 if (e.target === window || e.target === document) {\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 triggerChangeHandlers('virtual', e);\n }\n\n hasEventBeforeFocus = false;\n hasBlurredWindowRecently = false;\n}\n\nfunction handleWindowBlur() {\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 if (typeof window === 'undefined' || hasSetupGlobalListeners.get(getOwnerWindow(element))) {\n return;\n }\n\n const windowObject = getOwnerWindow(element);\n const documentObject = getOwnerDocument(element);\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 let focus = windowObject.HTMLElement.prototype.focus;\n windowObject.HTMLElement.prototype.focus = function () {\n hasEventBeforeFocus = true;\n focus.apply(this, arguments as unknown as [options?: FocusOptions | undefined]);\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 {\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('beforeunload', () => {\n tearDownWindowFocusTracking(element);\n }, {once: true});\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 windowObject.HTMLElement.prototype.focus = hasSetupGlobalListeners.get(windowObject)!.focus;\n\n documentObject.removeEventListener('keydown', handleKeyboardEvent, true);\n documentObject.removeEventListener('keyup', handleKeyboardEvent, true);\n documentObject.removeEventListener('click', handleClickEvent, true);\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 {\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 track if the focus\n * is visible because we cannot see interactions inside the iframe. If you have this in your application's architecture,\n * then this function will attach event listeners inside the iframe. You should call `addWindowFocusTracking` with an\n * element from inside the window you wish to add. We'll retrieve the relevant elements based on that.\n * Note, you do not need to call 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 cleanup function\n * returned by `addWindowFocusTracking`. Otherwise, when you unmount the iframe, all listeners and state will be cleaned\n * up automatically for you.\n *\n * @param element @default document.body - The element provided will be used to get the window to 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) {\n currentModality = modality;\n triggerChangeHandlers(modality, null);\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 keys pressed) so that\n * focus visible style can be properly set.\n */\nfunction isKeyboardFocusEvent(isTextInput: boolean, modality: Modality, e: HandlerEvent) {\n const IHTMLInputElement = typeof window !== 'undefined' ? getOwnerWindow(e?.target as Element).HTMLInputElement : HTMLInputElement;\n const IHTMLTextAreaElement = typeof window !== 'undefined' ? getOwnerWindow(e?.target as Element).HTMLTextAreaElement : HTMLTextAreaElement;\n const IHTMLElement = typeof window !== 'undefined' ? getOwnerWindow(e?.target as Element).HTMLElement : HTMLElement;\n const IKeyboardEvent = typeof window !== 'undefined' ? getOwnerWindow(e?.target as Element).KeyboardEvent : KeyboardEvent;\n\n isTextInput = isTextInput ||\n (e?.target instanceof IHTMLInputElement && !nonTextInputTypes.has(e?.target?.type)) ||\n e?.target instanceof IHTMLTextAreaElement ||\n (e?.target instanceof IHTMLElement && e?.target.isContentEditable);\n return !(isTextInput && modality === 'keyboard' && e instanceof IKeyboardEvent && !FOCUS_VISIBLE_INPUT_KEYS[e.key]);\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((isFocusVisible) => {\n setFocusVisible(isFocusVisible);\n }, [isTextInput], {isTextInput});\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(fn: FocusVisibleHandler, deps: ReadonlyArray<any>, opts?: {isTextInput?: boolean}): void {\n setupGlobalFocusEvents();\n\n useEffect(() => {\n let handler = (modality: Modality, e: HandlerEvent) => {\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.module.js.map"}
1
+ {"mappings":";;;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;;;AAuBlH,IAAI,wCAAmC;AACvC,IAAI,uCAAiB,IAAI;AAIlB,IAAI,4CAA0B,IAAI,OAAmC,yFAAyF;AACrK,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,qCAClB,QAAQ,UAAU;AAEtB;AAEA;;CAEC,GACD,SAAS,iCAAW,CAAgB;IAClC,gFAAgF;IAChF,OAAO,CAAE,CAAA,EAAE,OAAO,IAAK,CAAC,CAAA,GAAA,YAAI,OAAO,EAAE,MAAM,IAAK,EAAE,OAAO,IAAI,EAAE,GAAG,KAAK,aAAa,EAAE,GAAG,KAAK,WAAW,EAAE,GAAG,KAAK,MAAK;AAC1H;AAGA,SAAS,0CAAoB,C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QACA,qCAAe,GAAG,CAAC;QACnB,OAAO;YACL,qCAAe,MAAM,CAAC;QACxB;IACF,uDAAuD;IACvD,GAAG;AACL","sources":["packages/@react-aria/interactions/src/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 {getOwnerDocument, getOwnerWindow, isMac, isVirtualClick} from '@react-aria/utils';\nimport {ignoreFocusEvent} from './utils';\nimport {useEffect, useState} from 'react';\nimport {useIsSSR} from '@react-aria/ssr';\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 changeHandlers = new Set<Handler>();\ninterface GlobalListenerData {\n focus: () => void\n}\nexport let hasSetupGlobalListeners = new Map<Window, GlobalListenerData>(); // 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 styles visible.\n */\nfunction isValidKey(e: KeyboardEvent) {\n // Control and Shift keys trigger when navigating back to the tab with keyboard.\n return !(e.metaKey || (!isMac() && e.altKey) || e.ctrlKey || e.key === 'Control' || e.key === 'Shift' || e.key === 'Meta');\n}\n\n\nfunction handleKeyboardEvent(e: KeyboardEvent) {\n hasEventBeforeFocus = true;\n if (isValidKey(e)) {\n currentModality = 'keyboard';\n triggerChangeHandlers('keyboard', e);\n }\n}\n\nfunction handlePointerEvent(e: PointerEvent | MouseEvent) {\n currentModality = 'pointer';\n if (e.type === 'mousedown' || e.type === 'pointerdown') {\n hasEventBeforeFocus = true;\n triggerChangeHandlers('pointer', e);\n }\n}\n\nfunction handleClickEvent(e: MouseEvent) {\n if (isVirtualClick(e)) {\n hasEventBeforeFocus = true;\n currentModality = '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 if (e.target === window || e.target === document || ignoreFocusEvent || !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 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 if (typeof window === 'undefined' || hasSetupGlobalListeners.get(getOwnerWindow(element))) {\n return;\n }\n\n const windowObject = getOwnerWindow(element);\n const documentObject = getOwnerDocument(element);\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 let focus = windowObject.HTMLElement.prototype.focus;\n windowObject.HTMLElement.prototype.focus = function () {\n hasEventBeforeFocus = true;\n focus.apply(this, arguments as unknown as [options?: FocusOptions | undefined]);\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 {\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('beforeunload', () => {\n tearDownWindowFocusTracking(element);\n }, {once: true});\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 windowObject.HTMLElement.prototype.focus = hasSetupGlobalListeners.get(windowObject)!.focus;\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 {\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 track if the focus\n * is visible because we cannot see interactions inside the iframe. If you have this in your application's architecture,\n * then this function will attach event listeners inside the iframe. You should call `addWindowFocusTracking` with an\n * element from inside the window you wish to add. We'll retrieve the relevant elements based on that.\n * Note, you do not need to call 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 cleanup function\n * returned by `addWindowFocusTracking`. Otherwise, when you unmount the iframe, all listeners and state will be cleaned\n * up automatically for you.\n *\n * @param element @default document.body - The element provided will be used to get the window to 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) {\n currentModality = modality;\n triggerChangeHandlers(modality, null);\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 keys pressed) so that\n * focus visible style can be properly set.\n */\nfunction isKeyboardFocusEvent(isTextInput: boolean, modality: Modality, e: HandlerEvent) {\n let document = getOwnerDocument(e?.target as Element);\n const IHTMLInputElement = typeof window !== 'undefined' ? getOwnerWindow(e?.target as Element).HTMLInputElement : HTMLInputElement;\n const IHTMLTextAreaElement = typeof window !== 'undefined' ? getOwnerWindow(e?.target as Element).HTMLTextAreaElement : HTMLTextAreaElement;\n const IHTMLElement = typeof window !== 'undefined' ? getOwnerWindow(e?.target as Element).HTMLElement : HTMLElement;\n const IKeyboardEvent = typeof window !== 'undefined' ? getOwnerWindow(e?.target as Element).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 isTextInput = isTextInput ||\n (document.activeElement instanceof IHTMLInputElement && !nonTextInputTypes.has(document.activeElement.type)) ||\n document.activeElement instanceof IHTMLTextAreaElement ||\n (document.activeElement instanceof IHTMLElement && document.activeElement.isContentEditable);\n return !(isTextInput && modality === 'keyboard' && e instanceof IKeyboardEvent && !FOCUS_VISIBLE_INPUT_KEYS[e.key]);\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((isFocusVisible) => {\n setFocusVisible(isFocusVisible);\n }, [isTextInput], {isTextInput});\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(fn: FocusVisibleHandler, deps: ReadonlyArray<any>, opts?: {isTextInput?: boolean}): void {\n setupGlobalFocusEvents();\n\n useEffect(() => {\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.module.js.map"}
@@ -1,5 +1,6 @@
1
1
  var $625cf83917e112ad$exports = require("./utils.main.js");
2
2
  var $kDAhS$react = require("react");
3
+ var $kDAhS$reactariautils = require("@react-aria/utils");
3
4
 
4
5
 
5
6
  function $parcel$export(e, n, v, s) {
@@ -23,43 +24,71 @@ $parcel$export(module.exports, "useFocusWithin", () => $d16842bbd0359d1b$export$
23
24
  // See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
24
25
 
25
26
 
27
+
26
28
  function $d16842bbd0359d1b$export$420e68273165f4ec(props) {
27
29
  let { isDisabled: isDisabled, onBlurWithin: onBlurWithin, onFocusWithin: onFocusWithin, onFocusWithinChange: onFocusWithinChange } = props;
28
30
  let state = (0, $kDAhS$react.useRef)({
29
31
  isFocusWithin: false
30
32
  });
33
+ let { addGlobalListener: addGlobalListener, removeAllGlobalListeners: removeAllGlobalListeners } = (0, $kDAhS$reactariautils.useGlobalListeners)();
31
34
  let onBlur = (0, $kDAhS$react.useCallback)((e)=>{
35
+ // Ignore events bubbling through portals.
36
+ if (!e.currentTarget.contains(e.target)) return;
32
37
  // We don't want to trigger onBlurWithin and then immediately onFocusWithin again
33
38
  // when moving focus inside the element. Only trigger if the currentTarget doesn't
34
39
  // include the relatedTarget (where focus is moving).
35
40
  if (state.current.isFocusWithin && !e.currentTarget.contains(e.relatedTarget)) {
36
41
  state.current.isFocusWithin = false;
42
+ removeAllGlobalListeners();
37
43
  if (onBlurWithin) onBlurWithin(e);
38
44
  if (onFocusWithinChange) onFocusWithinChange(false);
39
45
  }
40
46
  }, [
41
47
  onBlurWithin,
42
48
  onFocusWithinChange,
43
- state
49
+ state,
50
+ removeAllGlobalListeners
44
51
  ]);
45
52
  let onSyntheticFocus = (0, $625cf83917e112ad$exports.useSyntheticBlurEvent)(onBlur);
46
53
  let onFocus = (0, $kDAhS$react.useCallback)((e)=>{
54
+ // Ignore events bubbling through portals.
55
+ if (!e.currentTarget.contains(e.target)) return;
47
56
  // Double check that document.activeElement actually matches e.target in case a previously chained
48
57
  // focus handler already moved focus somewhere else.
49
- if (!state.current.isFocusWithin && document.activeElement === e.target) {
58
+ const ownerDocument = (0, $kDAhS$reactariautils.getOwnerDocument)(e.target);
59
+ const activeElement = (0, $kDAhS$reactariautils.getActiveElement)(ownerDocument);
60
+ if (!state.current.isFocusWithin && activeElement === (0, $kDAhS$reactariautils.getEventTarget)(e.nativeEvent)) {
50
61
  if (onFocusWithin) onFocusWithin(e);
51
62
  if (onFocusWithinChange) onFocusWithinChange(true);
52
63
  state.current.isFocusWithin = true;
53
64
  onSyntheticFocus(e);
65
+ // Browsers don't fire blur events when elements are removed from the DOM.
66
+ // However, if a focus event occurs outside the element we're tracking, we
67
+ // can manually fire onBlur.
68
+ let currentTarget = e.currentTarget;
69
+ addGlobalListener(ownerDocument, 'focus', (e)=>{
70
+ if (state.current.isFocusWithin && !(0, $kDAhS$reactariautils.nodeContains)(currentTarget, e.target)) {
71
+ let event = new (0, $625cf83917e112ad$exports.SyntheticFocusEvent)('blur', new ownerDocument.defaultView.FocusEvent('blur', {
72
+ relatedTarget: e.target
73
+ }));
74
+ event.target = currentTarget;
75
+ event.currentTarget = currentTarget;
76
+ onBlur(event);
77
+ }
78
+ }, {
79
+ capture: true
80
+ });
54
81
  }
55
82
  }, [
56
83
  onFocusWithin,
57
84
  onFocusWithinChange,
58
- onSyntheticFocus
85
+ onSyntheticFocus,
86
+ addGlobalListener,
87
+ onBlur
59
88
  ]);
60
89
  if (isDisabled) return {
61
90
  focusWithinProps: {
62
- // These should not have been null, that would conflict in mergeProps
91
+ // These cannot be null, that would conflict in mergeProps
63
92
  onFocus: undefined,
64
93
  onBlur: undefined
65
94
  }
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;AAyB3G,SAAS,0CAAe,KAAuB;IACpD,IAAI,cACF,UAAU,gBACV,YAAY,iBACZ,aAAa,uBACb,mBAAmB,EACpB,GAAG;IACJ,IAAI,QAAQ,CAAA,GAAA,mBAAK,EAAE;QACjB,eAAe;IACjB;IAEA,IAAI,SAAS,CAAA,GAAA,wBAAU,EAAE,CAAC;QACxB,iFAAiF;QACjF,kFAAkF;QAClF,qDAAqD;QACrD,IAAI,MAAM,OAAO,CAAC,aAAa,IAAI,CAAC,AAAC,EAAE,aAAa,CAAa,QAAQ,CAAC,EAAE,aAAa,GAAc;YACrG,MAAM,OAAO,CAAC,aAAa,GAAG;YAE9B,IAAI,cACF,aAAa;YAGf,IAAI,qBACF,oBAAoB;QAExB;IACF,GAAG;QAAC;QAAc;QAAqB;KAAM;IAE7C,IAAI,mBAAmB,CAAA,GAAA,+CAAoB,EAAE;IAC7C,IAAI,UAAU,CAAA,GAAA,wBAAU,EAAE,CAAC;QACzB,kGAAkG;QAClG,oDAAoD;QACpD,IAAI,CAAC,MAAM,OAAO,CAAC,aAAa,IAAI,SAAS,aAAa,KAAK,EAAE,MAAM,EAAE;YACvE,IAAI,eACF,cAAc;YAGhB,IAAI,qBACF,oBAAoB;YAGtB,MAAM,OAAO,CAAC,aAAa,GAAG;YAC9B,iBAAiB;QACnB;IACF,GAAG;QAAC;QAAe;QAAqB;KAAiB;IAEzD,IAAI,YACF,OAAO;QACL,kBAAkB;YAChB,qEAAqE;YACrE,SAAS;YACT,QAAQ;QACV;IACF;IAGF,OAAO;QACL,kBAAkB;qBAChB;oBACA;QACF;IACF;AACF","sources":["packages/@react-aria/interactions/src/useFocusWithin.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 {DOMAttributes} from '@react-types/shared';\nimport {FocusEvent, useCallback, useRef} from 'react';\nimport {useSyntheticBlurEvent} from './utils';\n\nexport interface FocusWithinProps {\n /** Whether the focus within events should be disabled. */\n isDisabled?: boolean,\n /** Handler that is called when the target element or a descendant receives focus. */\n onFocusWithin?: (e: FocusEvent) => void,\n /** Handler that is called when the target element and all descendants lose focus. */\n onBlurWithin?: (e: FocusEvent) => void,\n /** Handler that is called when the the focus within state changes. */\n onFocusWithinChange?: (isFocusWithin: boolean) => void\n}\n\nexport interface FocusWithinResult {\n /** Props to spread onto the target element. */\n focusWithinProps: DOMAttributes\n}\n\n/**\n * Handles focus events for the target and its descendants.\n */\nexport function useFocusWithin(props: FocusWithinProps): FocusWithinResult {\n let {\n isDisabled,\n onBlurWithin,\n onFocusWithin,\n onFocusWithinChange\n } = props;\n let state = useRef({\n isFocusWithin: false\n });\n\n let onBlur = useCallback((e: FocusEvent) => {\n // We don't want to trigger onBlurWithin and then immediately onFocusWithin again\n // when moving focus inside the element. Only trigger if the currentTarget doesn't\n // include the relatedTarget (where focus is moving).\n if (state.current.isFocusWithin && !(e.currentTarget as Element).contains(e.relatedTarget as Element)) {\n state.current.isFocusWithin = false;\n\n if (onBlurWithin) {\n onBlurWithin(e);\n }\n\n if (onFocusWithinChange) {\n onFocusWithinChange(false);\n }\n }\n }, [onBlurWithin, onFocusWithinChange, state]);\n\n let onSyntheticFocus = useSyntheticBlurEvent(onBlur);\n let onFocus = useCallback((e: FocusEvent) => {\n // Double check that document.activeElement actually matches e.target in case a previously chained\n // focus handler already moved focus somewhere else.\n if (!state.current.isFocusWithin && document.activeElement === e.target) {\n if (onFocusWithin) {\n onFocusWithin(e);\n }\n\n if (onFocusWithinChange) {\n onFocusWithinChange(true);\n }\n\n state.current.isFocusWithin = true;\n onSyntheticFocus(e);\n }\n }, [onFocusWithin, onFocusWithinChange, onSyntheticFocus]);\n\n if (isDisabled) {\n return {\n focusWithinProps: {\n // These should not have been null, that would conflict in mergeProps\n onFocus: undefined,\n onBlur: undefined\n }\n };\n }\n\n return {\n focusWithinProps: {\n onFocus,\n onBlur\n }\n };\n}\n"],"names":[],"version":3,"file":"useFocusWithin.main.js.map"}
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;;AA0B3G,SAAS,0CAAe,KAAuB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a;YACnC,kBAAkB,eAAe,SAAS,CAAA;gBACxC,IAAI,MAAM,OAAO,CAAC,aAAa,IAAI,CAAC,CAAA,GAAA,kCAAW,EAAE,eAAe,EAAE,MAAM,GAAc;oBACpF,IAAI,QAAQ,IAAI,CAAA,GAAA,6CAAkB,EAAE,QAAQ,IAAI,cAAc,WAAW,CAAE,UAAU,CAAC,QAAQ;wBAAC,eAAe,EAAE,MAAM;oBAAA;oBACtH,MAAM,MAAM,GAAG;oBACf,MAAM,aAAa,GAAG;oBACtB,OAAO;gBACT;YACF,GAAG;gBAAC,SAAS;YAAI;QACnB;IACF,GAAG;QAAC;QAAe;QAAqB;QAAkB;QAAmB;KAAO;IAEpF,IAAI,YACF,OAAO;QACL,kBAAkB;YAChB,0DAA0D;YAC1D,SAAS;YACT,QAAQ;QACV;IACF;IAGF,OAAO;QACL,kBAAkB;qBAChB;oBACA;QACF;IACF;AACF","sources":["packages/@react-aria/interactions/src/useFocusWithin.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 {DOMAttributes} from '@react-types/shared';\nimport {FocusEvent, useCallback, useRef} from 'react';\nimport {getActiveElement, getEventTarget, getOwnerDocument, nodeContains, useGlobalListeners} from '@react-aria/utils';\nimport {SyntheticFocusEvent, useSyntheticBlurEvent} from './utils';\n\nexport interface FocusWithinProps {\n /** Whether the focus within events should be disabled. */\n isDisabled?: boolean,\n /** Handler that is called when the target element or a descendant receives focus. */\n onFocusWithin?: (e: FocusEvent) => void,\n /** Handler that is called when the target element and all descendants lose focus. */\n onBlurWithin?: (e: FocusEvent) => void,\n /** Handler that is called when the the focus within state changes. */\n onFocusWithinChange?: (isFocusWithin: boolean) => void\n}\n\nexport interface FocusWithinResult {\n /** Props to spread onto the target element. */\n focusWithinProps: DOMAttributes\n}\n\n/**\n * Handles focus events for the target and its descendants.\n */\nexport function useFocusWithin(props: FocusWithinProps): FocusWithinResult {\n let {\n isDisabled,\n onBlurWithin,\n onFocusWithin,\n onFocusWithinChange\n } = props;\n let state = useRef({\n isFocusWithin: false\n });\n\n let {addGlobalListener, removeAllGlobalListeners} = useGlobalListeners();\n\n let onBlur = useCallback((e: FocusEvent) => {\n // Ignore events bubbling through portals.\n if (!e.currentTarget.contains(e.target)) {\n return;\n }\n\n // We don't want to trigger onBlurWithin and then immediately onFocusWithin again\n // when moving focus inside the element. Only trigger if the currentTarget doesn't\n // include the relatedTarget (where focus is moving).\n if (state.current.isFocusWithin && !(e.currentTarget as Element).contains(e.relatedTarget as Element)) {\n state.current.isFocusWithin = false;\n removeAllGlobalListeners();\n\n if (onBlurWithin) {\n onBlurWithin(e);\n }\n\n if (onFocusWithinChange) {\n onFocusWithinChange(false);\n }\n }\n }, [onBlurWithin, onFocusWithinChange, state, removeAllGlobalListeners]);\n\n let onSyntheticFocus = useSyntheticBlurEvent(onBlur);\n let onFocus = useCallback((e: FocusEvent) => {\n // Ignore events bubbling through portals.\n if (!e.currentTarget.contains(e.target)) {\n return;\n }\n\n // Double check that document.activeElement actually matches e.target in case a previously chained\n // focus handler already moved focus somewhere else.\n const ownerDocument = getOwnerDocument(e.target);\n const activeElement = getActiveElement(ownerDocument);\n if (!state.current.isFocusWithin && activeElement === getEventTarget(e.nativeEvent)) {\n if (onFocusWithin) {\n onFocusWithin(e);\n }\n\n if (onFocusWithinChange) {\n onFocusWithinChange(true);\n }\n\n state.current.isFocusWithin = true;\n onSyntheticFocus(e);\n\n // Browsers don't fire blur events when elements are removed from the DOM.\n // However, if a focus event occurs outside the element we're tracking, we\n // can manually fire onBlur.\n let currentTarget = e.currentTarget;\n addGlobalListener(ownerDocument, 'focus', e => {\n if (state.current.isFocusWithin && !nodeContains(currentTarget, e.target as Element)) {\n let event = new SyntheticFocusEvent('blur', new ownerDocument.defaultView!.FocusEvent('blur', {relatedTarget: e.target}));\n event.target = currentTarget;\n event.currentTarget = currentTarget;\n onBlur(event);\n }\n }, {capture: true});\n }\n }, [onFocusWithin, onFocusWithinChange, onSyntheticFocus, addGlobalListener, onBlur]);\n\n if (isDisabled) {\n return {\n focusWithinProps: {\n // These cannot be null, that would conflict in mergeProps\n onFocus: undefined,\n onBlur: undefined\n }\n };\n }\n\n return {\n focusWithinProps: {\n onFocus,\n onBlur\n }\n };\n}\n"],"names":[],"version":3,"file":"useFocusWithin.main.js.map"}
@@ -1,5 +1,6 @@
1
- import {useSyntheticBlurEvent as $8a9cb279dc87e130$export$715c682d09d639cc} from "./utils.mjs";
1
+ import {SyntheticFocusEvent as $8a9cb279dc87e130$export$905e7fc544a71f36, useSyntheticBlurEvent as $8a9cb279dc87e130$export$715c682d09d639cc} from "./utils.mjs";
2
2
  import {useRef as $3b9Q0$useRef, useCallback as $3b9Q0$useCallback} from "react";
3
+ import {useGlobalListeners as $3b9Q0$useGlobalListeners, getOwnerDocument as $3b9Q0$getOwnerDocument, getActiveElement as $3b9Q0$getActiveElement, getEventTarget as $3b9Q0$getEventTarget, nodeContains as $3b9Q0$nodeContains} from "@react-aria/utils";
3
4
 
4
5
  /*
5
6
  * Copyright 2020 Adobe. All rights reserved.
@@ -17,43 +18,71 @@ import {useRef as $3b9Q0$useRef, useCallback as $3b9Q0$useCallback} from "react"
17
18
  // See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
18
19
 
19
20
 
21
+
20
22
  function $9ab94262bd0047c7$export$420e68273165f4ec(props) {
21
23
  let { isDisabled: isDisabled, onBlurWithin: onBlurWithin, onFocusWithin: onFocusWithin, onFocusWithinChange: onFocusWithinChange } = props;
22
24
  let state = (0, $3b9Q0$useRef)({
23
25
  isFocusWithin: false
24
26
  });
27
+ let { addGlobalListener: addGlobalListener, removeAllGlobalListeners: removeAllGlobalListeners } = (0, $3b9Q0$useGlobalListeners)();
25
28
  let onBlur = (0, $3b9Q0$useCallback)((e)=>{
29
+ // Ignore events bubbling through portals.
30
+ if (!e.currentTarget.contains(e.target)) return;
26
31
  // We don't want to trigger onBlurWithin and then immediately onFocusWithin again
27
32
  // when moving focus inside the element. Only trigger if the currentTarget doesn't
28
33
  // include the relatedTarget (where focus is moving).
29
34
  if (state.current.isFocusWithin && !e.currentTarget.contains(e.relatedTarget)) {
30
35
  state.current.isFocusWithin = false;
36
+ removeAllGlobalListeners();
31
37
  if (onBlurWithin) onBlurWithin(e);
32
38
  if (onFocusWithinChange) onFocusWithinChange(false);
33
39
  }
34
40
  }, [
35
41
  onBlurWithin,
36
42
  onFocusWithinChange,
37
- state
43
+ state,
44
+ removeAllGlobalListeners
38
45
  ]);
39
46
  let onSyntheticFocus = (0, $8a9cb279dc87e130$export$715c682d09d639cc)(onBlur);
40
47
  let onFocus = (0, $3b9Q0$useCallback)((e)=>{
48
+ // Ignore events bubbling through portals.
49
+ if (!e.currentTarget.contains(e.target)) return;
41
50
  // Double check that document.activeElement actually matches e.target in case a previously chained
42
51
  // focus handler already moved focus somewhere else.
43
- if (!state.current.isFocusWithin && document.activeElement === e.target) {
52
+ const ownerDocument = (0, $3b9Q0$getOwnerDocument)(e.target);
53
+ const activeElement = (0, $3b9Q0$getActiveElement)(ownerDocument);
54
+ if (!state.current.isFocusWithin && activeElement === (0, $3b9Q0$getEventTarget)(e.nativeEvent)) {
44
55
  if (onFocusWithin) onFocusWithin(e);
45
56
  if (onFocusWithinChange) onFocusWithinChange(true);
46
57
  state.current.isFocusWithin = true;
47
58
  onSyntheticFocus(e);
59
+ // Browsers don't fire blur events when elements are removed from the DOM.
60
+ // However, if a focus event occurs outside the element we're tracking, we
61
+ // can manually fire onBlur.
62
+ let currentTarget = e.currentTarget;
63
+ addGlobalListener(ownerDocument, 'focus', (e)=>{
64
+ if (state.current.isFocusWithin && !(0, $3b9Q0$nodeContains)(currentTarget, e.target)) {
65
+ let event = new (0, $8a9cb279dc87e130$export$905e7fc544a71f36)('blur', new ownerDocument.defaultView.FocusEvent('blur', {
66
+ relatedTarget: e.target
67
+ }));
68
+ event.target = currentTarget;
69
+ event.currentTarget = currentTarget;
70
+ onBlur(event);
71
+ }
72
+ }, {
73
+ capture: true
74
+ });
48
75
  }
49
76
  }, [
50
77
  onFocusWithin,
51
78
  onFocusWithinChange,
52
- onSyntheticFocus
79
+ onSyntheticFocus,
80
+ addGlobalListener,
81
+ onBlur
53
82
  ]);
54
83
  if (isDisabled) return {
55
84
  focusWithinProps: {
56
- // These should not have been null, that would conflict in mergeProps
85
+ // These cannot be null, that would conflict in mergeProps
57
86
  onFocus: undefined,
58
87
  onBlur: undefined
59
88
  }
@@ -1,5 +1,6 @@
1
- import {useSyntheticBlurEvent as $8a9cb279dc87e130$export$715c682d09d639cc} from "./utils.module.js";
1
+ import {SyntheticFocusEvent as $8a9cb279dc87e130$export$905e7fc544a71f36, useSyntheticBlurEvent as $8a9cb279dc87e130$export$715c682d09d639cc} from "./utils.module.js";
2
2
  import {useRef as $3b9Q0$useRef, useCallback as $3b9Q0$useCallback} from "react";
3
+ import {useGlobalListeners as $3b9Q0$useGlobalListeners, getOwnerDocument as $3b9Q0$getOwnerDocument, getActiveElement as $3b9Q0$getActiveElement, getEventTarget as $3b9Q0$getEventTarget, nodeContains as $3b9Q0$nodeContains} from "@react-aria/utils";
3
4
 
4
5
  /*
5
6
  * Copyright 2020 Adobe. All rights reserved.
@@ -17,43 +18,71 @@ import {useRef as $3b9Q0$useRef, useCallback as $3b9Q0$useCallback} from "react"
17
18
  // See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
18
19
 
19
20
 
21
+
20
22
  function $9ab94262bd0047c7$export$420e68273165f4ec(props) {
21
23
  let { isDisabled: isDisabled, onBlurWithin: onBlurWithin, onFocusWithin: onFocusWithin, onFocusWithinChange: onFocusWithinChange } = props;
22
24
  let state = (0, $3b9Q0$useRef)({
23
25
  isFocusWithin: false
24
26
  });
27
+ let { addGlobalListener: addGlobalListener, removeAllGlobalListeners: removeAllGlobalListeners } = (0, $3b9Q0$useGlobalListeners)();
25
28
  let onBlur = (0, $3b9Q0$useCallback)((e)=>{
29
+ // Ignore events bubbling through portals.
30
+ if (!e.currentTarget.contains(e.target)) return;
26
31
  // We don't want to trigger onBlurWithin and then immediately onFocusWithin again
27
32
  // when moving focus inside the element. Only trigger if the currentTarget doesn't
28
33
  // include the relatedTarget (where focus is moving).
29
34
  if (state.current.isFocusWithin && !e.currentTarget.contains(e.relatedTarget)) {
30
35
  state.current.isFocusWithin = false;
36
+ removeAllGlobalListeners();
31
37
  if (onBlurWithin) onBlurWithin(e);
32
38
  if (onFocusWithinChange) onFocusWithinChange(false);
33
39
  }
34
40
  }, [
35
41
  onBlurWithin,
36
42
  onFocusWithinChange,
37
- state
43
+ state,
44
+ removeAllGlobalListeners
38
45
  ]);
39
46
  let onSyntheticFocus = (0, $8a9cb279dc87e130$export$715c682d09d639cc)(onBlur);
40
47
  let onFocus = (0, $3b9Q0$useCallback)((e)=>{
48
+ // Ignore events bubbling through portals.
49
+ if (!e.currentTarget.contains(e.target)) return;
41
50
  // Double check that document.activeElement actually matches e.target in case a previously chained
42
51
  // focus handler already moved focus somewhere else.
43
- if (!state.current.isFocusWithin && document.activeElement === e.target) {
52
+ const ownerDocument = (0, $3b9Q0$getOwnerDocument)(e.target);
53
+ const activeElement = (0, $3b9Q0$getActiveElement)(ownerDocument);
54
+ if (!state.current.isFocusWithin && activeElement === (0, $3b9Q0$getEventTarget)(e.nativeEvent)) {
44
55
  if (onFocusWithin) onFocusWithin(e);
45
56
  if (onFocusWithinChange) onFocusWithinChange(true);
46
57
  state.current.isFocusWithin = true;
47
58
  onSyntheticFocus(e);
59
+ // Browsers don't fire blur events when elements are removed from the DOM.
60
+ // However, if a focus event occurs outside the element we're tracking, we
61
+ // can manually fire onBlur.
62
+ let currentTarget = e.currentTarget;
63
+ addGlobalListener(ownerDocument, 'focus', (e)=>{
64
+ if (state.current.isFocusWithin && !(0, $3b9Q0$nodeContains)(currentTarget, e.target)) {
65
+ let event = new (0, $8a9cb279dc87e130$export$905e7fc544a71f36)('blur', new ownerDocument.defaultView.FocusEvent('blur', {
66
+ relatedTarget: e.target
67
+ }));
68
+ event.target = currentTarget;
69
+ event.currentTarget = currentTarget;
70
+ onBlur(event);
71
+ }
72
+ }, {
73
+ capture: true
74
+ });
48
75
  }
49
76
  }, [
50
77
  onFocusWithin,
51
78
  onFocusWithinChange,
52
- onSyntheticFocus
79
+ onSyntheticFocus,
80
+ addGlobalListener,
81
+ onBlur
53
82
  ]);
54
83
  if (isDisabled) return {
55
84
  focusWithinProps: {
56
- // These should not have been null, that would conflict in mergeProps
85
+ // These cannot be null, that would conflict in mergeProps
57
86
  onFocus: undefined,
58
87
  onBlur: undefined
59
88
  }
@@ -1 +1 @@
1
- {"mappings":";;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;AAyB3G,SAAS,0CAAe,KAAuB;IACpD,IAAI,cACF,UAAU,gBACV,YAAY,iBACZ,aAAa,uBACb,mBAAmB,EACpB,GAAG;IACJ,IAAI,QAAQ,CAAA,GAAA,aAAK,EAAE;QACjB,eAAe;IACjB;IAEA,IAAI,SAAS,CAAA,GAAA,kBAAU,EAAE,CAAC;QACxB,iFAAiF;QACjF,kFAAkF;QAClF,qDAAqD;QACrD,IAAI,MAAM,OAAO,CAAC,aAAa,IAAI,CAAC,AAAC,EAAE,aAAa,CAAa,QAAQ,CAAC,EAAE,aAAa,GAAc;YACrG,MAAM,OAAO,CAAC,aAAa,GAAG;YAE9B,IAAI,cACF,aAAa;YAGf,IAAI,qBACF,oBAAoB;QAExB;IACF,GAAG;QAAC;QAAc;QAAqB;KAAM;IAE7C,IAAI,mBAAmB,CAAA,GAAA,yCAAoB,EAAE;IAC7C,IAAI,UAAU,CAAA,GAAA,kBAAU,EAAE,CAAC;QACzB,kGAAkG;QAClG,oDAAoD;QACpD,IAAI,CAAC,MAAM,OAAO,CAAC,aAAa,IAAI,SAAS,aAAa,KAAK,EAAE,MAAM,EAAE;YACvE,IAAI,eACF,cAAc;YAGhB,IAAI,qBACF,oBAAoB;YAGtB,MAAM,OAAO,CAAC,aAAa,GAAG;YAC9B,iBAAiB;QACnB;IACF,GAAG;QAAC;QAAe;QAAqB;KAAiB;IAEzD,IAAI,YACF,OAAO;QACL,kBAAkB;YAChB,qEAAqE;YACrE,SAAS;YACT,QAAQ;QACV;IACF;IAGF,OAAO;QACL,kBAAkB;qBAChB;oBACA;QACF;IACF;AACF","sources":["packages/@react-aria/interactions/src/useFocusWithin.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 {DOMAttributes} from '@react-types/shared';\nimport {FocusEvent, useCallback, useRef} from 'react';\nimport {useSyntheticBlurEvent} from './utils';\n\nexport interface FocusWithinProps {\n /** Whether the focus within events should be disabled. */\n isDisabled?: boolean,\n /** Handler that is called when the target element or a descendant receives focus. */\n onFocusWithin?: (e: FocusEvent) => void,\n /** Handler that is called when the target element and all descendants lose focus. */\n onBlurWithin?: (e: FocusEvent) => void,\n /** Handler that is called when the the focus within state changes. */\n onFocusWithinChange?: (isFocusWithin: boolean) => void\n}\n\nexport interface FocusWithinResult {\n /** Props to spread onto the target element. */\n focusWithinProps: DOMAttributes\n}\n\n/**\n * Handles focus events for the target and its descendants.\n */\nexport function useFocusWithin(props: FocusWithinProps): FocusWithinResult {\n let {\n isDisabled,\n onBlurWithin,\n onFocusWithin,\n onFocusWithinChange\n } = props;\n let state = useRef({\n isFocusWithin: false\n });\n\n let onBlur = useCallback((e: FocusEvent) => {\n // We don't want to trigger onBlurWithin and then immediately onFocusWithin again\n // when moving focus inside the element. Only trigger if the currentTarget doesn't\n // include the relatedTarget (where focus is moving).\n if (state.current.isFocusWithin && !(e.currentTarget as Element).contains(e.relatedTarget as Element)) {\n state.current.isFocusWithin = false;\n\n if (onBlurWithin) {\n onBlurWithin(e);\n }\n\n if (onFocusWithinChange) {\n onFocusWithinChange(false);\n }\n }\n }, [onBlurWithin, onFocusWithinChange, state]);\n\n let onSyntheticFocus = useSyntheticBlurEvent(onBlur);\n let onFocus = useCallback((e: FocusEvent) => {\n // Double check that document.activeElement actually matches e.target in case a previously chained\n // focus handler already moved focus somewhere else.\n if (!state.current.isFocusWithin && document.activeElement === e.target) {\n if (onFocusWithin) {\n onFocusWithin(e);\n }\n\n if (onFocusWithinChange) {\n onFocusWithinChange(true);\n }\n\n state.current.isFocusWithin = true;\n onSyntheticFocus(e);\n }\n }, [onFocusWithin, onFocusWithinChange, onSyntheticFocus]);\n\n if (isDisabled) {\n return {\n focusWithinProps: {\n // These should not have been null, that would conflict in mergeProps\n onFocus: undefined,\n onBlur: undefined\n }\n };\n }\n\n return {\n focusWithinProps: {\n onFocus,\n onBlur\n }\n };\n}\n"],"names":[],"version":3,"file":"useFocusWithin.module.js.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;YAGtB,MAAM,OAAO,CAAC,aAAa,GAAG;YAC9B,iBAAiB;YAEjB,0EAA0E;YAC1E,0EAA0E;YAC1E,4BAA4B;YAC5B,IAAI,gBAAgB,EAAE,aAAa;YACnC,kBAAkB,eAAe,SAAS,CAAA;gBACxC,IAAI,MAAM,OAAO,CAAC,aAAa,IAAI,CAAC,CAAA,GAAA,mBAAW,EAAE,eAAe,EAAE,MAAM,GAAc;oBACpF,IAAI,QAAQ,IAAI,CAAA,GAAA,yCAAkB,EAAE,QAAQ,IAAI,cAAc,WAAW,CAAE,UAAU,CAAC,QAAQ;wBAAC,eAAe,EAAE,MAAM;oBAAA;oBACtH,MAAM,MAAM,GAAG;oBACf,MAAM,aAAa,GAAG;oBACtB,OAAO;gBACT;YACF,GAAG;gBAAC,SAAS;YAAI;QACnB;IACF,GAAG;QAAC;QAAe;QAAqB;QAAkB;QAAmB;KAAO;IAEpF,IAAI,YACF,OAAO;QACL,kBAAkB;YAChB,0DAA0D;YAC1D,SAAS;YACT,QAAQ;QACV;IACF;IAGF,OAAO;QACL,kBAAkB;qBAChB;oBACA;QACF;IACF;AACF","sources":["packages/@react-aria/interactions/src/useFocusWithin.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 {DOMAttributes} from '@react-types/shared';\nimport {FocusEvent, useCallback, useRef} from 'react';\nimport {getActiveElement, getEventTarget, getOwnerDocument, nodeContains, useGlobalListeners} from '@react-aria/utils';\nimport {SyntheticFocusEvent, useSyntheticBlurEvent} from './utils';\n\nexport interface FocusWithinProps {\n /** Whether the focus within events should be disabled. */\n isDisabled?: boolean,\n /** Handler that is called when the target element or a descendant receives focus. */\n onFocusWithin?: (e: FocusEvent) => void,\n /** Handler that is called when the target element and all descendants lose focus. */\n onBlurWithin?: (e: FocusEvent) => void,\n /** Handler that is called when the the focus within state changes. */\n onFocusWithinChange?: (isFocusWithin: boolean) => void\n}\n\nexport interface FocusWithinResult {\n /** Props to spread onto the target element. */\n focusWithinProps: DOMAttributes\n}\n\n/**\n * Handles focus events for the target and its descendants.\n */\nexport function useFocusWithin(props: FocusWithinProps): FocusWithinResult {\n let {\n isDisabled,\n onBlurWithin,\n onFocusWithin,\n onFocusWithinChange\n } = props;\n let state = useRef({\n isFocusWithin: false\n });\n\n let {addGlobalListener, removeAllGlobalListeners} = useGlobalListeners();\n\n let onBlur = useCallback((e: FocusEvent) => {\n // Ignore events bubbling through portals.\n if (!e.currentTarget.contains(e.target)) {\n return;\n }\n\n // We don't want to trigger onBlurWithin and then immediately onFocusWithin again\n // when moving focus inside the element. Only trigger if the currentTarget doesn't\n // include the relatedTarget (where focus is moving).\n if (state.current.isFocusWithin && !(e.currentTarget as Element).contains(e.relatedTarget as Element)) {\n state.current.isFocusWithin = false;\n removeAllGlobalListeners();\n\n if (onBlurWithin) {\n onBlurWithin(e);\n }\n\n if (onFocusWithinChange) {\n onFocusWithinChange(false);\n }\n }\n }, [onBlurWithin, onFocusWithinChange, state, removeAllGlobalListeners]);\n\n let onSyntheticFocus = useSyntheticBlurEvent(onBlur);\n let onFocus = useCallback((e: FocusEvent) => {\n // Ignore events bubbling through portals.\n if (!e.currentTarget.contains(e.target)) {\n return;\n }\n\n // Double check that document.activeElement actually matches e.target in case a previously chained\n // focus handler already moved focus somewhere else.\n const ownerDocument = getOwnerDocument(e.target);\n const activeElement = getActiveElement(ownerDocument);\n if (!state.current.isFocusWithin && activeElement === getEventTarget(e.nativeEvent)) {\n if (onFocusWithin) {\n onFocusWithin(e);\n }\n\n if (onFocusWithinChange) {\n onFocusWithinChange(true);\n }\n\n state.current.isFocusWithin = true;\n onSyntheticFocus(e);\n\n // Browsers don't fire blur events when elements are removed from the DOM.\n // However, if a focus event occurs outside the element we're tracking, we\n // can manually fire onBlur.\n let currentTarget = e.currentTarget;\n addGlobalListener(ownerDocument, 'focus', e => {\n if (state.current.isFocusWithin && !nodeContains(currentTarget, e.target as Element)) {\n let event = new SyntheticFocusEvent('blur', new ownerDocument.defaultView!.FocusEvent('blur', {relatedTarget: e.target}));\n event.target = currentTarget;\n event.currentTarget = currentTarget;\n onBlur(event);\n }\n }, {capture: true});\n }\n }, [onFocusWithin, onFocusWithinChange, onSyntheticFocus, addGlobalListener, onBlur]);\n\n if (isDisabled) {\n return {\n focusWithinProps: {\n // These cannot be null, that would conflict in mergeProps\n onFocus: undefined,\n onBlur: undefined\n }\n };\n }\n\n return {\n focusWithinProps: {\n onFocus,\n onBlur\n }\n };\n}\n"],"names":[],"version":3,"file":"useFocusWithin.module.js.map"}
@@ -0,0 +1,112 @@
1
+ var $2833058fcd3993f5$exports = require("./focusSafely.main.js");
2
+ var $5cb73d0ce355b0dc$exports = require("./useFocus.main.js");
3
+ var $892d64db2a3c53b0$exports = require("./useKeyboard.main.js");
4
+ var $cvQje$reactariautils = require("@react-aria/utils");
5
+ var $cvQje$react = require("react");
6
+
7
+
8
+ function $parcel$interopDefault(a) {
9
+ return a && a.__esModule ? a.default : a;
10
+ }
11
+
12
+ function $parcel$export(e, n, v, s) {
13
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
14
+ }
15
+
16
+ $parcel$export(module.exports, "FocusableContext", () => $15f8fd80892557ff$export$f9762fab77588ecb);
17
+ $parcel$export(module.exports, "FocusableProvider", () => $15f8fd80892557ff$export$13f3202a3e5ddd5);
18
+ $parcel$export(module.exports, "useFocusable", () => $15f8fd80892557ff$export$4c014de7c8940b4c);
19
+ $parcel$export(module.exports, "Focusable", () => $15f8fd80892557ff$export$35a3bebf7ef2d934);
20
+ /*
21
+ * Copyright 2020 Adobe. All rights reserved.
22
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
23
+ * you may not use this file except in compliance with the License. You may obtain a copy
24
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
25
+ *
26
+ * Unless required by applicable law or agreed to in writing, software distributed under
27
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
28
+ * OF ANY KIND, either express or implied. See the License for the specific language
29
+ * governing permissions and limitations under the License.
30
+ */
31
+
32
+
33
+
34
+
35
+ let $15f8fd80892557ff$export$f9762fab77588ecb = /*#__PURE__*/ (0, ($parcel$interopDefault($cvQje$react))).createContext(null);
36
+ function $15f8fd80892557ff$var$useFocusableContext(ref) {
37
+ let context = (0, $cvQje$react.useContext)($15f8fd80892557ff$export$f9762fab77588ecb) || {};
38
+ (0, $cvQje$reactariautils.useSyncRef)(context, ref);
39
+ // eslint-disable-next-line
40
+ let { ref: _, ...otherProps } = context;
41
+ return otherProps;
42
+ }
43
+ const $15f8fd80892557ff$export$13f3202a3e5ddd5 = /*#__PURE__*/ (0, ($parcel$interopDefault($cvQje$react))).forwardRef(function FocusableProvider(props, ref) {
44
+ let { children: children, ...otherProps } = props;
45
+ let objRef = (0, $cvQje$reactariautils.useObjectRef)(ref);
46
+ let context = {
47
+ ...otherProps,
48
+ ref: objRef
49
+ };
50
+ return /*#__PURE__*/ (0, ($parcel$interopDefault($cvQje$react))).createElement($15f8fd80892557ff$export$f9762fab77588ecb.Provider, {
51
+ value: context
52
+ }, children);
53
+ });
54
+ function $15f8fd80892557ff$export$4c014de7c8940b4c(props, domRef) {
55
+ let { focusProps: focusProps } = (0, $5cb73d0ce355b0dc$exports.useFocus)(props);
56
+ let { keyboardProps: keyboardProps } = (0, $892d64db2a3c53b0$exports.useKeyboard)(props);
57
+ let interactions = (0, $cvQje$reactariautils.mergeProps)(focusProps, keyboardProps);
58
+ let domProps = $15f8fd80892557ff$var$useFocusableContext(domRef);
59
+ let interactionProps = props.isDisabled ? {} : domProps;
60
+ let autoFocusRef = (0, $cvQje$react.useRef)(props.autoFocus);
61
+ (0, $cvQje$react.useEffect)(()=>{
62
+ if (autoFocusRef.current && domRef.current) (0, $2833058fcd3993f5$exports.focusSafely)(domRef.current);
63
+ autoFocusRef.current = false;
64
+ }, [
65
+ domRef
66
+ ]);
67
+ // Always set a tabIndex so that Safari allows focusing native buttons and inputs.
68
+ let tabIndex = props.excludeFromTabOrder ? -1 : 0;
69
+ if (props.isDisabled) tabIndex = undefined;
70
+ return {
71
+ focusableProps: (0, $cvQje$reactariautils.mergeProps)({
72
+ ...interactions,
73
+ tabIndex: tabIndex
74
+ }, interactionProps)
75
+ };
76
+ }
77
+ const $15f8fd80892557ff$export$35a3bebf7ef2d934 = /*#__PURE__*/ (0, $cvQje$react.forwardRef)(({ children: children, ...props }, ref)=>{
78
+ ref = (0, $cvQje$reactariautils.useObjectRef)(ref);
79
+ let { focusableProps: focusableProps } = $15f8fd80892557ff$export$4c014de7c8940b4c(props, ref);
80
+ let child = (0, ($parcel$interopDefault($cvQje$react))).Children.only(children);
81
+ (0, $cvQje$react.useEffect)(()=>{
82
+ let el = ref.current;
83
+ if (!el || !(el instanceof (0, $cvQje$reactariautils.getOwnerWindow)(el).Element)) {
84
+ console.error('<Focusable> child must forward its ref to a DOM element.');
85
+ return;
86
+ }
87
+ if (!props.isDisabled && !(0, $cvQje$reactariautils.isFocusable)(el)) {
88
+ console.warn('<Focusable> child must be focusable. Please ensure the tabIndex prop is passed through.');
89
+ return;
90
+ }
91
+ if (el.localName !== 'button' && el.localName !== 'input' && el.localName !== 'select' && el.localName !== 'textarea' && el.localName !== 'a' && el.localName !== 'area' && el.localName !== 'summary' && el.localName !== 'img' && el.localName !== 'svg') {
92
+ let role = el.getAttribute('role');
93
+ if (!role) console.warn('<Focusable> child must have an interactive ARIA role.');
94
+ else if (// https://w3c.github.io/aria/#widget_roles
95
+ role !== 'application' && role !== 'button' && role !== 'checkbox' && role !== 'combobox' && role !== 'gridcell' && role !== 'link' && role !== 'menuitem' && role !== 'menuitemcheckbox' && role !== 'menuitemradio' && role !== 'option' && role !== 'radio' && role !== 'searchbox' && role !== 'separator' && role !== 'slider' && role !== 'spinbutton' && role !== 'switch' && role !== 'tab' && role !== 'tabpanel' && role !== 'textbox' && role !== 'treeitem' && // aria-describedby is also announced on these roles
96
+ role !== 'img' && role !== 'meter' && role !== 'progressbar') console.warn(`<Focusable> child must have an interactive ARIA role. Got "${role}".`);
97
+ }
98
+ }, [
99
+ ref,
100
+ props.isDisabled
101
+ ]);
102
+ // @ts-ignore
103
+ let childRef = parseInt((0, ($parcel$interopDefault($cvQje$react))).version, 10) < 19 ? child.ref : child.props.ref;
104
+ return /*#__PURE__*/ (0, ($parcel$interopDefault($cvQje$react))).cloneElement(child, {
105
+ ...(0, $cvQje$reactariautils.mergeProps)(focusableProps, child.props),
106
+ // @ts-ignore
107
+ ref: (0, $cvQje$reactariautils.mergeRefs)(childRef, ref)
108
+ });
109
+ });
110
+
111
+
112
+ //# sourceMappingURL=useFocusable.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAyBM,IAAI,0DAAmB,CAAA,GAAA,sCAAI,EAAE,aAAa,CAA+B;AAEhF,SAAS,0CAAoB,GAAuC;IAClE,IAAI,UAAU,CAAA,GAAA,uBAAS,EAAE,8CAAqB,CAAC;IAC/C,CAAA,GAAA,gCAAS,EAAE,SAAS;IAEpB,2BAA2B;IAC3B,IAAI,EAAC,KAAK,CAAC,EAAE,GAAG,YAAW,GAAG;IAC9B,OAAO;AACT;AAKO,MAAM,yDAAoB,CAAA,GAAA,sCAAI,EAAE,UAAU,CAAC,SAAS,kBAAkB,KAA6B,EAAE,GAAmC;IAC7I,IAAI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B;AAEJ","sources":["packages/@react-aria/interactions/src/useFocusable.tsx"],"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 {DOMAttributes, FocusableDOMProps, FocusableElement, FocusableProps, RefObject} from '@react-types/shared';\nimport {focusSafely} from './';\nimport {getOwnerWindow, isFocusable, mergeProps, mergeRefs, useObjectRef, useSyncRef} from '@react-aria/utils';\nimport React, {ForwardedRef, forwardRef, MutableRefObject, ReactElement, ReactNode, useContext, useEffect, useRef} from 'react';\nimport {useFocus} from './useFocus';\nimport {useKeyboard} from './useKeyboard';\n\nexport interface FocusableOptions<T = FocusableElement> extends FocusableProps<T>, FocusableDOMProps {\n /** Whether focus should be disabled. */\n isDisabled?: boolean\n}\n\nexport interface FocusableProviderProps extends DOMAttributes {\n /** The child element to provide DOM props to. */\n children?: ReactNode\n}\n\ninterface FocusableContextValue extends FocusableProviderProps {\n ref?: MutableRefObject<FocusableElement | null>\n}\n\n// Exported for @react-aria/collections, which forwards this context.\n/** @private */\nexport let FocusableContext = React.createContext<FocusableContextValue | null>(null);\n\nfunction useFocusableContext(ref: RefObject<FocusableElement | null>): FocusableContextValue {\n let context = useContext(FocusableContext) || {};\n useSyncRef(context, ref);\n\n // eslint-disable-next-line\n let {ref: _, ...otherProps} = context;\n return otherProps;\n}\n\n/**\n * Provides DOM props to the nearest focusable child.\n */\nexport const FocusableProvider = React.forwardRef(function FocusableProvider(props: FocusableProviderProps, ref: ForwardedRef<FocusableElement>) {\n let {children, ...otherProps} = props;\n let objRef = useObjectRef(ref);\n let context = {\n ...otherProps,\n ref: objRef\n };\n\n return (\n <FocusableContext.Provider value={context}>\n {children}\n </FocusableContext.Provider>\n );\n});\n\nexport interface FocusableAria {\n /** Props for the focusable element. */\n focusableProps: DOMAttributes\n}\n\n/**\n * Used to make an element focusable and capable of auto focus.\n */\nexport function useFocusable<T extends FocusableElement = FocusableElement>(props: FocusableOptions<T>, domRef: RefObject<FocusableElement | null>): FocusableAria {\n let {focusProps} = useFocus(props);\n let {keyboardProps} = useKeyboard(props);\n let interactions = mergeProps(focusProps, keyboardProps);\n let domProps = useFocusableContext(domRef);\n let interactionProps = props.isDisabled ? {} : domProps;\n let autoFocusRef = useRef(props.autoFocus);\n\n useEffect(() => {\n if (autoFocusRef.current && domRef.current) {\n focusSafely(domRef.current);\n }\n autoFocusRef.current = false;\n }, [domRef]);\n\n // Always set a tabIndex so that Safari allows focusing native buttons and inputs.\n let tabIndex: number | undefined = props.excludeFromTabOrder ? -1 : 0;\n if (props.isDisabled) {\n tabIndex = undefined;\n }\n\n return {\n focusableProps: mergeProps(\n {\n ...interactions,\n tabIndex\n },\n interactionProps\n )\n };\n}\n\nexport interface FocusableComponentProps extends FocusableOptions {\n children: ReactElement<DOMAttributes, string>\n}\n\nexport const Focusable = forwardRef(({children, ...props}: FocusableComponentProps, ref: ForwardedRef<FocusableElement>) => {\n ref = useObjectRef(ref);\n let {focusableProps} = useFocusable(props, ref);\n let child = React.Children.only(children);\n\n useEffect(() => {\n let el = ref.current;\n if (!el || !(el instanceof getOwnerWindow(el).Element)) {\n console.error('<Focusable> child must forward its ref to a DOM element.');\n return;\n }\n\n if (!props.isDisabled && !isFocusable(el)) {\n console.warn('<Focusable> child must be focusable. Please ensure the tabIndex prop is passed through.');\n return;\n }\n\n if (\n el.localName !== 'button' &&\n el.localName !== 'input' &&\n el.localName !== 'select' &&\n el.localName !== 'textarea' &&\n el.localName !== 'a' &&\n el.localName !== 'area' &&\n el.localName !== 'summary' &&\n el.localName !== 'img' &&\n el.localName !== 'svg'\n ) {\n let role = el.getAttribute('role');\n if (!role) {\n console.warn('<Focusable> child must have an interactive ARIA role.');\n } else if (\n // https://w3c.github.io/aria/#widget_roles\n role !== 'application' &&\n role !== 'button' &&\n role !== 'checkbox' &&\n role !== 'combobox' &&\n role !== 'gridcell' &&\n role !== 'link' &&\n role !== 'menuitem' &&\n role !== 'menuitemcheckbox' &&\n role !== 'menuitemradio' &&\n role !== 'option' &&\n role !== 'radio' &&\n role !== 'searchbox' &&\n role !== 'separator' &&\n role !== 'slider' &&\n role !== 'spinbutton' &&\n role !== 'switch' &&\n role !== 'tab' &&\n role !== 'tabpanel' &&\n role !== 'textbox' &&\n role !== 'treeitem' &&\n // aria-describedby is also announced on these roles\n role !== 'img' &&\n role !== 'meter' &&\n role !== 'progressbar'\n ) {\n console.warn(`<Focusable> child must have an interactive ARIA role. Got \"${role}\".`);\n }\n }\n }, [ref, props.isDisabled]);\n\n // @ts-ignore\n let childRef = parseInt(React.version, 10) < 19 ? child.ref : child.props.ref;\n\n return React.cloneElement(\n child,\n {\n ...mergeProps(focusableProps, child.props),\n // @ts-ignore\n ref: mergeRefs(childRef, ref)\n }\n );\n});\n"],"names":[],"version":3,"file":"useFocusable.main.js.map"}