@box/blueprint-web 19.6.0 → 20.0.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 (200) hide show
  1. package/THIRD_PARTY_LICENSES +119 -0
  2. package/dist/lib-esm/accordion/accordion.js +6 -6
  3. package/dist/lib-esm/accordion/types.d.ts +1 -1
  4. package/dist/lib-esm/checkbox/checkbox-item.js +3 -3
  5. package/dist/lib-esm/checkbox/types.d.ts +1 -1
  6. package/dist/lib-esm/collapsible/collapsible-section.js +5 -5
  7. package/dist/lib-esm/collapsible/types.d.ts +1 -1
  8. package/dist/lib-esm/combobox-group/combobox-group-combobox.js +1 -1
  9. package/dist/lib-esm/date-picker/date-picker.js +8 -7
  10. package/dist/lib-esm/guided-tooltip/guided-tooltip.js +7 -7
  11. package/dist/lib-esm/guided-tooltip/types.d.ts +1 -1
  12. package/dist/lib-esm/modal/alert-modal.types.d.ts +1 -1
  13. package/dist/lib-esm/modal/modal-close.js +2 -2
  14. package/dist/lib-esm/modal/modal-content.d.ts +1 -1
  15. package/dist/lib-esm/modal/modal-content.js +4 -4
  16. package/dist/lib-esm/modal/modal-description.js +2 -2
  17. package/dist/lib-esm/modal/modal-title.js +2 -2
  18. package/dist/lib-esm/modal/modal-trigger.js +2 -2
  19. package/dist/lib-esm/modal/modal.d.ts +1 -1
  20. package/dist/lib-esm/modal/modal.js +1 -1
  21. package/dist/lib-esm/modal/types.d.ts +1 -1
  22. package/dist/lib-esm/navigation-menu/index.d.ts +4 -2
  23. package/dist/lib-esm/navigation-menu/navigation-menu-item.d.ts +1 -1
  24. package/dist/lib-esm/navigation-menu/navigation-menu-trigger.d.ts +3 -1
  25. package/dist/lib-esm/primitives/chips/chip.d.ts +1 -1
  26. package/dist/lib-esm/primitives/chips/chip.js +2 -2
  27. package/dist/lib-esm/primitives/chips/chips-group.js +2 -2
  28. package/dist/lib-esm/primitives/chips/filter-chip/filter-chip-button.d.ts +1 -1
  29. package/dist/lib-esm/primitives/chips/filter-chip/filter-chip.d.ts +1 -1
  30. package/dist/lib-esm/primitives/chips/filter-chip/filter-combo-chip.d.ts +2 -2
  31. package/dist/lib-esm/primitives/chips/filter-chip/filter-trigger-chip.d.ts +1 -1
  32. package/dist/lib-esm/primitives/chips/filter-chip/index.d.ts +5 -5
  33. package/dist/lib-esm/primitives/chips/types.d.ts +1 -1
  34. package/dist/lib-esm/primitives/context-menu/context-menu-item.d.ts +2 -2
  35. package/dist/lib-esm/primitives/context-menu/context-menu-item.js +2 -2
  36. package/dist/lib-esm/primitives/context-menu/context-menu-menu-content.d.ts +1 -1
  37. package/dist/lib-esm/primitives/context-menu/context-menu-menu-content.js +5 -5
  38. package/dist/lib-esm/primitives/context-menu/context-menu-menu-header.js +3 -10
  39. package/dist/lib-esm/primitives/context-menu/context-menu-menu-root.d.ts +1 -1
  40. package/dist/lib-esm/primitives/context-menu/context-menu-menu-root.js +1 -1
  41. package/dist/lib-esm/primitives/context-menu/context-menu-menu-trigger.d.ts +1 -1
  42. package/dist/lib-esm/primitives/context-menu/context-menu-menu-trigger.js +1 -1
  43. package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-content.d.ts +1 -1
  44. package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-content.js +5 -5
  45. package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-root.d.ts +1 -1
  46. package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-root.js +1 -1
  47. package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-trigger.d.ts +2 -2
  48. package/dist/lib-esm/primitives/context-menu/context-menu-sub-menu-trigger.js +1 -1
  49. package/dist/lib-esm/primitives/context-menu/index.d.ts +3 -3
  50. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-checkbox-item.d.ts +2 -2
  51. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-checkbox-item.js +3 -3
  52. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-content.d.ts +1 -1
  53. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-content.js +5 -5
  54. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-group.d.ts +4 -2
  55. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-group.js +2 -2
  56. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-item.d.ts +2 -2
  57. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-item.js +2 -2
  58. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-group.d.ts +2 -2
  59. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-group.js +2 -2
  60. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-select-item.d.ts +2 -2
  61. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-radio-select-item.js +3 -3
  62. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-root.d.ts +1 -1
  63. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-root.js +2 -2
  64. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-header.d.ts +4 -2
  65. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-header.js +2 -2
  66. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-content.d.ts +1 -1
  67. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-content.js +5 -5
  68. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-root.d.ts +1 -1
  69. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-root.js +2 -2
  70. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-trigger.d.ts +2 -2
  71. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-sub-menu-trigger.js +2 -2
  72. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-trigger.d.ts +4 -2
  73. package/dist/lib-esm/primitives/dropdown-menu/dropdown-menu-trigger.js +2 -2
  74. package/dist/lib-esm/primitives/dropdown-menu/index.d.ts +14 -8
  75. package/dist/lib-esm/primitives/notification/hooks/use-notification-layer.d.ts +15 -0
  76. package/dist/lib-esm/primitives/notification/hooks/use-notification-layer.js +49 -0
  77. package/dist/lib-esm/primitives/notification/notification-provider.js +2 -2
  78. package/dist/lib-esm/primitives/notification/notification.viewport-animated.js +12 -8
  79. package/dist/lib-esm/primitives/notification/notification.viewport.js +5 -1
  80. package/dist/lib-esm/primitives/notification/private-notification-element-animated.js +44 -6
  81. package/dist/lib-esm/primitives/notification/private-notification-element.js +34 -4
  82. package/dist/lib-esm/primitives/popover/index.d.ts +11 -5
  83. package/dist/lib-esm/primitives/popover/popover-anchor.d.ts +4 -2
  84. package/dist/lib-esm/primitives/popover/popover-anchor.js +2 -2
  85. package/dist/lib-esm/primitives/popover/popover-close.d.ts +4 -2
  86. package/dist/lib-esm/primitives/popover/popover-close.js +2 -2
  87. package/dist/lib-esm/primitives/popover/popover-content-container.d.ts +1 -1
  88. package/dist/lib-esm/primitives/popover/popover-content-container.js +3 -3
  89. package/dist/lib-esm/primitives/popover/popover-footer.d.ts +1 -1
  90. package/dist/lib-esm/primitives/popover/popover-main-content.d.ts +1 -1
  91. package/dist/lib-esm/primitives/popover/popover-root.d.ts +1 -1
  92. package/dist/lib-esm/primitives/popover/popover-root.js +2 -2
  93. package/dist/lib-esm/primitives/popover/popover-trigger.d.ts +4 -2
  94. package/dist/lib-esm/primitives/popover/popover-trigger.js +2 -2
  95. package/dist/lib-esm/radio-group/index.d.ts +1 -1
  96. package/dist/lib-esm/radio-group/radio-group.d.ts +1 -1
  97. package/dist/lib-esm/radio-group/radio-group.js +2 -2
  98. package/dist/lib-esm/radio-group/radio-item.js +3 -3
  99. package/dist/lib-esm/radio-group/types.d.ts +1 -1
  100. package/dist/lib-esm/select/select.js +12 -12
  101. package/dist/lib-esm/select/types.d.ts +1 -1
  102. package/dist/lib-esm/select/utils/use-select-exit-animation.d.ts +3 -3
  103. package/dist/lib-esm/select/utils/use-select-exit-animation.js +3 -3
  104. package/dist/lib-esm/side-panel/side-panel-close.js +2 -2
  105. package/dist/lib-esm/side-panel/side-panel-content.js +3 -3
  106. package/dist/lib-esm/side-panel/side-panel-header.js +2 -2
  107. package/dist/lib-esm/side-panel/side-panel-overlay.js +3 -3
  108. package/dist/lib-esm/side-panel/side-panel-trigger.js +2 -2
  109. package/dist/lib-esm/side-panel/side-panel.js +1 -1
  110. package/dist/lib-esm/side-panel/types.d.ts +1 -1
  111. package/dist/lib-esm/switch/switch-item.js +3 -3
  112. package/dist/lib-esm/switch/types.d.ts +1 -1
  113. package/dist/lib-esm/toolbar/index.d.ts +2 -2
  114. package/dist/lib-esm/toolbar/toolbar-button.js +2 -2
  115. package/dist/lib-esm/toolbar/toolbar-input.js +2 -2
  116. package/dist/lib-esm/toolbar/toolbar-link.js +2 -2
  117. package/dist/lib-esm/toolbar/toolbar-root.js +3 -3
  118. package/dist/lib-esm/toolbar/toolbar-separator.d.ts +1 -1
  119. package/dist/lib-esm/toolbar/toolbar-separator.js +2 -2
  120. package/dist/lib-esm/toolbar/toolbar-text-toggle-item.js +2 -2
  121. package/dist/lib-esm/toolbar/toolbar-toggle-group.d.ts +1 -2
  122. package/dist/lib-esm/toolbar/toolbar-toggle-group.js +2 -2
  123. package/dist/lib-esm/toolbar/toolbar-toggle-item.js +2 -2
  124. package/dist/lib-esm/toolbar/types.d.ts +1 -1
  125. package/dist/lib-esm/tooltip/tooltip.d.ts +1 -1
  126. package/dist/lib-esm/tooltip/tooltip.js +6 -6
  127. package/dist/lib-esm/tooltip/types.d.ts +1 -1
  128. package/dist/lib-esm/utils/radix-compat/accordion.d.ts +45 -0
  129. package/dist/lib-esm/utils/radix-compat/accordion.js +299 -0
  130. package/dist/lib-esm/utils/radix-compat/allow-auto-focus.d.ts +9 -0
  131. package/dist/lib-esm/utils/radix-compat/allow-auto-focus.js +16 -0
  132. package/dist/lib-esm/utils/radix-compat/bubble-input.d.ts +14 -0
  133. package/dist/lib-esm/utils/radix-compat/bubble-input.js +70 -0
  134. package/dist/lib-esm/utils/radix-compat/button-controls.d.ts +9 -0
  135. package/dist/lib-esm/utils/radix-compat/button-controls.js +6 -0
  136. package/dist/lib-esm/utils/radix-compat/checkbox.d.ts +18 -0
  137. package/dist/lib-esm/utils/radix-compat/checkbox.js +131 -0
  138. package/dist/lib-esm/utils/radix-compat/collapsible.d.ts +33 -0
  139. package/dist/lib-esm/utils/radix-compat/collapsible.js +133 -0
  140. package/dist/lib-esm/utils/radix-compat/collection.d.ts +21 -0
  141. package/dist/lib-esm/utils/radix-compat/collection.js +82 -0
  142. package/dist/lib-esm/utils/radix-compat/compose-refs.d.ts +8 -0
  143. package/dist/lib-esm/utils/radix-compat/compose-refs.js +44 -0
  144. package/dist/lib-esm/utils/radix-compat/content-size.d.ts +15 -0
  145. package/dist/lib-esm/utils/radix-compat/content-size.js +61 -0
  146. package/dist/lib-esm/utils/radix-compat/context-menu.d.ts +56 -0
  147. package/dist/lib-esm/utils/radix-compat/context-menu.js +191 -0
  148. package/dist/lib-esm/utils/radix-compat/dialog.d.ts +50 -0
  149. package/dist/lib-esm/utils/radix-compat/dialog.js +367 -0
  150. package/dist/lib-esm/utils/radix-compat/dismiss-marker.d.ts +5 -0
  151. package/dist/lib-esm/utils/radix-compat/dismiss-marker.js +12 -0
  152. package/dist/lib-esm/utils/radix-compat/dismissable.d.ts +34 -0
  153. package/dist/lib-esm/utils/radix-compat/dismissable.js +205 -0
  154. package/dist/lib-esm/utils/radix-compat/dropdown-menu.d.ts +57 -0
  155. package/dist/lib-esm/utils/radix-compat/dropdown-menu.js +187 -0
  156. package/dist/lib-esm/utils/radix-compat/focus-scope-component.d.ts +16 -0
  157. package/dist/lib-esm/utils/radix-compat/focus-scope-component.js +41 -0
  158. package/dist/lib-esm/utils/radix-compat/focus-scope.d.ts +37 -0
  159. package/dist/lib-esm/utils/radix-compat/focus-scope.js +288 -0
  160. package/dist/lib-esm/utils/radix-compat/hide-others.d.ts +6 -0
  161. package/dist/lib-esm/utils/radix-compat/hide-others.js +18 -0
  162. package/dist/lib-esm/utils/radix-compat/index.d.ts +14 -0
  163. package/dist/lib-esm/utils/radix-compat/layers.d.ts +25 -0
  164. package/dist/lib-esm/utils/radix-compat/layers.js +61 -0
  165. package/dist/lib-esm/utils/radix-compat/menu.d.ts +98 -0
  166. package/dist/lib-esm/utils/radix-compat/menu.js +1041 -0
  167. package/dist/lib-esm/utils/radix-compat/popover.d.ts +44 -0
  168. package/dist/lib-esm/utils/radix-compat/popover.js +386 -0
  169. package/dist/lib-esm/utils/radix-compat/popper.d.ts +60 -0
  170. package/dist/lib-esm/utils/radix-compat/popper.js +416 -0
  171. package/dist/lib-esm/utils/radix-compat/portal.d.ts +11 -0
  172. package/dist/lib-esm/utils/radix-compat/portal.js +20 -0
  173. package/dist/lib-esm/utils/radix-compat/presence.d.ts +20 -0
  174. package/dist/lib-esm/utils/radix-compat/presence.js +110 -0
  175. package/dist/lib-esm/utils/radix-compat/radio-group.d.ts +27 -0
  176. package/dist/lib-esm/utils/radix-compat/radio-group.js +189 -0
  177. package/dist/lib-esm/utils/radix-compat/roving-focus.d.ts +35 -0
  178. package/dist/lib-esm/utils/radix-compat/roving-focus.js +237 -0
  179. package/dist/lib-esm/utils/radix-compat/select.d.ts +82 -0
  180. package/dist/lib-esm/utils/radix-compat/select.js +901 -0
  181. package/dist/lib-esm/utils/radix-compat/slot.d.ts +31 -0
  182. package/dist/lib-esm/utils/radix-compat/slot.js +119 -0
  183. package/dist/lib-esm/utils/radix-compat/store-options.d.ts +8 -0
  184. package/dist/lib-esm/utils/radix-compat/store-options.js +10 -0
  185. package/dist/lib-esm/utils/radix-compat/switch.d.ts +16 -0
  186. package/dist/lib-esm/utils/radix-compat/switch.js +97 -0
  187. package/dist/lib-esm/utils/radix-compat/toggle-group.d.ts +41 -0
  188. package/dist/lib-esm/utils/radix-compat/toggle-group.js +195 -0
  189. package/dist/lib-esm/utils/radix-compat/toolbar.d.ts +32 -0
  190. package/dist/lib-esm/utils/radix-compat/toolbar.js +136 -0
  191. package/dist/lib-esm/utils/radix-compat/tooltip.d.ts +59 -0
  192. package/dist/lib-esm/utils/radix-compat/tooltip.js +636 -0
  193. package/dist/lib-esm/utils/radix-compat/typeahead.d.ts +22 -0
  194. package/dist/lib-esm/utils/radix-compat/typeahead.js +64 -0
  195. package/dist/lib-esm/utils/radix-compat/types.d.ts +53 -0
  196. package/dist/lib-esm/utils/radix-compat/viewport-height.d.ts +5 -0
  197. package/dist/lib-esm/utils/radix-compat/viewport-height.js +28 -0
  198. package/dist/lib-esm/utils/radix-compat/visually-hidden.d.ts +2 -0
  199. package/dist/lib-esm/utils/radix-compat/visually-hidden.js +24 -0
  200. package/package.json +8 -19
