@react-aria/interactions 3.23.0 → 3.24.1

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 (84) 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/focusSafely.main.js +40 -0
  7. package/dist/focusSafely.main.js.map +1 -0
  8. package/dist/focusSafely.mjs +35 -0
  9. package/dist/focusSafely.module.js +35 -0
  10. package/dist/focusSafely.module.js.map +1 -0
  11. package/dist/import.mjs +5 -1
  12. package/dist/main.js +9 -0
  13. package/dist/main.js.map +1 -1
  14. package/dist/module.js +5 -1
  15. package/dist/module.js.map +1 -1
  16. package/dist/textSelection.main.js +5 -3
  17. package/dist/textSelection.main.js.map +1 -1
  18. package/dist/textSelection.mjs +5 -3
  19. package/dist/textSelection.module.js +5 -3
  20. package/dist/textSelection.module.js.map +1 -1
  21. package/dist/types.d.ts +59 -25
  22. package/dist/types.d.ts.map +1 -1
  23. package/dist/useFocus.main.js +2 -1
  24. package/dist/useFocus.main.js.map +1 -1
  25. package/dist/useFocus.mjs +3 -2
  26. package/dist/useFocus.module.js +3 -2
  27. package/dist/useFocus.module.js.map +1 -1
  28. package/dist/useFocusVisible.main.js +9 -3
  29. package/dist/useFocusVisible.main.js.map +1 -1
  30. package/dist/useFocusVisible.mjs +9 -3
  31. package/dist/useFocusVisible.module.js +9 -3
  32. package/dist/useFocusVisible.module.js.map +1 -1
  33. package/dist/useFocusWithin.main.js +33 -4
  34. package/dist/useFocusWithin.main.js.map +1 -1
  35. package/dist/useFocusWithin.mjs +34 -5
  36. package/dist/useFocusWithin.module.js +34 -5
  37. package/dist/useFocusWithin.module.js.map +1 -1
  38. package/dist/useFocusable.main.js +112 -0
  39. package/dist/useFocusable.main.js.map +1 -0
  40. package/dist/useFocusable.mjs +100 -0
  41. package/dist/useFocusable.module.js +100 -0
  42. package/dist/useFocusable.module.js.map +1 -0
  43. package/dist/useHover.main.js +18 -3
  44. package/dist/useHover.main.js.map +1 -1
  45. package/dist/useHover.mjs +18 -3
  46. package/dist/useHover.module.js +18 -3
  47. package/dist/useHover.module.js.map +1 -1
  48. package/dist/useInteractOutside.main.js +6 -1
  49. package/dist/useInteractOutside.main.js.map +1 -1
  50. package/dist/useInteractOutside.mjs +6 -1
  51. package/dist/useInteractOutside.module.js +6 -1
  52. package/dist/useInteractOutside.module.js.map +1 -1
  53. package/dist/useLongPress.main.js +2 -0
  54. package/dist/useLongPress.main.js.map +1 -1
  55. package/dist/useLongPress.mjs +3 -1
  56. package/dist/useLongPress.module.js +3 -1
  57. package/dist/useLongPress.module.js.map +1 -1
  58. package/dist/usePress.main.js +85 -80
  59. package/dist/usePress.main.js.map +1 -1
  60. package/dist/usePress.mjs +86 -81
  61. package/dist/usePress.module.js +86 -81
  62. package/dist/usePress.module.js.map +1 -1
  63. package/dist/utils.main.js +57 -1
  64. package/dist/utils.main.js.map +1 -1
  65. package/dist/utils.mjs +55 -2
  66. package/dist/utils.module.js +55 -2
  67. package/dist/utils.module.js.map +1 -1
  68. package/package.json +5 -4
  69. package/src/Pressable.tsx +66 -6
  70. package/src/focusSafely.ts +45 -0
  71. package/src/index.ts +3 -0
  72. package/src/textSelection.ts +6 -4
  73. package/src/useFocus.ts +3 -3
  74. package/src/useFocusVisible.ts +14 -4
  75. package/src/useFocusWithin.ts +34 -5
  76. package/src/useFocusable.tsx +183 -0
  77. package/src/useHover.ts +17 -3
  78. package/src/useInteractOutside.ts +9 -3
  79. package/src/useLongPress.ts +8 -2
  80. package/src/usePress.ts +117 -115
  81. package/src/utils.ts +80 -1
  82. package/src/DOMPropsContext.ts +0 -39
  83. package/src/DOMPropsResponder.tsx +0 -47
  84. package/src/useDOMPropsResponder.ts +0 -27