@@ -0,0 +1,205 @@
1
+ import { useRef, useEffect, useCallback } from 'react';
2
+ import { flushSync } from 'react-dom';
3
+ import { useCallbackRef } from '../useCallbackRef.js';
4
+ import { useLayer, isInsidePersistentElement } from './layers.js';
5
+
6
+ const POINTER_DOWN_OUTSIDE = 'dismissableLayer.pointerDownOutside';
7
+ const FOCUS_OUTSIDE = 'dismissableLayer.focusOutside';
8
+ function dispatchOutsideEvent(name, originalEvent, handler, discrete) {
9
+ const target = originalEvent.target;
10
+ const event = new CustomEvent(name, {
11
+ bubbles: false,
12
+ cancelable: true,
13
+ detail: {
14
+ originalEvent
15
+ }
16
+ });
17
+ const listener = customEvent => handler(customEvent);
18
+ if (target && 'dispatchEvent' in target) {
19
+ target.addEventListener(name, listener, {
20
+ once: true
21
+ });
22
+ if (discrete) {
23
+ flushSync(() => target.dispatchEvent(event));
24
+ } else {
25
+ target.dispatchEvent(event);
26
+ }
27
+ target.removeEventListener(name, listener);
28
+ } else {
29
+ handler(event);
30
+ }
31
+ return event;
32
+ }
33
+ /**
34
+ * Handles the dismissal of an overlay like the Radix dismissable layer, with its callbacks and event shapes.
35
+ *
36
+ * Escape is handled on the document, after the handlers inside the overlay ran, by the most recently opened
37
+ * layer only: `onEscapeKeyDown` can prevent the dismissal, and the key press keeps propagating, so the Ariakit
38
+ * overlays must not hide on Escape themselves. Outside interactions are handled on the document too:
39
+ * `onPointerDownOutside` runs on `pointerdown` (on the click that follows it for touch), `onFocusOutside` on
40
+ * `focusin`, and calling `preventDefault()` keeps the overlay open. Ariakit mustn't hide the overlay on outside
41
+ * interactions itself: once focus was inside, it ignores elements added to the page after the overlay opened.
42
+ *
43
+ * Returns the props for the Ariakit dialog and the capture handlers to spread on the content element,
44
+ * which keep pointer downs in React portals rendered from the content counted as inside.
45
+ */
46
+ function useDismissable({
47
+ open,
48
+ disableOutsidePointerEvents = false,
49
+ onDismiss,
50
+ onEscapeKeyDown,
51
+ onPointerDownOutside,
52
+ onFocusOutside,
53
+ onInteractOutside
54
+ }) {
55
+ const handleDismiss = useCallbackRef(onDismiss);
56
+ const handleEscapeKeyDown = useCallbackRef(onEscapeKeyDown);
57
+ const handlePointerDownOutside = useCallbackRef(onPointerDownOutside);
58
+ const handleFocusOutside = useCallbackRef(onFocusOutside);
59
+ const handleInteractOutside = useCallbackRef(onInteractOutside);
60
+ const isOpen = useCallbackRef(() => open);
61
+ const {
62
+ hasLayerAbove,
63
+ hasBlockingLayerAbove
64
+ } = useLayer('overlay', open, disableOutsidePointerEvents);
65
+ const isPointerInsideReactTreeRef = useRef(false);
66
+ const isFocusInsideReactTreeRef = useRef(false);
67
+ const hasInteractedOutsideRef = useRef(false);
68
+ useEffect(() => {
69
+ if (open) {
70
+ hasInteractedOutsideRef.current = false;
71
+ }
72
+ }, [open]);
73
+ // Like with Radix, outside pointer downs are reported as long as the content is mounted, also while it closes,
74
+ // and dismiss it while it's open. A pointer down that is stopped before it bubbles to the document (React Aria's
75
+ // `usePress` does that) is no outside interaction.
76
+ useEffect(() => {
77
+ let wasOpenOnPointerDown = false;
78
+ let handleClick;
79
+ const removeClickListener = () => {
80
+ if (handleClick) {
81
+ document.removeEventListener('click', handleClick);
82
+ }
83
+ };
84
+ // A pointer down that opens the layer again while it closes, like one on its trigger, mustn't dismiss it.
85
+ const handlePointerDownCapture = () => {
86
+ wasOpenOnPointerDown = isOpen();
87
+ };
88
+ const handlePointerDown = event => {
89
+ if (event.target && !isPointerInsideReactTreeRef.current) {
90
+ const wasOpen = wasOpenOnPointerDown;
91
+ const handlePointerDownOutsideEvent = () => {
92
+ if (isInsidePersistentElement(event.target) || hasBlockingLayerAbove()) {
93
+ return;
94
+ }
95
+ const outsideEvent = dispatchOutsideEvent(POINTER_DOWN_OUTSIDE, event, customEvent => {
96
+ handlePointerDownOutside(customEvent);
97
+ handleInteractOutside(customEvent);
98
+ }, true);
99
+ if (!outsideEvent.defaultPrevented) {
100
+ hasInteractedOutsideRef.current = true;
101
+ if (wasOpen && isOpen()) {
102
+ handleDismiss();
103
+ }
104
+ }
105
+ };
106
+ // Browsers fire the click of a touch about 350ms after it ends; dismissing earlier could let that
107
+ // click reach what was below the overlay.
108
+ if (event.pointerType === 'touch') {
109
+ removeClickListener();
110
+ handleClick = handlePointerDownOutsideEvent;
111
+ document.addEventListener('click', handleClick, {
112
+ once: true
113
+ });
114
+ } else {
115
+ handlePointerDownOutsideEvent();
116
+ }
117
+ } else {
118
+ removeClickListener();
119
+ }
120
+ isPointerInsideReactTreeRef.current = false;
121
+ };
122
+ // The pointer down that opened the layer must not count as an outside interaction.
123
+ const timerId = window.setTimeout(() => {
124
+ document.addEventListener('pointerdown', handlePointerDownCapture, true);
125
+ document.addEventListener('pointerdown', handlePointerDown);
126
+ }, 0);
127
+ return () => {
128
+ window.clearTimeout(timerId);
129
+ document.removeEventListener('pointerdown', handlePointerDownCapture, true);
130
+ document.removeEventListener('pointerdown', handlePointerDown);
131
+ removeClickListener();
132
+ };
133
+ }, [handleDismiss, handlePointerDownOutside, handleInteractOutside, hasBlockingLayerAbove, isOpen]);
134
+ // Like with Radix, focus moving outside is reported as long as the content is mounted, and dismisses it while it's
135
+ // open; reporting it while the content closes keeps focus where it moved to when the content unmounts. Focus that
136
+ // moves into the React tree, such as a nested menu in a portal, isn't outside: React marks it in its capture
137
+ // phase, before the event bubbles to the document.
138
+ useEffect(() => {
139
+ const handleFocusIn = event => {
140
+ if (!event.target || isFocusInsideReactTreeRef.current || isInsidePersistentElement(event.target)) {
141
+ return;
142
+ }
143
+ const outsideEvent = dispatchOutsideEvent(FOCUS_OUTSIDE, event, customEvent => {
144
+ handleFocusOutside(customEvent);
145
+ handleInteractOutside(customEvent);
146
+ }, false);
147
+ if (!outsideEvent.defaultPrevented) {
148
+ hasInteractedOutsideRef.current = true;
149
+ if (open) {
150
+ handleDismiss();
151
+ }
152
+ }
153
+ };
154
+ document.addEventListener('focusin', handleFocusIn);
155
+ return () => document.removeEventListener('focusin', handleFocusIn);
156
+ }, [open, handleDismiss, handleFocusOutside, handleInteractOutside]);
157
+ useEffect(() => {
158
+ if (!open) {
159
+ return undefined;
160
+ }
161
+ const handleKeyDown = event => {
162
+ if (event.key !== 'Escape' || hasLayerAbove('overlay') || hasLayerAbove('notification')) {
163
+ return;
164
+ }
165
+ handleEscapeKeyDown(event);
166
+ if (!event.defaultPrevented) {
167
+ event.preventDefault();
168
+ handleDismiss();
169
+ }
170
+ };
171
+ document.addEventListener('keydown', handleKeyDown);
172
+ return () => document.removeEventListener('keydown', handleKeyDown);
173
+ }, [open, handleDismiss, handleEscapeKeyDown, hasLayerAbove]);
174
+ const onPointerDownCapture = useCallback(() => {
175
+ isPointerInsideReactTreeRef.current = true;
176
+ }, []);
177
+ const onFocusCapture = useCallback(() => {
178
+ isFocusInsideReactTreeRef.current = true;
179
+ }, []);
180
+ const onBlurCapture = useCallback(() => {
181
+ isFocusInsideReactTreeRef.current = false;
182
+ }, []);
183
+ return {
184
+ hideOnInteractOutside: false,
185
+ hasInteractedOutsideRef,
186
+ contentProps: {
187
+ onPointerDownCapture,
188
+ onFocusCapture,
189
+ onBlurCapture
190
+ }
191
+ };
192
+ }
193
+ /** Composes a Radix style outside handler so that right clicks and Ctrl + left clicks never dismiss. */
194
+ function preventRightClickDismiss(event) {
195
+ const {
196
+ originalEvent
197
+ } = event.detail;
198
+ const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
199
+ const isRightClick = originalEvent.button === 2 || ctrlLeftClick;
200
+ if (isRightClick) {
201
+ event.preventDefault();
202
+ }
203
+ }
204
+
205
+ export { preventRightClickDismiss, useDismissable };
@@ -0,0 +1,57 @@
1
+ import { type ReactNode } from 'react';
2
+ import * as MenuPrimitive from './menu';
3
+ import { type Direction, type PrimitiveProps } from './types';
4
+ export interface DropdownMenuProps {
5
+ children?: ReactNode;
6
+ dir?: Direction;
7
+ open?: boolean;
8
+ defaultOpen?: boolean;
9
+ onOpenChange?(open: boolean): void;
10
+ modal?: boolean;
11
+ }
12
+ /** Dropdown menu with the Radix API, DOM and keyboard model; its content is an Ariakit popover with `role="menu"`. */
13
+ export declare const Root: {
14
+ (props: DropdownMenuProps): import("react/jsx-runtime").JSX.Element;
15
+ displayName: string;
16
+ };
17
+ export type DropdownMenuTriggerProps = PrimitiveProps<'button'>;
18
+ export declare const Trigger: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").ButtonHTMLAttributes<HTMLButtonElement>, HTMLButtonElement>, "ref"> & {
19
+ asChild?: boolean;
20
+ } & import("react").RefAttributes<HTMLButtonElement>>;
21
+ export type DropdownMenuPortalProps = MenuPrimitive.MenuPortalProps;
22
+ export declare const Portal: {
23
+ ({ forceMount, children, container }: MenuPrimitive.MenuPortalProps): import("react/jsx-runtime").JSX.Element;
24
+ displayName: string;
25
+ };
26
+ export type DropdownMenuContentProps = Omit<MenuPrimitive.MenuContentProps, 'onEntryFocus'>;
27
+ export declare const Content: import("react").ForwardRefExoticComponent<DropdownMenuContentProps & import("react").RefAttributes<HTMLDivElement>>;
28
+ export type DropdownMenuGroupProps = MenuPrimitive.MenuGroupProps;
29
+ export type DropdownMenuLabelProps = MenuPrimitive.MenuLabelProps;
30
+ export type DropdownMenuItemProps = MenuPrimitive.MenuItemProps;
31
+ export type DropdownMenuCheckboxItemProps = MenuPrimitive.MenuCheckboxItemProps;
32
+ export type DropdownMenuRadioGroupProps = MenuPrimitive.MenuRadioGroupProps;
33
+ export type DropdownMenuRadioItemProps = MenuPrimitive.MenuRadioItemProps;
34
+ export type DropdownMenuItemIndicatorProps = MenuPrimitive.MenuItemIndicatorProps;
35
+ export type DropdownMenuSeparatorProps = MenuPrimitive.MenuSeparatorProps;
36
+ export type DropdownMenuArrowProps = MenuPrimitive.MenuArrowProps;
37
+ export type DropdownMenuSubTriggerProps = MenuPrimitive.MenuSubTriggerProps;
38
+ export type { MenuSubContentProps } from './menu';
39
+ export declare const Group: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
40
+ asChild?: boolean;
41
+ } & import("react").RefAttributes<HTMLDivElement>>, Label: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
42
+ asChild?: boolean;
43
+ } & import("react").RefAttributes<HTMLDivElement>>, Item: import("react").ForwardRefExoticComponent<MenuPrimitive.MenuItemProps & import("react").RefAttributes<HTMLDivElement>>, CheckboxItem: import("react").ForwardRefExoticComponent<MenuPrimitive.MenuCheckboxItemProps & import("react").RefAttributes<HTMLDivElement>>, RadioGroup: import("react").ForwardRefExoticComponent<MenuPrimitive.MenuRadioGroupProps & import("react").RefAttributes<HTMLDivElement>>, RadioItem: import("react").ForwardRefExoticComponent<MenuPrimitive.MenuRadioItemProps & import("react").RefAttributes<HTMLDivElement>>, ItemIndicator: import("react").ForwardRefExoticComponent<MenuPrimitive.MenuItemIndicatorProps & import("react").RefAttributes<HTMLSpanElement>>, Separator: import("react").ForwardRefExoticComponent<Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
44
+ asChild?: boolean;
45
+ } & import("react").RefAttributes<HTMLDivElement>>, Arrow: import("react").ForwardRefExoticComponent<Omit<import("./popper").PopperArrowProps, "ref"> & import("react").RefAttributes<SVGSVGElement>>, SubTrigger: import("react").ForwardRefExoticComponent<MenuPrimitive.MenuItemImplProps & import("react").RefAttributes<HTMLDivElement>>;
46
+ export interface DropdownMenuSubProps {
47
+ children?: ReactNode;
48
+ open?: boolean;
49
+ defaultOpen?: boolean;
50
+ onOpenChange?(open: boolean): void;
51
+ }
52
+ export declare const Sub: {
53
+ (props: DropdownMenuSubProps): import("react/jsx-runtime").JSX.Element;
54
+ displayName: string;
55
+ };
56
+ export type DropdownMenuSubContentProps = MenuPrimitive.MenuSubContentProps;
57
+ export declare const SubContent: import("react").ForwardRefExoticComponent<MenuPrimitive.MenuSubContentProps & import("react").RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,187 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { forwardRef, useRef, useContext, createContext, useId, useCallback, useMemo } from 'react';
3
+ import { composeEventHandlers } from '../composeEventHandlers.js';
4
+ import { useControllableState } from '../useControllableState.js';
5
+ import { useComposedRefs } from './compose-refs.js';
6
+ import * as menu from './menu.js';
7
+ import { Anchor, Content as Content$1, SubContent as SubContent$1, Root as Root$1, Sub as Sub$1 } from './menu.js';
8
+ import { getPopperCssVariables } from './popper.js';
9
+ import { Slot } from './slot.js';
10
+
11
+ const contentCssVariables = getPopperCssVariables('dropdown-menu');
12
+ const DropdownMenuContext = /*#__PURE__*/createContext(null);
13
+ function useDropdownMenuContext(consumerName) {
14
+ const context = useContext(DropdownMenuContext);
15
+ if (!context) {
16
+ throw new Error(`\`${consumerName}\` must be used within \`DropdownMenu\``);
17
+ }
18
+ return context;
19
+ }
20
+ /** Dropdown menu with the Radix API, DOM and keyboard model; its content is an Ariakit popover with `role="menu"`. */
21
+ const Root = props => {
22
+ const {
23
+ children,
24
+ dir,
25
+ open: openProp,
26
+ defaultOpen,
27
+ onOpenChange,
28
+ modal = true
29
+ } = props;
30
+ const triggerRef = useRef(null);
31
+ const triggerId = useId();
32
+ const contentId = useId();
33
+ const [open = false, setOpen] = useControllableState({
34
+ prop: openProp,
35
+ defaultProp: defaultOpen,
36
+ onChange: onOpenChange
37
+ });
38
+ const onOpenToggle = useCallback(() => setOpen(prevOpen => !prevOpen), [setOpen]);
39
+ const onOpenChangeCallback = useCallback(nextOpen => setOpen(nextOpen), [setOpen]);
40
+ const value = useMemo(() => ({
41
+ triggerId,
42
+ triggerRef,
43
+ contentId,
44
+ open,
45
+ onOpenChange: onOpenChangeCallback,
46
+ onOpenToggle,
47
+ modal
48
+ }), [triggerId, contentId, open, onOpenChangeCallback, onOpenToggle, modal]);
49
+ return jsx(DropdownMenuContext.Provider, {
50
+ value: value,
51
+ children: jsx(Root$1, {
52
+ dir: dir,
53
+ modal: modal,
54
+ onOpenChange: onOpenChangeCallback,
55
+ open: open,
56
+ children: children
57
+ })
58
+ });
59
+ };
60
+ Root.displayName = 'DropdownMenu';
61
+ const Trigger = /*#__PURE__*/forwardRef((props, forwardedRef) => {
62
+ const {
63
+ disabled = false,
64
+ asChild,
65
+ ...triggerProps
66
+ } = props;
67
+ const context = useDropdownMenuContext('DropdownMenuTrigger');
68
+ const composedRefs = useComposedRefs(forwardedRef, context.triggerRef);
69
+ const Comp = asChild ? Slot : 'button';
70
+ return jsx(Anchor, {
71
+ asChild: true,
72
+ children: jsx(Comp, {
73
+ "aria-controls": context.open ? context.contentId : undefined,
74
+ "aria-expanded": context.open,
75
+ "aria-haspopup": "menu",
76
+ "data-disabled": disabled ? '' : undefined,
77
+ "data-state": context.open ? 'open' : 'closed',
78
+ disabled: disabled,
79
+ id: context.triggerId,
80
+ type: "button",
81
+ ...triggerProps,
82
+ ref: composedRefs,
83
+ onKeyDown: composeEventHandlers(props.onKeyDown, event => {
84
+ if (disabled) {
85
+ return;
86
+ }
87
+ if (['Enter', ' '].includes(event.key)) {
88
+ context.onOpenToggle();
89
+ }
90
+ if (event.key === 'ArrowDown') {
91
+ context.onOpenChange(true);
92
+ }
93
+ // Prevent the key press from scrolling the window or reaching the first focused item.
94
+ if (['Enter', ' ', 'ArrowDown'].includes(event.key)) {
95
+ event.preventDefault();
96
+ }
97
+ }),
98
+ onPointerDown: composeEventHandlers(props.onPointerDown, event => {
99
+ // Only the primary button opens the menu, and not with Ctrl (macOS right click).
100
+ if (!disabled && event.button === 0 && event.ctrlKey === false) {
101
+ context.onOpenToggle();
102
+ // The trigger doesn't take focus when opening, so the content gets it without competition.
103
+ if (!context.open) {
104
+ event.preventDefault();
105
+ }
106
+ }
107
+ })
108
+ })
109
+ });
110
+ });
111
+ Trigger.displayName = 'DropdownMenuTrigger';
112
+ const {
113
+ Portal
114
+ } = menu;
115
+ const Content = /*#__PURE__*/forwardRef((props, forwardedRef) => {
116
+ const context = useDropdownMenuContext('DropdownMenuContent');
117
+ const hasInteractedOutsideRef = useRef(false);
118
+ return jsx(Content$1, {
119
+ "aria-labelledby": context.triggerId,
120
+ id: context.contentId,
121
+ ...props,
122
+ ref: forwardedRef,
123
+ onCloseAutoFocus: composeEventHandlers(props.onCloseAutoFocus, event => {
124
+ if (!hasInteractedOutsideRef.current) {
125
+ context.triggerRef.current?.focus();
126
+ }
127
+ hasInteractedOutsideRef.current = false;
128
+ // Always prevent auto focus because we either focus manually or want user agent focus.
129
+ event.preventDefault();
130
+ }),
131
+ onInteractOutside: composeEventHandlers(props.onInteractOutside, event => {
132
+ const {
133
+ originalEvent
134
+ } = event.detail;
135
+ const ctrlLeftClick = originalEvent.button === 0 && originalEvent.ctrlKey === true;
136
+ const isRightClick = originalEvent.button === 2 || ctrlLeftClick;
137
+ if (!context.modal || isRightClick) {
138
+ hasInteractedOutsideRef.current = true;
139
+ }
140
+ }),
141
+ style: {
142
+ ...props.style,
143
+ ...contentCssVariables
144
+ }
145
+ });
146
+ });
147
+ Content.displayName = 'DropdownMenuContent';
148
+ const {
149
+ Group,
150
+ Label,
151
+ Item,
152
+ CheckboxItem,
153
+ RadioGroup,
154
+ RadioItem,
155
+ ItemIndicator,
156
+ SubTrigger
157
+ } = menu;
158
+ const Sub = props => {
159
+ const {
160
+ children,
161
+ open: openProp,
162
+ onOpenChange,
163
+ defaultOpen
164
+ } = props;
165
+ const [open = false, setOpen] = useControllableState({
166
+ prop: openProp,
167
+ defaultProp: defaultOpen,
168
+ onChange: onOpenChange
169
+ });
170
+ return jsx(Sub$1, {
171
+ onOpenChange: setOpen,
172
+ open: open,
173
+ children: children
174
+ });
175
+ };
176
+ Sub.displayName = 'DropdownMenuSub';
177
+ const SubContent = /*#__PURE__*/forwardRef((props, forwardedRef) => jsx(SubContent$1, {
178
+ ...props,
179
+ ref: forwardedRef,
180
+ style: {
181
+ ...props.style,
182
+ ...contentCssVariables
183
+ }
184
+ }));
185
+ SubContent.displayName = 'DropdownMenuSubContent';
186
+
187
+ export { CheckboxItem, Content, Group, Item, ItemIndicator, Label, Portal, RadioGroup, RadioItem, Root, Sub, SubContent, SubTrigger, Trigger };
@@ -0,0 +1,16 @@
1
+ import { type PrimitiveProps } from './types';
2
+ export interface FocusScopeComponentProps extends PrimitiveProps<'div'> {
3
+ /** When `true`, tabbing from the last item focuses the first one, and Shift+Tab from the first focuses the last. */
4
+ loop?: boolean;
5
+ /** When `true`, Tab and Shift+Tab can't leave the scope. */
6
+ trapped?: boolean;
7
+ /** Called when auto-focusing on mount. Can be prevented. */
8
+ onMountAutoFocus?: (event: Event) => void;
9
+ /** Called when auto-focusing on unmount. Can be prevented. */
10
+ onUnmountAutoFocus?: (event: Event) => void;
11
+ }
12
+ /**
13
+ * The Radix `FocusScope` component: a focusable `div` (or its only child with `asChild`) that manages focus
14
+ * inside it. Nested scopes pause the outer ones.
15
+ */
16
+ export declare const FocusScope: import("react").ForwardRefExoticComponent<FocusScopeComponentProps & import("react").RefAttributes<HTMLDivElement>>;
@@ -0,0 +1,41 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import { forwardRef, useState } from 'react';
3
+ import { composeEventHandlers } from '../composeEventHandlers.js';
4
+ import { useComposedRefs } from './compose-refs.js';
5
+ import { useFocusScope } from './focus-scope.js';
6
+ import { Slot } from './slot.js';
7
+
8
+ /**
9
+ * The Radix `FocusScope` component: a focusable `div` (or its only child with `asChild`) that manages focus
10
+ * inside it. Nested scopes pause the outer ones.
11
+ */
12
+ const FocusScope = /*#__PURE__*/forwardRef((props, forwardedRef) => {
13
+ const {
14
+ loop = false,
15
+ trapped = false,
16
+ onMountAutoFocus,
17
+ onUnmountAutoFocus,
18
+ asChild,
19
+ onKeyDown,
20
+ ...scopeProps
21
+ } = props;
22
+ const [container, setContainer] = useState(null);
23
+ const composedRefs = useComposedRefs(forwardedRef, setContainer);
24
+ const focusScope = useFocusScope({
25
+ container,
26
+ loop,
27
+ trapped,
28
+ onMountAutoFocus,
29
+ onUnmountAutoFocus
30
+ });
31
+ const Comp = asChild ? Slot : 'div';
32
+ return jsx(Comp, {
33
+ tabIndex: -1,
34
+ ...scopeProps,
35
+ ref: composedRefs,
36
+ onKeyDown: composeEventHandlers(onKeyDown, focusScope.onKeyDown)
37
+ });
38
+ });
39
+ FocusScope.displayName = 'FocusScope';
40
+
41
+ export { FocusScope };
@@ -0,0 +1,37 @@
1
+ import { type KeyboardEvent as ReactKeyboardEvent } from 'react';
2
+ export declare function focusElement(element?: HTMLElement | null, { select }?: {
3
+ select?: boolean | undefined;
4
+ }): void;
5
+ /**
6
+ * Focuses the first candidate that actually receives focus.
7
+ */
8
+ export declare function focusFirst(candidates: HTMLElement[], { select }?: {
9
+ select?: boolean | undefined;
10
+ }): void;
11
+ /**
12
+ * Elements inside `container` that the browser considers tabbable, in DOM order.
13
+ */
14
+ export declare function getTabbableCandidates(container: HTMLElement): HTMLElement[];
15
+ export declare function getTabbableEdges(container: HTMLElement): readonly [HTMLElement | undefined, HTMLElement | undefined];
16
+ export declare function removeLinks(items: HTMLElement[]): HTMLElement[];
17
+ export interface UseFocusScopeOptions {
18
+ /** The element focus is scoped to. Pass `null` while it isn't mounted. */
19
+ container: HTMLElement | null;
20
+ /** When `true`, tabbing from the last item focuses the first one, and Shift+Tab from the first focuses the last. */
21
+ loop?: boolean;
22
+ /** When `true`, Tab and Shift+Tab can't leave the container. */
23
+ trapped?: boolean;
24
+ /** Called when auto-focusing on mount. Call `event.preventDefault()` to prevent it. */
25
+ onMountAutoFocus?: (event: Event) => void;
26
+ /** Called when auto-focusing on unmount. Call `event.preventDefault()` to prevent it. */
27
+ onUnmountAutoFocus?: (event: Event) => void;
28
+ /** Picks the element to focus on mount. Defaults to the first tabbable element that isn't a link. */
29
+ getMountAutoFocusCandidates?: (container: HTMLElement) => HTMLElement[];
30
+ }
31
+ /**
32
+ * Focus management of the Radix `FocusScope`: initial focus, focus restore and Tab looping/trapping.
33
+ * Nested scopes pause the outer ones, so only the innermost scope handles Tab.
34
+ */
35
+ export declare function useFocusScope({ container, loop, trapped, onMountAutoFocus: onMountAutoFocusProp, onUnmountAutoFocus: onUnmountAutoFocusProp, getMountAutoFocusCandidates, }: UseFocusScopeOptions): {
36
+ onKeyDown: (event: ReactKeyboardEvent<HTMLElement>) => void;
37
+ };