package/dist/types.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { DOMAttributes, PressEvents, RefObject, FocusableElement, FocusEvents, HoverEvents, KeyboardEvents, MoveEvents, ScrollEvents, LongPressEvent } from "@react-types/shared";
2
- import React, { ReactElement, ReactNode, FocusEvent } from "react";
1
+ import { DOMAttributes, PressEvents, RefObject, FocusableElement, FocusEvents, KeyboardEvents, FocusableDOMProps, FocusableProps, HoverEvents, MoveEvents, ScrollEvents, LongPressEvent } from "@react-types/shared";
2
+ import React, { MutableRefObject, ReactElement, ReactNode, FocusEvent } from "react";
3
3
  export interface PressProps extends PressEvents {
4
4
  /** Whether the target is in a controlled press state (e.g. an overlay it triggers is open). */
5
5
  isPressed?: boolean;
@@ -33,17 +33,6 @@ export interface PressResult {
33
33
  * of dealing with pointer and keyboard events.
34
34
  */
35
35
  export function usePress(props: PressHookProps): PressResult;
36
- interface PressableProps extends PressProps {
37
- children: ReactElement<DOMAttributes, string>;
38
- }
39
- export const Pressable: React.ForwardRefExoticComponent<PressableProps & React.RefAttributes<HTMLElement>>;
40
- interface PressResponderProps extends PressProps {
41
- children: ReactNode;
42
- }
43
- export const PressResponder: React.ForwardRefExoticComponent<PressResponderProps & React.RefAttributes<FocusableElement>>;
44
- export function ClearPressResponder({ children }: {
45
- children: ReactNode;
46
- }): React.JSX.Element;
47
36
  export interface FocusProps<Target = FocusableElement> extends FocusEvents<Target> {
48
37
  /** Whether the focus events should be disabled. */
49
38
  isDisabled?: boolean;
@@ -57,6 +46,58 @@ export interface FocusResult<Target = FocusableElement> {
57
46
  * Focus events on child elements will be ignored.
58
47
  */
59
48
  export function useFocus<Target extends FocusableElement = FocusableElement>(props: FocusProps<Target>): FocusResult<Target>;
49
+ export interface KeyboardProps extends KeyboardEvents {
50
+ /** Whether the keyboard events should be disabled. */
51
+ isDisabled?: boolean;
52
+ }
53
+ export interface KeyboardResult {
54
+ /** Props to spread onto the target element. */
55
+ keyboardProps: DOMAttributes;
56
+ }
57
+ /**
58
+ * Handles keyboard interactions for a focusable element.
59
+ */
60
+ export function useKeyboard(props: KeyboardProps): KeyboardResult;
61
+ export interface FocusableOptions<T = FocusableElement> extends FocusableProps<T>, FocusableDOMProps {
62
+ /** Whether focus should be disabled. */
63
+ isDisabled?: boolean;
64
+ }
65
+ export interface FocusableProviderProps extends DOMAttributes {
66
+ /** The child element to provide DOM props to. */
67
+ children?: ReactNode;
68
+ }
69
+ interface FocusableContextValue extends FocusableProviderProps {
70
+ ref?: MutableRefObject<FocusableElement | null>;
71
+ }
72
+ /** @private */
73
+ export let FocusableContext: React.Context<FocusableContextValue | null>;
74
+ /**
75
+ * Provides DOM props to the nearest focusable child.
76
+ */
77
+ export const FocusableProvider: React.ForwardRefExoticComponent<FocusableProviderProps & React.RefAttributes<FocusableElement>>;
78
+ export interface FocusableAria {
79
+ /** Props for the focusable element. */
80
+ focusableProps: DOMAttributes;
81
+ }
82
+ /**
83
+ * Used to make an element focusable and capable of auto focus.
84
+ */
85
+ export function useFocusable<T extends FocusableElement = FocusableElement>(props: FocusableOptions<T>, domRef: RefObject<FocusableElement | null>): FocusableAria;
86
+ interface FocusableComponentProps extends FocusableOptions {
87
+ children: ReactElement<DOMAttributes, string>;
88
+ }
89
+ export const Focusable: React.ForwardRefExoticComponent<FocusableComponentProps & React.RefAttributes<FocusableElement>>;
90
+ interface PressableProps extends PressProps {
91
+ children: ReactElement<DOMAttributes, string>;
92
+ }
93
+ export const Pressable: React.ForwardRefExoticComponent<PressableProps & React.RefAttributes<FocusableElement>>;
94
+ interface PressResponderProps extends PressProps {
95
+ children: ReactNode;
96
+ }
97
+ export const PressResponder: React.ForwardRefExoticComponent<PressResponderProps & React.RefAttributes<FocusableElement>>;
98
+ export function ClearPressResponder({ children }: {
99
+ children: ReactNode;
100
+ }): React.JSX.Element;
60
101
  export type Modality = 'keyboard' | 'pointer' | 'virtual';
61
102
  export type FocusVisibleHandler = (isFocusVisible: boolean) => void;
62
103
  export interface FocusVisibleProps {
@@ -151,18 +192,6 @@ export interface InteractOutsideProps {
151
192
  * when a user clicks outside them.
152
193
  */
153
194
  export function useInteractOutside(props: InteractOutsideProps): void;
154
- export interface KeyboardProps extends KeyboardEvents {
155
- /** Whether the keyboard events should be disabled. */
156
- isDisabled?: boolean;
157
- }
158
- export interface KeyboardResult {
159
- /** Props to spread onto the target element. */
160
- keyboardProps: DOMAttributes;
161
- }
162
- /**
163
- * Handles keyboard interactions for a focusable element.
164
- */
165
- export function useKeyboard(props: KeyboardProps): KeyboardResult;
166
195
  export interface MoveResult {
167
196
  /** Props to spread on the target element. */
168
197
  moveProps: DOMAttributes;
@@ -213,6 +242,11 @@ export interface LongPressResult {
213
242
  * accessibility description, and normalizes behavior across browsers and devices.
214
243
  */
215
244
  export function useLongPress(props: LongPressProps): LongPressResult;
245
+ /**
246
+ * A utility function that focuses an element while avoiding undesired side effects such
247
+ * as page scrolling and screen reader issues with CSS transitions.
248
+ */
249
+ export function focusSafely(element: FocusableElement): void;
216
250
  export type { PressEvent, PressEvents, MoveStartEvent, MoveMoveEvent, MoveEndEvent, MoveEvents, HoverEvent, HoverEvents, FocusEvents, KeyboardEvents } from '@react-types/shared';
217
251
 
218
252
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"mappings":";;AEuBA,2BAA4B,SAAQ,WAAW;IAC7C,+FAA+F;IAC/F,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,mDAAmD;IACnD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,4DAA4D;IAC5D,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;;;OAKG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,yEAAyE;IACzE,yBAAyB,CAAC,EAAE,OAAO,CAAA;CACpC;AAED,+BAAgC,SAAQ,UAAU;IAChD,mCAAmC;IACnC,GAAG,CAAC,EAAE,UAAU,OAAO,GAAG,IAAI,CAAC,CAAA;CAChC;AA2BD;IACE,+CAA+C;IAC/C,SAAS,EAAE,OAAO,CAAC;IACnB,6CAA6C;IAC7C,UAAU,EAAE,aAAa,CAAA;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AM,qBAAqB,CAAC","sources":["packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/textSelection.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/context.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/usePress.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/Pressable.tsx","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/PressResponder.tsx","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/utils.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useFocus.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useFocusVisible.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useFocusWithin.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useHover.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useInteractOutside.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/createEventHandler.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useKeyboard.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useMove.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useScrollWheel.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useLongPress.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/index.ts","packages/@react-aria/interactions/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,"/*\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\nexport {Pressable} from './Pressable';\nexport {PressResponder, ClearPressResponder} from './PressResponder';\nexport {useFocus} from './useFocus';\nexport {\n isFocusVisible,\n getInteractionModality,\n setInteractionModality,\n addWindowFocusTracking,\n useInteractionModality,\n useFocusVisible,\n useFocusVisibleListener\n} from './useFocusVisible';\nexport {useFocusWithin} from './useFocusWithin';\nexport {useHover} from './useHover';\nexport {useInteractOutside} from './useInteractOutside';\nexport {useKeyboard} from './useKeyboard';\nexport {useMove} from './useMove';\nexport {usePress} from './usePress';\nexport {useScrollWheel} from './useScrollWheel';\nexport {useLongPress} from './useLongPress';\n\nexport type {FocusProps, FocusResult} from './useFocus';\nexport type {FocusVisibleHandler, FocusVisibleProps, FocusVisibleResult, Modality} from './useFocusVisible';\nexport type {FocusWithinProps, FocusWithinResult} from './useFocusWithin';\nexport type {HoverProps, HoverResult} from './useHover';\nexport type {InteractOutsideProps} from './useInteractOutside';\nexport type {KeyboardProps, KeyboardResult} from './useKeyboard';\nexport type {PressProps, PressHookProps, PressResult} from './usePress';\nexport type {PressEvent, PressEvents, MoveStartEvent, MoveMoveEvent, MoveEndEvent, MoveEvents, HoverEvent, HoverEvents, FocusEvents, KeyboardEvents} from '@react-types/shared';\nexport type {MoveResult} from './useMove';\nexport type {LongPressProps, LongPressResult} from './useLongPress';\nexport type {ScrollWheelProps} from './useScrollWheel';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":";;AGwCA,2BAA4B,SAAQ,WAAW;IAC7C,+FAA+F;IAC/F,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,mDAAmD;IACnD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,4DAA4D;IAC5D,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;;;;OAKG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;IACpC,yEAAyE;IACzE,yBAAyB,CAAC,EAAE,OAAO,CAAA;CACpC;AAED,+BAAgC,SAAQ,UAAU;IAChD,mCAAmC;IACnC,GAAG,CAAC,EAAE,UAAU,OAAO,GAAG,IAAI,CAAC,CAAA;C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CAoMrD;ACtND,iCAAkC,SAAQ,YAAY;IACpD,sDAAsD;IACtD,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAGD,+BAA+B,KAAK,EAAE,gBAAgB,EAAE,GAAG,EAAE,UAAU,WAAW,GAAG,IAAI,CAAC,GAAG,IAAI,CAkBhG;ACvBD;IACE,oDAAoD;IACpD,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,mEAAmE;IACnE,gBAAgB,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,KAAK,IAAI,CAAC;IAC/C;;;OAGG;IACH,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,KAAK,IAAI,CAAC;IAC7C;;;OAGG;IACH,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,KAAK,IAAI,CAAC;IAC1C;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAA;CAClC;AAED;IACE,6CAA6C;IAC7C,cAAc,EAAE,aAAa,CAAA;CAC9B;AAID;;;GAGG;AACH,6BAA6B,KAAK,EAAE,cAAc,GAAG,eAAe,CA+EnE;ACjHD;;;GAGG;AACH,4BAA4B,OAAO,EAAE,gBAAgB,QAmBpD;ACFD,YAAY,EAAC,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAC,MAAM,qBAAqB,CAAC","sources":["packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/textSelection.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/context.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/utils.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/usePress.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useFocus.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/createEventHandler.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useKeyboard.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useFocusable.tsx","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/Pressable.tsx","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/PressResponder.tsx","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useFocusVisible.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useFocusWithin.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useHover.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useInteractOutside.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useMove.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useScrollWheel.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useLongPress.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/focusSafely.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/index.ts","packages/@react-aria/interactions/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,"/*\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\nexport {Pressable} from './Pressable';\nexport {PressResponder, ClearPressResponder} from './PressResponder';\nexport {useFocus} from './useFocus';\nexport {\n isFocusVisible,\n getInteractionModality,\n setInteractionModality,\n addWindowFocusTracking,\n useInteractionModality,\n useFocusVisible,\n useFocusVisibleListener\n} from './useFocusVisible';\nexport {useFocusWithin} from './useFocusWithin';\nexport {useHover} from './useHover';\nexport {useInteractOutside} from './useInteractOutside';\nexport {useKeyboard} from './useKeyboard';\nexport {useMove} from './useMove';\nexport {usePress} from './usePress';\nexport {useScrollWheel} from './useScrollWheel';\nexport {useLongPress} from './useLongPress';\nexport {useFocusable, FocusableProvider, Focusable, FocusableContext} from './useFocusable';\nexport {focusSafely} from './focusSafely';\n\nexport type {FocusProps, FocusResult} from './useFocus';\nexport type {FocusVisibleHandler, FocusVisibleProps, FocusVisibleResult, Modality} from './useFocusVisible';\nexport type {FocusWithinProps, FocusWithinResult} from './useFocusWithin';\nexport type {HoverProps, HoverResult} from './useHover';\nexport type {InteractOutsideProps} from './useInteractOutside';\nexport type {KeyboardProps, KeyboardResult} from './useKeyboard';\nexport type {PressProps, PressHookProps, PressResult} from './usePress';\nexport type {PressEvent, PressEvents, MoveStartEvent, MoveMoveEvent, MoveEndEvent, MoveEvents, HoverEvent, HoverEvents, FocusEvents, KeyboardEvents} from '@react-types/shared';\nexport type {MoveResult} from './useMove';\nexport type {LongPressProps, LongPressResult} from './useLongPress';\nexport type {ScrollWheelProps} from './useScrollWheel';\nexport type {FocusableAria, FocusableOptions, FocusableProviderProps} from './useFocusable';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -42,7 +42,8 @@ function $5cb73d0ce355b0dc$export$f8168d8dd8fd66e6(props) {
42
42
  // Double check that document.activeElement actually matches e.target in case a previously chained
43
43
  // focus handler already moved focus somewhere else.
44
44
  const ownerDocument = (0, $hrHul$reactariautils.getOwnerDocument)(e.target);
45
- if (e.target === e.currentTarget && ownerDocument.activeElement === e.target) {
45
+ const activeElement = ownerDocument ? (0, $hrHul$reactariautils.getActiveElement)(ownerDocument) : (0, $hrHul$reactariautils.getActiveElement)();
46
+ if (e.target === e.currentTarget && activeElement === (0, $hrHul$reactariautils.getEventTarget)(e.nativeEvent)) {
46
47
  if (onFocusProp) onFocusProp(e);
47
48
  if (onFocusChange) onFocusChange(true);
48
49
  onSyntheticFocus(e);
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;;AAqB3G,SAAS,0CAA6D,KAAyB;IACpG,IAAI,cACF,UAAU,EACV,SAAS,WAAW,EACpB,QAAQ,UAAU,iBAClB,aAAa,EACd,GAAG;IAEJ,MAAM,SAAuC,CAAA,GAAA,wBAAU,EAAE,CAAC;QACxD,IAAI,EAAE,MAAM,KAAK,EAAE,aAAa,EAAE;YAChC,IAAI,YACF,WAAW;YAGb,IAAI,eACF,cAAc;YAGhB,OAAO;QACT;IACF,GAAG;QAAC;QAAY;KAAc;IAG9B,MAAM,mBAAmB,CAAA,GAAA,+CAAoB,EAAU;IAEvD,MAAM,UAAyC,CAAA,GAAA,wBAAU,EAAE,CAAC;QAC1D,kGAAkG;QAClG,oDAAoD;QAEpD,MAAM,gBAAgB,CAAA,GAAA,sCAAe,EAAE,EAAE,MAAM;QAE/C,IAAI,EAAE,MAAM,KAAK,EAAE,aAAa,IAAI,cAAc,aAAa,KAAK,EAAE,MAAM,EAAE;YAC5E,IAAI,aACF,YAAY;YAGd,IAAI,eACF,cAAc;YAGhB,iBAAiB;QACnB;IACF,GAAG;QAAC;QAAe;QAAa;KAAiB;IAEjD,OAAO;QACL,YAAY;YACV,SAAS,AAAC,CAAC,cAAe,CAAA,eAAe,iBAAiB,UAAS,IAAM,UAAU;YACnF,QAAQ,AAAC,CAAC,cAAe,CAAA,cAAc,aAAY,IAAM,SAAS;QACpE;IACF;AACF","sources":["packages/@react-aria/interactions/src/useFocus.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, FocusableElement, FocusEvents} from '@react-types/shared';\nimport {FocusEvent, useCallback} from 'react';\nimport {getOwnerDocument} from '@react-aria/utils';\nimport {useSyntheticBlurEvent} from './utils';\n\nexport interface FocusProps<Target = FocusableElement> extends FocusEvents<Target> {\n /** Whether the focus events should be disabled. */\n isDisabled?: boolean\n}\n\nexport interface FocusResult<Target = FocusableElement> {\n /** Props to spread onto the target element. */\n focusProps: DOMAttributes<Target>\n}\n\n/**\n * Handles focus events for the immediate target.\n * Focus events on child elements will be ignored.\n */\nexport function useFocus<Target extends FocusableElement = FocusableElement>(props: FocusProps<Target>): FocusResult<Target> {\n let {\n isDisabled,\n onFocus: onFocusProp,\n onBlur: onBlurProp,\n onFocusChange\n } = props;\n\n const onBlur: FocusProps<Target>['onBlur'] = useCallback((e: FocusEvent<Target>) => {\n if (e.target === e.currentTarget) {\n if (onBlurProp) {\n onBlurProp(e);\n }\n\n if (onFocusChange) {\n onFocusChange(false);\n }\n\n return true;\n }\n }, [onBlurProp, onFocusChange]);\n\n\n const onSyntheticFocus = useSyntheticBlurEvent<Target>(onBlur);\n\n const onFocus: FocusProps<Target>['onFocus'] = useCallback((e: FocusEvent<Target>) => {\n // Double check that document.activeElement actually matches e.target in case a previously chained\n // focus handler already moved focus somewhere else.\n\n const ownerDocument = getOwnerDocument(e.target);\n\n if (e.target === e.currentTarget && ownerDocument.activeElement === e.target) {\n if (onFocusProp) {\n onFocusProp(e);\n }\n\n if (onFocusChange) {\n onFocusChange(true);\n }\n\n onSyntheticFocus(e);\n }\n }, [onFocusChange, onFocusProp, onSyntheticFocus]);\n\n return {\n focusProps: {\n onFocus: (!isDisabled && (onFocusProp || onFocusChange || onBlurProp)) ? onFocus : undefined,\n onBlur: (!isDisabled && (onBlurProp || onFocusChange)) ? onBlur : undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"useFocus.main.js.map"}
1
+ {"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;;AAqB3G,SAAS,0CAA6D,KAAyB;IACpG,IAAI,cACF,UAAU,EACV,SAAS,WAAW,EACpB,QAAQ,UAAU,iBAClB,aAAa,EACd,GAAG;IAEJ,MAAM,SAAuC,CAAA,GAAA,wBAAU,EAAE,CAAC;QACxD,IAAI,EAAE,MAAM,KAAK,EAAE,aAAa,EAAE;YAChC,IAAI,YACF,WAAW;YAGb,IAAI,eACF,cAAc;YAGhB,OAAO;QACT;IACF,GAAG;QAAC;QAAY;KAAc;IAG9B,MAAM,mBAAmB,CAAA,GAAA,+CAAoB,EAAU;IAEvD,MAAM,UAAyC,CAAA,GAAA,wBAAU,EAAE,CAAC;QAC1D,kGAAkG;QAClG,oDAAoD;QAEpD,MAAM,gBAAgB,CAAA,GAAA,sCAAe,EAAE,EAAE,MAAM;QAC/C,MAAM,gBAAgB,gBAAgB,CAAA,GAAA,sCAAe,EAAE,iBAAiB,CAAA,GAAA,sCAAe;QACvF,IAAI,EAAE,MAAM,KAAK,EAAE,aAAa,IAAI,kBAAkB,CAAA,GAAA,oCAAa,EAAE,EAAE,WAAW,GAAG;YACnF,IAAI,aACF,YAAY;YAGd,IAAI,eACF,cAAc;YAGhB,iBAAiB;QACnB;IACF,GAAG;QAAC;QAAe;QAAa;KAAiB;IAEjD,OAAO;QACL,YAAY;YACV,SAAS,AAAC,CAAC,cAAe,CAAA,eAAe,iBAAiB,UAAS,IAAM,UAAU;YACnF,QAAQ,AAAC,CAAC,cAAe,CAAA,cAAc,aAAY,IAAM,SAAS;QACpE;IACF;AACF","sources":["packages/@react-aria/interactions/src/useFocus.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, FocusableElement, FocusEvents} from '@react-types/shared';\nimport {FocusEvent, useCallback} from 'react';\nimport {getActiveElement, getEventTarget, getOwnerDocument} from '@react-aria/utils';\nimport {useSyntheticBlurEvent} from './utils';\n\nexport interface FocusProps<Target = FocusableElement> extends FocusEvents<Target> {\n /** Whether the focus events should be disabled. */\n isDisabled?: boolean\n}\n\nexport interface FocusResult<Target = FocusableElement> {\n /** Props to spread onto the target element. */\n focusProps: DOMAttributes<Target>\n}\n\n/**\n * Handles focus events for the immediate target.\n * Focus events on child elements will be ignored.\n */\nexport function useFocus<Target extends FocusableElement = FocusableElement>(props: FocusProps<Target>): FocusResult<Target> {\n let {\n isDisabled,\n onFocus: onFocusProp,\n onBlur: onBlurProp,\n onFocusChange\n } = props;\n\n const onBlur: FocusProps<Target>['onBlur'] = useCallback((e: FocusEvent<Target>) => {\n if (e.target === e.currentTarget) {\n if (onBlurProp) {\n onBlurProp(e);\n }\n\n if (onFocusChange) {\n onFocusChange(false);\n }\n\n return true;\n }\n }, [onBlurProp, onFocusChange]);\n\n\n const onSyntheticFocus = useSyntheticBlurEvent<Target>(onBlur);\n\n const onFocus: FocusProps<Target>['onFocus'] = useCallback((e: FocusEvent<Target>) => {\n // Double check that document.activeElement actually matches e.target in case a previously chained\n // focus handler already moved focus somewhere else.\n\n const ownerDocument = getOwnerDocument(e.target);\n const activeElement = ownerDocument ? getActiveElement(ownerDocument) : getActiveElement();\n if (e.target === e.currentTarget && activeElement === getEventTarget(e.nativeEvent)) {\n if (onFocusProp) {\n onFocusProp(e);\n }\n\n if (onFocusChange) {\n onFocusChange(true);\n }\n\n onSyntheticFocus(e);\n }\n }, [onFocusChange, onFocusProp, onSyntheticFocus]);\n\n return {\n focusProps: {\n onFocus: (!isDisabled && (onFocusProp || onFocusChange || onBlurProp)) ? onFocus : undefined,\n onBlur: (!isDisabled && (onBlurProp || onFocusChange)) ? onBlur : undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"useFocus.main.js.map"}
package/dist/useFocus.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {useSyntheticBlurEvent as $8a9cb279dc87e130$export$715c682d09d639cc} from "./utils.mjs";
2
2
  import {useCallback as $hf0lj$useCallback} from "react";
3
- import {getOwnerDocument as $hf0lj$getOwnerDocument} from "@react-aria/utils";
3
+ import {getOwnerDocument as $hf0lj$getOwnerDocument, getActiveElement as $hf0lj$getActiveElement, getEventTarget as $hf0lj$getEventTarget} from "@react-aria/utils";
4
4
 
5
5
  /*
6
6
  * Copyright 2020 Adobe. All rights reserved.
@@ -36,7 +36,8 @@ function $a1ea59d68270f0dd$export$f8168d8dd8fd66e6(props) {
36
36
  // Double check that document.activeElement actually matches e.target in case a previously chained
37
37
  // focus handler already moved focus somewhere else.
38
38
  const ownerDocument = (0, $hf0lj$getOwnerDocument)(e.target);
39
- if (e.target === e.currentTarget && ownerDocument.activeElement === e.target) {
39
+ const activeElement = ownerDocument ? (0, $hf0lj$getActiveElement)(ownerDocument) : (0, $hf0lj$getActiveElement)();
40
+ if (e.target === e.currentTarget && activeElement === (0, $hf0lj$getEventTarget)(e.nativeEvent)) {
40
41
  if (onFocusProp) onFocusProp(e);
41
42
  if (onFocusChange) onFocusChange(true);
42
43
  onSyntheticFocus(e);
@@ -1,6 +1,6 @@
1
1
  import {useSyntheticBlurEvent as $8a9cb279dc87e130$export$715c682d09d639cc} from "./utils.module.js";
2
2
  import {useCallback as $hf0lj$useCallback} from "react";
3
- import {getOwnerDocument as $hf0lj$getOwnerDocument} from "@react-aria/utils";
3
+ import {getOwnerDocument as $hf0lj$getOwnerDocument, getActiveElement as $hf0lj$getActiveElement, getEventTarget as $hf0lj$getEventTarget} from "@react-aria/utils";
4
4
 
5
5
  /*
6
6
  * Copyright 2020 Adobe. All rights reserved.
@@ -36,7 +36,8 @@ function $a1ea59d68270f0dd$export$f8168d8dd8fd66e6(props) {
36
36
  // Double check that document.activeElement actually matches e.target in case a previously chained
37
37
  // focus handler already moved focus somewhere else.
38
38
  const ownerDocument = (0, $hf0lj$getOwnerDocument)(e.target);
39
- if (e.target === e.currentTarget && ownerDocument.activeElement === e.target) {
39
+ const activeElement = ownerDocument ? (0, $hf0lj$getActiveElement)(ownerDocument) : (0, $hf0lj$getActiveElement)();
40
+ if (e.target === e.currentTarget && activeElement === (0, $hf0lj$getEventTarget)(e.nativeEvent)) {
40
41
  if (onFocusProp) onFocusProp(e);
41
42
  if (onFocusChange) onFocusChange(true);
42
43
  onSyntheticFocus(e);
@@ -1 +1 @@
1
- {"mappings":";;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;;AAqB3G,SAAS,0CAA6D,KAAyB;IACpG,IAAI,cACF,UAAU,EACV,SAAS,WAAW,EACpB,QAAQ,UAAU,iBAClB,aAAa,EACd,GAAG;IAEJ,MAAM,SAAuC,CAAA,GAAA,kBAAU,EAAE,CAAC;QACxD,IAAI,EAAE,MAAM,KAAK,EAAE,aAAa,EAAE;YAChC,IAAI,YACF,WAAW;YAGb,IAAI,eACF,cAAc;YAGhB,OAAO;QACT;IACF,GAAG;QAAC;QAAY;KAAc;IAG9B,MAAM,mBAAmB,CAAA,GAAA,yCAAoB,EAAU;IAEvD,MAAM,UAAyC,CAAA,GAAA,kBAAU,EAAE,CAAC;QAC1D,kGAAkG;QAClG,oDAAoD;QAEpD,MAAM,gBAAgB,CAAA,GAAA,uBAAe,EAAE,EAAE,MAAM;QAE/C,IAAI,EAAE,MAAM,KAAK,EAAE,aAAa,IAAI,cAAc,aAAa,KAAK,EAAE,MAAM,EAAE;YAC5E,IAAI,aACF,YAAY;YAGd,IAAI,eACF,cAAc;YAGhB,iBAAiB;QACnB;IACF,GAAG;QAAC;QAAe;QAAa;KAAiB;IAEjD,OAAO;QACL,YAAY;YACV,SAAS,AAAC,CAAC,cAAe,CAAA,eAAe,iBAAiB,UAAS,IAAM,UAAU;YACnF,QAAQ,AAAC,CAAC,cAAe,CAAA,cAAc,aAAY,IAAM,SAAS;QACpE;IACF;AACF","sources":["packages/@react-aria/interactions/src/useFocus.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, FocusableElement, FocusEvents} from '@react-types/shared';\nimport {FocusEvent, useCallback} from 'react';\nimport {getOwnerDocument} from '@react-aria/utils';\nimport {useSyntheticBlurEvent} from './utils';\n\nexport interface FocusProps<Target = FocusableElement> extends FocusEvents<Target> {\n /** Whether the focus events should be disabled. */\n isDisabled?: boolean\n}\n\nexport interface FocusResult<Target = FocusableElement> {\n /** Props to spread onto the target element. */\n focusProps: DOMAttributes<Target>\n}\n\n/**\n * Handles focus events for the immediate target.\n * Focus events on child elements will be ignored.\n */\nexport function useFocus<Target extends FocusableElement = FocusableElement>(props: FocusProps<Target>): FocusResult<Target> {\n let {\n isDisabled,\n onFocus: onFocusProp,\n onBlur: onBlurProp,\n onFocusChange\n } = props;\n\n const onBlur: FocusProps<Target>['onBlur'] = useCallback((e: FocusEvent<Target>) => {\n if (e.target === e.currentTarget) {\n if (onBlurProp) {\n onBlurProp(e);\n }\n\n if (onFocusChange) {\n onFocusChange(false);\n }\n\n return true;\n }\n }, [onBlurProp, onFocusChange]);\n\n\n const onSyntheticFocus = useSyntheticBlurEvent<Target>(onBlur);\n\n const onFocus: FocusProps<Target>['onFocus'] = useCallback((e: FocusEvent<Target>) => {\n // Double check that document.activeElement actually matches e.target in case a previously chained\n // focus handler already moved focus somewhere else.\n\n const ownerDocument = getOwnerDocument(e.target);\n\n if (e.target === e.currentTarget && ownerDocument.activeElement === e.target) {\n if (onFocusProp) {\n onFocusProp(e);\n }\n\n if (onFocusChange) {\n onFocusChange(true);\n }\n\n onSyntheticFocus(e);\n }\n }, [onFocusChange, onFocusProp, onSyntheticFocus]);\n\n return {\n focusProps: {\n onFocus: (!isDisabled && (onFocusProp || onFocusChange || onBlurProp)) ? onFocus : undefined,\n onBlur: (!isDisabled && (onBlurProp || onFocusChange)) ? onBlur : undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"useFocus.module.js.map"}
1
+ {"mappings":";;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;;AAqB3G,SAAS,0CAA6D,KAAyB;IACpG,IAAI,cACF,UAAU,EACV,SAAS,WAAW,EACpB,QAAQ,UAAU,iBAClB,aAAa,EACd,GAAG;IAEJ,MAAM,SAAuC,CAAA,GAAA,kBAAU,EAAE,CAAC;QACxD,IAAI,EAAE,MAAM,KAAK,EAAE,aAAa,EAAE;YAChC,IAAI,YACF,WAAW;YAGb,IAAI,eACF,cAAc;YAGhB,OAAO;QACT;IACF,GAAG;QAAC;QAAY;KAAc;IAG9B,MAAM,mBAAmB,CAAA,GAAA,yCAAoB,EAAU;IAEvD,MAAM,UAAyC,CAAA,GAAA,kBAAU,EAAE,CAAC;QAC1D,kGAAkG;QAClG,oDAAoD;QAEpD,MAAM,gBAAgB,CAAA,GAAA,uBAAe,EAAE,EAAE,MAAM;QAC/C,MAAM,gBAAgB,gBAAgB,CAAA,GAAA,uBAAe,EAAE,iBAAiB,CAAA,GAAA,uBAAe;QACvF,IAAI,EAAE,MAAM,KAAK,EAAE,aAAa,IAAI,kBAAkB,CAAA,GAAA,qBAAa,EAAE,EAAE,WAAW,GAAG;YACnF,IAAI,aACF,YAAY;YAGd,IAAI,eACF,cAAc;YAGhB,iBAAiB;QACnB;IACF,GAAG;QAAC;QAAe;QAAa;KAAiB;IAEjD,OAAO;QACL,YAAY;YACV,SAAS,AAAC,CAAC,cAAe,CAAA,eAAe,iBAAiB,UAAS,IAAM,UAAU;YACnF,QAAQ,AAAC,CAAC,cAAe,CAAA,cAAc,aAAY,IAAM,SAAS;QACpE;IACF;AACF","sources":["packages/@react-aria/interactions/src/useFocus.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, FocusableElement, FocusEvents} from '@react-types/shared';\nimport {FocusEvent, useCallback} from 'react';\nimport {getActiveElement, getEventTarget, getOwnerDocument} from '@react-aria/utils';\nimport {useSyntheticBlurEvent} from './utils';\n\nexport interface FocusProps<Target = FocusableElement> extends FocusEvents<Target> {\n /** Whether the focus events should be disabled. */\n isDisabled?: boolean\n}\n\nexport interface FocusResult<Target = FocusableElement> {\n /** Props to spread onto the target element. */\n focusProps: DOMAttributes<Target>\n}\n\n/**\n * Handles focus events for the immediate target.\n * Focus events on child elements will be ignored.\n */\nexport function useFocus<Target extends FocusableElement = FocusableElement>(props: FocusProps<Target>): FocusResult<Target> {\n let {\n isDisabled,\n onFocus: onFocusProp,\n onBlur: onBlurProp,\n onFocusChange\n } = props;\n\n const onBlur: FocusProps<Target>['onBlur'] = useCallback((e: FocusEvent<Target>) => {\n if (e.target === e.currentTarget) {\n if (onBlurProp) {\n onBlurProp(e);\n }\n\n if (onFocusChange) {\n onFocusChange(false);\n }\n\n return true;\n }\n }, [onBlurProp, onFocusChange]);\n\n\n const onSyntheticFocus = useSyntheticBlurEvent<Target>(onBlur);\n\n const onFocus: FocusProps<Target>['onFocus'] = useCallback((e: FocusEvent<Target>) => {\n // Double check that document.activeElement actually matches e.target in case a previously chained\n // focus handler already moved focus somewhere else.\n\n const ownerDocument = getOwnerDocument(e.target);\n const activeElement = ownerDocument ? getActiveElement(ownerDocument) : getActiveElement();\n if (e.target === e.currentTarget && activeElement === getEventTarget(e.nativeEvent)) {\n if (onFocusProp) {\n onFocusProp(e);\n }\n\n if (onFocusChange) {\n onFocusChange(true);\n }\n\n onSyntheticFocus(e);\n }\n }, [onFocusChange, onFocusProp, onSyntheticFocus]);\n\n return {\n focusProps: {\n onFocus: (!isDisabled && (onFocusProp || onFocusChange || onBlurProp)) ? onFocus : undefined,\n onBlur: (!isDisabled && (onBlurProp || onFocusChange)) ? onBlur : undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"useFocus.module.js.map"}
@@ -1,3 +1,4 @@
1
+ var $625cf83917e112ad$exports = require("./utils.main.js");
1
2
  var $cR3F8$reactariautils = require("@react-aria/utils");
2
3
  var $cR3F8$react = require("react");
3
4
  var $cR3F8$reactariassr = require("@react-aria/ssr");
@@ -31,6 +32,7 @@ $parcel$export(module.exports, "useFocusVisibleListener", () => $e77252a287ef94a
31
32
 
32
33
 
33
34
 
35
+
34
36
  let $e77252a287ef94ab$var$currentModality = null;
35
37
  let $e77252a287ef94ab$var$changeHandlers = new Set();
36
38
  let $e77252a287ef94ab$export$d90243b58daecda7 = new Map(); // We use a map here to support setting event listeners across multiple document objects.
@@ -74,7 +76,7 @@ function $e77252a287ef94ab$var$handleFocusEvent(e) {
74
76
  // Firefox fires two extra focus events when the user first clicks into an iframe:
75
77
  // first on the window, then on the document. We ignore these events so they don't
76
78
  // cause keyboard focus rings to appear.
77
- if (e.target === window || e.target === document) return;
79
+ if (e.target === window || e.target === document || (0, $625cf83917e112ad$exports.ignoreFocusEvent) || !e.isTrusted) return;
78
80
  // If a focus event occurs without a preceding keyboard or pointer event, switch to virtual modality.
79
81
  // This occurs, for example, when navigating a form with the next/previous buttons on iOS.
80
82
  if (!$e77252a287ef94ab$var$hasEventBeforeFocus && !$e77252a287ef94ab$var$hasBlurredWindowRecently) {
@@ -85,6 +87,7 @@ function $e77252a287ef94ab$var$handleFocusEvent(e) {
85
87
  $e77252a287ef94ab$var$hasBlurredWindowRecently = false;
86
88
  }
87
89
  function $e77252a287ef94ab$var$handleWindowBlur() {
90
+ if (0, $625cf83917e112ad$exports.ignoreFocusEvent) return;
88
91
  // When the window is blurred, reset state. This is necessary when tabbing out of the window,
89
92
  // for example, since a subsequent focus event won't be fired.
90
93
  $e77252a287ef94ab$var$hasEventBeforeFocus = false;
@@ -207,12 +210,14 @@ const $e77252a287ef94ab$var$nonTextInputTypes = new Set([
207
210
  * If this is attached to text input component, return if the event is a focus event (Tab/Escape keys pressed) so that
208
211
  * focus visible style can be properly set.
209
212
  */ function $e77252a287ef94ab$var$isKeyboardFocusEvent(isTextInput, modality, e) {
210
- var _e_target;
213
+ let document1 = (0, $cR3F8$reactariautils.getOwnerDocument)(e === null || e === void 0 ? void 0 : e.target);
211
214
  const IHTMLInputElement = typeof window !== 'undefined' ? (0, $cR3F8$reactariautils.getOwnerWindow)(e === null || e === void 0 ? void 0 : e.target).HTMLInputElement : HTMLInputElement;
212
215
  const IHTMLTextAreaElement = typeof window !== 'undefined' ? (0, $cR3F8$reactariautils.getOwnerWindow)(e === null || e === void 0 ? void 0 : e.target).HTMLTextAreaElement : HTMLTextAreaElement;
213
216
  const IHTMLElement = typeof window !== 'undefined' ? (0, $cR3F8$reactariautils.getOwnerWindow)(e === null || e === void 0 ? void 0 : e.target).HTMLElement : HTMLElement;
214
217
  const IKeyboardEvent = typeof window !== 'undefined' ? (0, $cR3F8$reactariautils.getOwnerWindow)(e === null || e === void 0 ? void 0 : e.target).KeyboardEvent : KeyboardEvent;
215
- isTextInput = isTextInput || (e === null || e === void 0 ? void 0 : e.target) instanceof IHTMLInputElement && !$e77252a287ef94ab$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);
218
+ // 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)
219
+ // we need to rely on the user passing isTextInput into here. This way we can skip toggling focus visiblity for said input element
220
+ isTextInput = isTextInput || document1.activeElement instanceof IHTMLInputElement && !$e77252a287ef94ab$var$nonTextInputTypes.has(document1.activeElement.type) || document1.activeElement instanceof IHTMLTextAreaElement || document1.activeElement instanceof IHTMLElement && document1.activeElement.isContentEditable;
216
221
  return !(isTextInput && modality === 'keyboard' && e instanceof IKeyboardEvent && !$e77252a287ef94ab$var$FOCUS_VISIBLE_INPUT_KEYS[e.key]);
217
222
  }
218
223
  function $e77252a287ef94ab$export$ffd9e5021c1fb2d6(props = {}) {
@@ -233,6 +238,7 @@ function $e77252a287ef94ab$export$ec71b4b83ac08ec3(fn, deps, opts) {
233
238
  $e77252a287ef94ab$var$setupGlobalFocusEvents();
234
239
  (0, $cR3F8$react.useEffect)(()=>{
235
240
  let handler = (modality, e)=>{
241
+ // We want to early return for any keyboard events that occur inside text inputs EXCEPT for Tab and Escape
236
242
  if (!$e77252a287ef94ab$var$isKeyboardFocusEvent(!!(opts === null || opts === void 0 ? void 0 : opts.isTextInput), modality, e)) return;
237
243
  fn($e77252a287ef94ab$export$b9b3dfddab17db27());
238
244
  };
@@ -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,2BAAI,OAAO,EAAE,MAAM,IAAK,EAAE,OAAO,IAAI,EAAE,GAAG,KAAK,aAAa,EAAE,GAAG,KAAK,WAAW,EAAE,GAAG,KAAK,MAAK;AAC1H;AAGA,SAAS,0CAAoB,CAAgB;IAC3C,4CAAsB;IACtB,IAAI,iCAAW,IAAI;QACjB,wCAAkB;QAClB,4CAAsB,YAAY;IACpC;AACF;AAEA,SAAS,yCAAmB,CAA4B;IACtD,wCAAkB;IAClB,IAAI,EAAE,IAAI,KAAK,eAAe,EAAE,IAAI,KAAK,eAAe;QACtD,4CAAsB;QACtB,4CAA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AAA,wBAAA,EAAG,MAAM,EAAa,aAAa,GAAG;IAE5G,cAAc,eACX,CAAA,cAAA,wBAAA,EAAG,MAAM,aAAY,qBAAqB,CAAC,wCAAkB,GAAG,CAAC,cAAA,yBAAA,YAAA,EAAG,MAAM,cAAT,gCAAA,UAAW,IAAI,KACjF,CAAA,cAAA,wBAAA,EAAG,MAAM,aAAY,wBACpB,CAAA,cAAA,wBAAA,EAAG,MAAM,aAAY,iBAAgB,cAAA,wBAAA,EAAG,MAAM,CAAC,iBAAiB;IACnE,OAAO,CAAE,CAAA,eAAe,aAAa,cAAc,aAAa,kBAAkB,CAAC,8CAAwB,CAAC,EAAE,GAAG,CAAC,AAAD;AACnH;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,0CAAwB,CAAC;QACvB,gBAAgB;IAClB,GAAG;QAAC;KAAY,EAAE;qBAAC;IAAW;IAE9B,OAAO;QAAC,gBAAgB;IAAmB;AAC7C;AAKO,SAAS,0CAAwB,EAAuB,EAAE,IAAwB,EAAE,IAA8B;IACvH;IAEA,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,UAAU,CAAC,UAAoB;YACjC,IAAI,CAAC,2CAAqB,CAAC,EAAE,iBAAA,2BAAA,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.main.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,2BAAI,OAAO,EAAE,MAAM,IAAK,EAAE,OAAO,IAAI,EAAE,GAAG,KAAK,aAAa,EAAE,GAAG,KAAK,WAAW,EAAE,GAAG,KAAK,MAAK;AAC1H;AAGA,SAAS,0CAAoB,CAAgB;IAC3C,4CAAsB;IACtB,IAAI,iCAAW,IAAI;QACjB,wCAAkB;QAClB,4CAAsB,YAAY;IACpC;AACF;AAEA,SAAS,yCAAmB,CAA4B;IACtD,wCAAkB;IAClB,IAAI,EAAE,IAAI,KAAK,eAAe,EAAE,IAAI,KAAK,eAAe;QACtD,4CAAsB;QACtB,4CAAsB,WAAW;IACnC;AACF;AAEA,SAAS,uCAAiB,CAAa;IACrC,IAAI,CAAA,GAAA,oCAAa,EAAE,IAAI;QACrB,4CAAsB;QAC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,CAAA,GAAA,oCAAa,EAAE,cAAA,wBAAA,EAAG,MAAM,EAAa,aAAa,GAAG;IAE5G,qKAAqK;IACrK,kIAAkI;IAClI,cAAc,eACX,UAAS,aAAa,YAAY,qBAAqB,CAAC,wCAAkB,GAAG,CAAC,UAAS,aAAa,CAAC,IAAI,KAC1G,UAAS,aAAa,YAAY,wBACjC,UAAS,aAAa,YAAY,gBAAgB,UAAS,aAAa,CAAC,iBAAiB;IAC7F,OAAO,CAAE,CAAA,eAAe,aAAa,cAAc,aAAa,kBAAkB,CAAC,8CAAwB,CAAC,EAAE,GAAG,CAAC,AAAD;AACnH;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,0CAAwB,CAAC;QACvB,gBAAgB;IAClB,GAAG;QAAC;KAAY,EAAE;qBAAC;IAAW;IAE9B,OAAO;QAAC,gBAAgB;IAAmB;AAC7C;AAKO,SAAS,0CAAwB,EAAuB,EAAE,IAAwB,EAAE,IAA8B;IACvH;IAEA,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,UAAU,CAAC,UAAoB;YACjC,0GAA0G;YAC1G,IAAI,CAAC,2CAAqB,CAAC,EAAE,iBAAA,2BAAA,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 {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.main.js.map"}
@@ -1,3 +1,4 @@
1
+ import {ignoreFocusEvent as $8a9cb279dc87e130$export$fda7da73ab5d4c48} from "./utils.mjs";
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,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
  };