akar 2.0.11 → 2.0.12

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 (157) hide show
  1. package/dist/AlertDialog/AlertDialogRoot.cjs +4 -0
  2. package/dist/AlertDialog/AlertDialogRoot.cjs.map +1 -1
  3. package/dist/AlertDialog/AlertDialogRoot.js +4 -0
  4. package/dist/AlertDialog/AlertDialogRoot.js.map +1 -1
  5. package/dist/Combobox/ComboboxContent.cjs +4 -0
  6. package/dist/Combobox/ComboboxContent.cjs.map +1 -1
  7. package/dist/Combobox/ComboboxContent.js +4 -0
  8. package/dist/Combobox/ComboboxContent.js.map +1 -1
  9. package/dist/Combobox/ComboboxContentImpl.cjs +4 -0
  10. package/dist/Combobox/ComboboxContentImpl.cjs.map +1 -1
  11. package/dist/Combobox/ComboboxContentImpl.js +4 -0
  12. package/dist/Combobox/ComboboxContentImpl.js.map +1 -1
  13. package/dist/DatePicker/DatePickerContent.cjs +4 -0
  14. package/dist/DatePicker/DatePickerContent.cjs.map +1 -1
  15. package/dist/DatePicker/DatePickerContent.js +4 -0
  16. package/dist/DatePicker/DatePickerContent.js.map +1 -1
  17. package/dist/DateRangePicker/DateRangePickerContent.cjs +4 -0
  18. package/dist/DateRangePicker/DateRangePickerContent.cjs.map +1 -1
  19. package/dist/DateRangePicker/DateRangePickerContent.js +4 -0
  20. package/dist/DateRangePicker/DateRangePickerContent.js.map +1 -1
  21. package/dist/Dialog/DialogContent.cjs +14 -9
  22. package/dist/Dialog/DialogContent.cjs.map +1 -1
  23. package/dist/Dialog/DialogContent.js +15 -10
  24. package/dist/Dialog/DialogContent.js.map +1 -1
  25. package/dist/Dialog/DialogContentImpl.cjs +8 -1
  26. package/dist/Dialog/DialogContentImpl.cjs.map +1 -1
  27. package/dist/Dialog/DialogContentImpl.js +8 -1
  28. package/dist/Dialog/DialogContentImpl.js.map +1 -1
  29. package/dist/Dialog/DialogContentModal.cjs +20 -3
  30. package/dist/Dialog/DialogContentModal.cjs.map +1 -1
  31. package/dist/Dialog/DialogContentModal.js +21 -4
  32. package/dist/Dialog/DialogContentModal.js.map +1 -1
  33. package/dist/Dialog/DialogContentNonModal.cjs +18 -2
  34. package/dist/Dialog/DialogContentNonModal.cjs.map +1 -1
  35. package/dist/Dialog/DialogContentNonModal.js +19 -3
  36. package/dist/Dialog/DialogContentNonModal.js.map +1 -1
  37. package/dist/Dialog/DialogOverlay.cjs +12 -6
  38. package/dist/Dialog/DialogOverlay.cjs.map +1 -1
  39. package/dist/Dialog/DialogOverlay.js +13 -7
  40. package/dist/Dialog/DialogOverlay.js.map +1 -1
  41. package/dist/Dialog/DialogOverlayImpl.cjs +10 -1
  42. package/dist/Dialog/DialogOverlayImpl.cjs.map +1 -1
  43. package/dist/Dialog/DialogOverlayImpl.js +11 -2
  44. package/dist/Dialog/DialogOverlayImpl.js.map +1 -1
  45. package/dist/Dialog/DialogRoot.cjs +7 -1
  46. package/dist/Dialog/DialogRoot.cjs.map +1 -1
  47. package/dist/Dialog/DialogRoot.js +7 -1
  48. package/dist/Dialog/DialogRoot.js.map +1 -1
  49. package/dist/DismissableLayer/DismissableLayer.cjs +20 -4
  50. package/dist/DismissableLayer/DismissableLayer.cjs.map +1 -1
  51. package/dist/DismissableLayer/DismissableLayer.js +20 -4
  52. package/dist/DismissableLayer/DismissableLayer.js.map +1 -1
  53. package/dist/FocusScope/FocusScope.cjs +31 -11
  54. package/dist/FocusScope/FocusScope.cjs.map +1 -1
  55. package/dist/FocusScope/FocusScope.js +32 -12
  56. package/dist/FocusScope/FocusScope.js.map +1 -1
  57. package/dist/HoverCard/HoverCardContent.cjs +4 -0
  58. package/dist/HoverCard/HoverCardContent.cjs.map +1 -1
  59. package/dist/HoverCard/HoverCardContent.js +4 -0
  60. package/dist/HoverCard/HoverCardContent.js.map +1 -1
  61. package/dist/HoverCard/HoverCardContentImpl.cjs +4 -0
  62. package/dist/HoverCard/HoverCardContentImpl.cjs.map +1 -1
  63. package/dist/HoverCard/HoverCardContentImpl.js +4 -0
  64. package/dist/HoverCard/HoverCardContentImpl.js.map +1 -1
  65. package/dist/Popover/PopoverContent.cjs +4 -0
  66. package/dist/Popover/PopoverContent.cjs.map +1 -1
  67. package/dist/Popover/PopoverContent.js +4 -0
  68. package/dist/Popover/PopoverContent.js.map +1 -1
  69. package/dist/Popover/PopoverContentImpl.cjs +4 -0
  70. package/dist/Popover/PopoverContentImpl.cjs.map +1 -1
  71. package/dist/Popover/PopoverContentImpl.js +4 -0
  72. package/dist/Popover/PopoverContentImpl.js.map +1 -1
  73. package/dist/Popover/PopoverContentModal.cjs +4 -0
  74. package/dist/Popover/PopoverContentModal.cjs.map +1 -1
  75. package/dist/Popover/PopoverContentModal.js +4 -0
  76. package/dist/Popover/PopoverContentModal.js.map +1 -1
  77. package/dist/Popover/PopoverContentNonModal.cjs +4 -0
  78. package/dist/Popover/PopoverContentNonModal.cjs.map +1 -1
  79. package/dist/Popover/PopoverContentNonModal.js +4 -0
  80. package/dist/Popover/PopoverContentNonModal.js.map +1 -1
  81. package/dist/Popper/PopperContent.cjs +14 -4
  82. package/dist/Popper/PopperContent.cjs.map +1 -1
  83. package/dist/Popper/PopperContent.js +14 -4
  84. package/dist/Popper/PopperContent.js.map +1 -1
  85. package/dist/Popper/utils.cjs +10 -5
  86. package/dist/Popper/utils.cjs.map +1 -1
  87. package/dist/Popper/utils.js +10 -5
  88. package/dist/Popper/utils.js.map +1 -1
  89. package/dist/Select/SelectContent.cjs +4 -0
  90. package/dist/Select/SelectContent.cjs.map +1 -1
  91. package/dist/Select/SelectContent.js +4 -0
  92. package/dist/Select/SelectContent.js.map +1 -1
  93. package/dist/Select/SelectContentImpl.cjs +4 -0
  94. package/dist/Select/SelectContentImpl.cjs.map +1 -1
  95. package/dist/Select/SelectContentImpl.js +4 -0
  96. package/dist/Select/SelectContentImpl.js.map +1 -1
  97. package/dist/Select/SelectPopperPosition.cjs +4 -0
  98. package/dist/Select/SelectPopperPosition.cjs.map +1 -1
  99. package/dist/Select/SelectPopperPosition.js +4 -0
  100. package/dist/Select/SelectPopperPosition.js.map +1 -1
  101. package/dist/constant/components.cjs +15 -0
  102. package/dist/constant/components.cjs.map +1 -1
  103. package/dist/constant/components.js +15 -0
  104. package/dist/constant/components.js.map +1 -1
  105. package/dist/constant.d.cts +1 -0
  106. package/dist/constant.d.cts.map +1 -1
  107. package/dist/constant.d.ts +1 -0
  108. package/dist/constant.d.ts.map +1 -1
  109. package/dist/index.cjs +0 -1
  110. package/dist/index.js +0 -1
  111. package/dist/index2.d.cts.map +1 -1
  112. package/dist/index2.d.ts.map +1 -1
  113. package/dist/index3.d.cts +1 -5
  114. package/dist/index3.d.cts.map +1 -1
  115. package/dist/index3.d.ts +16 -20
  116. package/dist/index3.d.ts.map +1 -1
  117. package/dist/index4.d.cts +706 -686
  118. package/dist/index4.d.cts.map +1 -1
  119. package/dist/index4.d.ts +706 -686
  120. package/dist/index4.d.ts.map +1 -1
  121. package/dist/internal.cjs +0 -1
  122. package/dist/internal.d.cts +2 -2
  123. package/dist/internal.d.cts.map +1 -1
  124. package/dist/internal.d.ts +2 -2
  125. package/dist/internal.d.ts.map +1 -1
  126. package/dist/internal.js +0 -1
  127. package/dist/namespaced/index.cjs +16 -0
  128. package/dist/namespaced/index.d.cts +17 -2
  129. package/dist/namespaced/index.d.mts +17 -2
  130. package/dist/namespaced/index.mjs +17 -2
  131. package/dist/nuxt/index.d.cts +2 -1
  132. package/dist/nuxt/index.d.mts +2 -1
  133. package/dist/resolver/index.d.cts +2 -1
  134. package/dist/resolver/index.d.mts +2 -1
  135. package/dist/shared.cjs +0 -2
  136. package/dist/shared.d.cts +2 -2
  137. package/dist/shared.d.ts +2 -2
  138. package/dist/shared.js +1 -2
  139. package/package.json +1 -1
  140. package/src/Dialog/DialogContent.vue +9 -1
  141. package/src/Dialog/DialogContentImpl.vue +9 -2
  142. package/src/Dialog/DialogContentModal.vue +21 -3
  143. package/src/Dialog/DialogContentNonModal.vue +22 -3
  144. package/src/Dialog/DialogOverlay.vue +4 -0
  145. package/src/Dialog/DialogOverlayImpl.vue +8 -2
  146. package/src/Dialog/DialogRoot.vue +10 -1
  147. package/src/DismissableLayer/DismissableLayer.vue +44 -8
  148. package/src/FocusScope/FocusScope.vue +82 -20
  149. package/src/Popper/PopperContent.vue +11 -3
  150. package/src/Popper/utils.ts +21 -11
  151. package/src/Tree/TreeRoot.vue +2 -2
  152. package/src/shared/index.ts +0 -1
  153. package/dist/shared/trap-focus.cjs +0 -35
  154. package/dist/shared/trap-focus.cjs.map +0 -1
  155. package/dist/shared/trap-focus.js +0 -30
  156. package/dist/shared/trap-focus.js.map +0 -1
  157. package/src/shared/trap-focus.ts +0 -44
@@ -12,6 +12,12 @@ export interface DialogRootProps {
12
12
  * interaction with outside elements will be disabled and only dialog content will be visible to screen readers.
13
13
  */
14
14
  modal?: boolean;
15
+ /**
16
+ * When set to `false`, the dialog content will not be unmounted when closed, but instead hidden with CSS. <br>
17
+ * Useful for SEO or when you want to improve performance by not remounting the component on every open.
18
+ * @defaultValue true
19
+ */
20
+ unmountOnHide?: boolean;
15
21
  }
16
22
 
17
23
  export type DialogRootEmits = {
@@ -22,6 +28,7 @@ export type DialogRootEmits = {
22
28
  export interface DialogRootContext {
23
29
  open: Readonly<Ref<boolean>>;
24
30
  modal: Ref<boolean>;
31
+ unmountOnHide: Ref<boolean>;
25
32
  openModal: () => void;
26
33
  onOpenChange: (value: boolean) => void;
27
34
  onOpenToggle: () => void;
@@ -48,6 +55,7 @@ const props = withDefaults(defineProps<DialogRootProps>(), {
48
55
  open: undefined,
49
56
  defaultOpen: false,
50
57
  modal: true,
58
+ unmountOnHide: true,
51
59
  });
52
60
  const emit = defineEmits<DialogRootEmits>();
53
61
 
@@ -67,11 +75,12 @@ const open = useVModel(props, 'open', emit, {
67
75
 
68
76
  const triggerElement = ref<HTMLElement>();
69
77
  const contentElement = ref<HTMLElement>();
70
- const { modal } = toRefs(props);
78
+ const { modal, unmountOnHide } = toRefs(props);
71
79
 
72
80
  provideDialogRootContext({
73
81
  open,
74
82
  modal,
83
+ unmountOnHide,
75
84
  openModal: () => {
76
85
  open.value = true;
77
86
  },
@@ -72,8 +72,19 @@ import {
72
72
  usePointerDownOutside,
73
73
  } from './utils';
74
74
 
75
- const props = withDefaults(defineProps<DismissableLayerProps>(), {
75
+ const props = withDefaults(defineProps<DismissableLayerProps & {
76
+ /**
77
+ * Whether the layer is currently active. A layer that stays mounted while
78
+ * hidden (e.g. a Dialog with `unmountOnHide: false`) must opt out of the
79
+ * layer stack, otherwise it would be treated as the topmost layer and
80
+ * swallow Escape / outside interactions meant for the visible one.
81
+ * Kept out of the public `DismissableLayerProps` on purpose — it is
82
+ * internal plumbing between primitives.
83
+ */
84
+ present?: boolean;
85
+ }>(), {
76
86
  disableOutsidePointerEvents: false,
87
+ present: true,
77
88
  });
78
89
 
79
90
  const emits = defineEmits<DismissableLayerPrivateEmits>();
@@ -108,7 +119,7 @@ const pointerDownOutside = usePointerDownOutside(async (event) => {
108
119
  branch?.contains(event.target as HTMLElement),
109
120
  );
110
121
 
111
- if (!isPointerEventsEnabled.value || isPointerDownOnBranch) {
122
+ if (!props.present || !isPointerEventsEnabled.value || isPointerDownOnBranch) {
112
123
  return;
113
124
  }
114
125
  emits('pointerDownOutside', event);
@@ -124,7 +135,7 @@ const focusOutside = useFocusOutside((event) => {
124
135
  branch?.contains(event.target as HTMLElement),
125
136
  );
126
137
 
127
- if (isFocusInBranch) {
138
+ if (!props.present || isFocusInBranch) {
128
139
  return;
129
140
  }
130
141
  emits('focusOutside', event);
@@ -135,6 +146,13 @@ const focusOutside = useFocusOutside((event) => {
135
146
  }, layerElement);
136
147
 
137
148
  onKeyStroke('Escape', (event) => {
149
+ // A layer that stays mounted while hidden (e.g. a Dialog with
150
+ // `unmountOnHide: false`) is out of the layer stack, so its `index` is `-1`.
151
+ // When no layer is visible (`size === 0`), `-1 === size - 1` would otherwise
152
+ // make it look like the highest layer and emit `escapeKeyDown` / `dismiss`.
153
+ if (!props.present) {
154
+ return;
155
+ }
138
156
  const isHighestLayer = index.value === layers.value.size - 1;
139
157
  if (!isHighestLayer) {
140
158
  return;
@@ -150,11 +168,11 @@ onKeyStroke('Escape', (event) => {
150
168
  // Reading `context.layersWithOutsidePointerEventsDisabled.size` inside the
151
169
  // callback must NOT make it reactive: otherwise adding/removing any other
152
170
  // layer would re-run this effect and its cleanup could prematurely restore the
153
- // body's `pointer-events` while an ancestor layer is still open.
171
+ // body's `pointer-events` while an ancestor layer is still open (#2674).
154
172
  watch(
155
- [layerElement, () => props.disableOutsidePointerEvents],
156
- ([element, disableOutsidePointerEvents], _, onCleanup) => {
157
- if (!element) {
173
+ [layerElement, () => props.disableOutsidePointerEvents, () => props.present],
174
+ ([element, disableOutsidePointerEvents, present], _, onCleanup) => {
175
+ if (!element || !present) {
158
176
  return;
159
177
  }
160
178
  if (disableOutsidePointerEvents) {
@@ -170,7 +188,7 @@ watch(
170
188
  // the unmount-only effect below — keeps the set accurate when
171
189
  // `disableOutsidePointerEvents` toggles `true -> false` while still
172
190
  // mounted (e.g. a modal Menu closing). Checking `size === 0` *after*
173
- // deletion makes the restore independent of cleanup ordering.
191
+ // deletion makes the restore independent of cleanup ordering (#2674).
174
192
  onCleanup(() => {
175
193
  context.layersWithOutsidePointerEventsDisabled.delete(element);
176
194
  if (
@@ -181,7 +199,25 @@ watch(
181
199
  }
182
200
  });
183
201
  }
202
+ },
203
+ { immediate: true },
204
+ );
205
+
206
+ // Membership in the layer stack follows presence, not mount: a hidden layer
207
+ // (e.g. a closed Dialog with `unmountOnHide: false`) must leave the stack so
208
+ // Escape and outside interactions target the layer that is actually visible.
209
+ // Kept separate from the pointer-events watch above so a
210
+ // `disableOutsidePointerEvents` toggle alone never re-orders the stack.
211
+ watch(
212
+ [layerElement, () => props.present],
213
+ ([element, present], _, onCleanup) => {
214
+ if (!element || !present) {
215
+ return;
216
+ }
184
217
  layers.value.add(element);
218
+ onCleanup(() => {
219
+ layers.value.delete(element);
220
+ });
185
221
  },
186
222
  { immediate: true },
187
223
  );
@@ -30,12 +30,22 @@ export interface FocusScopeProps extends PrimitiveProps {
30
30
  * @defaultValue false
31
31
  */
32
32
  trapped?: boolean;
33
+
34
+ /**
35
+ * Whether the scope is currently visible. Lets a consumer keep the scope
36
+ * mounted but hidden (e.g. `display: none`) and still get correct auto-focus:
37
+ * the mount auto-focus is skipped while not present, and re-runs when it
38
+ * becomes present again. Defaults to `true` so consumers that mount the scope
39
+ * only while visible are unaffected.
40
+ * @defaultValue true
41
+ */
42
+ present?: boolean;
33
43
  }
34
44
  </script>
35
45
 
36
46
  <script setup lang="ts">
37
47
  import { isClient } from '@vueuse/shared';
38
- import { nextTick, reactive, ref, watchEffect } from 'vue';
48
+ import { nextTick, reactive, ref, watch, watchEffect } from 'vue';
39
49
  import { Primitive } from '@/Primitive';
40
50
  import { createFocusScopesStack } from './stack';
41
51
  import {
@@ -157,6 +167,25 @@ watchEffect((cleanupFn) => {
157
167
  });
158
168
  });
159
169
 
170
+ // Dispatch the mount auto-focus event and move focus to the first tabbable
171
+ // candidate (or the container as a fallback). Shared by the physical-mount path
172
+ // and the visibility path below so both behave identically. Consumers (e.g.
173
+ // Dialog's `openAutoFocus`) may `preventDefault()` to opt out of default focus.
174
+ function dispatchMountAutoFocus(container: HTMLElement, previouslyFocusedElement: HTMLElement | null) {
175
+ const mountEvent = new CustomEvent(AUTOFOCUS_ON_MOUNT, EVENT_OPTIONS);
176
+ const handleMountAutoFocus = (ev: Event) => emits('mountAutoFocus', ev);
177
+ container.addEventListener(AUTOFOCUS_ON_MOUNT, handleMountAutoFocus);
178
+ container.dispatchEvent(mountEvent);
179
+ container.removeEventListener(AUTOFOCUS_ON_MOUNT, handleMountAutoFocus);
180
+
181
+ if (!mountEvent.defaultPrevented) {
182
+ focusFirst(getTabbableCandidates(container), { select: true });
183
+ if (getActiveElement() === previouslyFocusedElement) {
184
+ focus(container);
185
+ }
186
+ }
187
+ }
188
+
160
189
  watchEffect(async (cleanupFn) => {
161
190
  const container = currentElement.value;
162
191
 
@@ -164,30 +193,29 @@ watchEffect(async (cleanupFn) => {
164
193
  if (!container) {
165
194
  return;
166
195
  }
167
- focusScopesStack.add(focusScope);
196
+ // A scope that mounts hidden (`present: false`, e.g. a closed Dialog with
197
+ // `unmountOnHide: false`) must stay out of the scope stack: adding it would
198
+ // pause the currently active scope and break its focus trap. The `present`
199
+ // watcher below adds/removes it as it becomes visible.
200
+ if (props.present !== false) {
201
+ focusScopesStack.add(focusScope);
202
+ }
168
203
  const previouslyFocusedElement = getActiveElement() as HTMLElement | null;
169
204
  const hasFocusedCandidate = container.contains(previouslyFocusedElement);
170
205
 
171
- if (!hasFocusedCandidate) {
172
- const mountEvent = new CustomEvent(AUTOFOCUS_ON_MOUNT, EVENT_OPTIONS);
173
- container.addEventListener(AUTOFOCUS_ON_MOUNT, (ev: Event) =>
174
- emits('mountAutoFocus', ev));
175
- container.dispatchEvent(mountEvent);
176
-
177
- if (!mountEvent.defaultPrevented) {
178
- focusFirst(getTabbableCandidates(container), {
179
- select: true,
180
- });
181
- if (getActiveElement() === previouslyFocusedElement) {
182
- focus(container);
183
- }
184
- }
206
+ // When force-mounted while closed (e.g. Dialog `unmountOnHide: false`), the
207
+ // consumer keeps the scope mounted but flags it as not present. Skip the
208
+ // mount auto-focus in that case, otherwise it fires `mountAutoFocus` and
209
+ // steals focus into a hidden scope. The `present` watcher below re-runs the
210
+ // auto-focus once the scope becomes present again.
211
+ // NOTE: `props.present` must stay read *after* the `await` above so this
212
+ // effect does not track it — re-running on `present` changes would dispatch
213
+ // the unmount auto-focus cleanup below on every close.
214
+ if (!hasFocusedCandidate && props.present !== false) {
215
+ dispatchMountAutoFocus(container, previouslyFocusedElement);
185
216
  }
186
217
 
187
218
  cleanupFn(() => {
188
- container.removeEventListener(AUTOFOCUS_ON_MOUNT, (ev: Event) =>
189
- emits('mountAutoFocus', ev));
190
-
191
219
  const unmountEvent = new CustomEvent(AUTOFOCUS_ON_UNMOUNT, EVENT_OPTIONS);
192
220
  const unmountEventHandler = (ev: Event) => {
193
221
  emits('unmountAutoFocus', ev);
@@ -208,12 +236,46 @@ watchEffect(async (cleanupFn) => {
208
236
  container.removeEventListener(AUTOFOCUS_ON_UNMOUNT, unmountEventHandler);
209
237
 
210
238
  focusScopesStack.remove(focusScope);
211
-
212
239
  container.removeAttribute('data-focus-scope-unmounting');
213
240
  }, 0);
214
241
  });
215
242
  });
216
243
 
244
+ // Force-mounted scopes (e.g. Dialog `unmountOnHide: false`) stay mounted across
245
+ // open/close and toggle `present` instead of unmounting, so mount/unmount-keyed
246
+ // behavior must be re-keyed on `present`: stack membership (which pauses other
247
+ // scopes' traps) and the mount auto-focus (which only fires on physical mount).
248
+ // Awaiting `nextTick` lets the consumer's visibility change (e.g. `v-show`)
249
+ // apply first, so the focus targets exist. Consumers that don't pass `present`
250
+ // never hit this — it stays `undefined`.
251
+ watch(() => props.present, async (present, prevPresent) => {
252
+ if (!isClient) {
253
+ return;
254
+ }
255
+
256
+ if (present === false && prevPresent === true) {
257
+ focusScopesStack.remove(focusScope);
258
+ return;
259
+ }
260
+
261
+ if (present !== true || prevPresent !== false) {
262
+ return;
263
+ }
264
+
265
+ focusScopesStack.add(focusScope);
266
+
267
+ await nextTick();
268
+ const container = currentElement.value;
269
+ if (!container) {
270
+ return;
271
+ }
272
+
273
+ const previouslyFocusedElement = getActiveElement() as HTMLElement | null;
274
+ if (!container.contains(previouslyFocusedElement)) {
275
+ dispatchMountAutoFocus(container, previouslyFocusedElement);
276
+ }
277
+ });
278
+
217
279
  function handleKeyDown(event: KeyboardEvent) {
218
280
  if (!props.loop && !props.trapped) {
219
281
  return;
@@ -10,7 +10,8 @@ import type {
10
10
  Side,
11
11
  } from './utils';
12
12
  import type { PrimitiveProps } from '@/Primitive';
13
- import { createContext, useForwardExpose, useSize } from '@/shared';
13
+ import type { Direction } from '@/shared/types';
14
+ import { createContext, useDirection, useForwardExpose, useSize } from '@/shared';
14
15
 
15
16
  export const PopperContentPropsDefaultValue = {
16
17
  side: 'bottom' as Side,
@@ -177,6 +178,10 @@ export interface PopperContentProps extends PrimitiveProps {
177
178
  * If provided, it will replace the default anchor element.
178
179
  */
179
180
  reference?: ReferenceElement;
181
+ /**
182
+ * The reading direction of the popper content when applicable. <br> If omitted, inherits globally from `ConfigProvider` or assumes LTR (left-to-right) reading mode.
183
+ */
184
+ dir?: Direction;
180
185
  }
181
186
 
182
187
  export interface PopperContentContext {
@@ -204,7 +209,6 @@ import {
204
209
  useFloating,
205
210
  } from '@floating-ui/vue';
206
211
  import { isNumber } from '@vinicunca/perkakas';
207
- import { computedEager } from '@vueuse/core';
208
212
  import { computed, ref, watchEffect, watchPostEffect } from 'vue';
209
213
  import {
210
214
  Primitive,
@@ -229,6 +233,7 @@ const emits = defineEmits<{
229
233
 
230
234
  const rootContext = injectPopperRootContext();
231
235
  const { forwardRef, currentElement: contentElement } = useForwardExpose();
236
+ const dir = useDirection(computed(() => props.dir));
232
237
 
233
238
  const floatingRef = ref<HTMLElement>();
234
239
 
@@ -269,7 +274,7 @@ const flipOptions = computed(() => {
269
274
  };
270
275
  });
271
276
 
272
- const computedMiddleware = computedEager(() => {
277
+ const computedMiddleware = computed(() => {
273
278
  return [
274
279
  offset({
275
280
  mainAxis: props.sideOffset + arrowHeight.value,
@@ -322,6 +327,7 @@ const computedMiddleware = computedEager(() => {
322
327
  transformOrigin({
323
328
  arrowWidth: arrowWidth.value,
324
329
  arrowHeight: arrowHeight.value,
330
+ dir: dir.value,
325
331
  }),
326
332
  props.hideWhenDetached
327
333
  && hide({ strategy: 'referenceHidden', ...detectOverflowOptions.value }),
@@ -391,6 +397,7 @@ providePopperContentContext({
391
397
  <div
392
398
  ref="floatingRef"
393
399
  data-akar-popper-content-wrapper=""
400
+ :dir="dir"
394
401
  :style="{
395
402
  ...floatingStyles,
396
403
  transform: isPositioned ? floatingStyles.transform : 'translate(0, -200%)', // keep off the page when measuring
@@ -427,6 +434,7 @@ providePopperContentContext({
427
434
  :as="props.as"
428
435
  :data-side="placedSide"
429
436
  :data-align="placedAlign"
437
+ :dir="dir"
430
438
  :style="{
431
439
  // if the PopperContent hasn't been placed yet (not all measurements done)
432
440
  // we prevent animations so that users's animation don't kick in too early referring wrong sides
@@ -1,10 +1,11 @@
1
1
  import type { Middleware, Placement } from '@floating-ui/vue';
2
+ import type { Direction } from '@/shared/types';
2
3
 
3
- const SIDE_OPTIONS = ['top', 'right', 'bottom', 'left'] as const;
4
- const ALIGN_OPTIONS = ['start', 'center', 'end'] as const;
4
+ const _SIDE_OPTIONS = ['top', 'right', 'bottom', 'left'] as const;
5
+ const _ALIGN_OPTIONS = ['start', 'center', 'end'] as const;
5
6
 
6
- export type Side = (typeof SIDE_OPTIONS)[number];
7
- export type Align = (typeof ALIGN_OPTIONS)[number];
7
+ export type Side = (typeof _SIDE_OPTIONS)[number];
8
+ export type Align = (typeof _ALIGN_OPTIONS)[number];
8
9
 
9
10
  export function isNotNull<T>(value: T | null): value is T {
10
11
  return value !== null;
@@ -13,6 +14,7 @@ export function isNotNull<T>(value: T | null): value is T {
13
14
  export function transformOrigin(options: {
14
15
  arrowWidth: number;
15
16
  arrowHeight: number;
17
+ dir?: Direction;
16
18
  }): Middleware {
17
19
  return {
18
20
  name: 'transformOrigin',
@@ -26,9 +28,17 @@ export function transformOrigin(options: {
26
28
  const arrowHeight = isArrowHidden ? 0 : options.arrowHeight;
27
29
 
28
30
  const [placedSide, placedAlign] = getSideAndAlignFromPlacement(placement);
29
- const noArrowAlign = { start: '0%', center: '50%', end: '100%' }[
30
- placedAlign
31
- ];
31
+ const noArrowAlignX = {
32
+ start: options.dir === 'rtl' ? '100%' : '0%',
33
+ center: '50%',
34
+ end: options.dir === 'rtl' ? '0%' : '100%',
35
+ }[placedAlign];
36
+
37
+ const noArrowAlignY = {
38
+ start: '0%',
39
+ center: '50%',
40
+ end: '100%',
41
+ }[placedAlign];
32
42
 
33
43
  const arrowXCenter = (middlewareData.arrow?.x ?? 0) + arrowWidth / 2;
34
44
  const arrowYCenter = (middlewareData.arrow?.y ?? 0) + arrowHeight / 2;
@@ -37,17 +47,17 @@ export function transformOrigin(options: {
37
47
  let y = '';
38
48
 
39
49
  if (placedSide === 'bottom') {
40
- x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;
50
+ x = isArrowHidden ? noArrowAlignX : `${arrowXCenter}px`;
41
51
  y = `${-arrowHeight}px`;
42
52
  } else if (placedSide === 'top') {
43
- x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;
53
+ x = isArrowHidden ? noArrowAlignX : `${arrowXCenter}px`;
44
54
  y = `${rects.floating.height + arrowHeight}px`;
45
55
  } else if (placedSide === 'right') {
46
56
  x = `${-arrowHeight}px`;
47
- y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;
57
+ y = isArrowHidden ? noArrowAlignY : `${arrowYCenter}px`;
48
58
  } else if (placedSide === 'left') {
49
59
  x = `${rects.floating.width + arrowHeight}px`;
50
- y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;
60
+ y = isArrowHidden ? noArrowAlignY : `${arrowYCenter}px`;
51
61
  }
52
62
  return { data: { x, y } };
53
63
  },
@@ -26,9 +26,9 @@ export interface TreeRootProps<T = Record<string, any>, U extends Record<string,
26
26
  dir?: Direction;
27
27
  /** When `true`, prevents the user from interacting with tree */
28
28
  disabled?: boolean;
29
- /** When `true`, selecting parent will select the descendants. */
29
+ /** When `true`, selecting parent will select the descendants. Requires `multiple` to be `true`. */
30
30
  propagateSelect?: boolean;
31
- /** When `true`, selecting children will update the parent state. */
31
+ /** When `true`, selecting children will update the parent state. Requires `multiple` to be `true`. */
32
32
  bubbleSelect?: boolean;
33
33
  }
34
34
 
@@ -8,7 +8,6 @@ export { isValidVNodeElement } from './isValidVNodeElement';
8
8
  export { isValueEqualOrExist } from './isValueEqualOrExist';
9
9
  export { onFocusOutside } from './onFocusOutside';
10
10
  export { renderSlotFragments } from './renderSlotFragments';
11
- export { trapFocus } from './trap-focus';
12
11
  export { useArrowNavigation } from './useArrowNavigation';
13
12
  export { useBodyScrollLock } from './useBodyScrollLock';
14
13
  export { useComposing } from './useComposing';
@@ -1,35 +0,0 @@
1
- const require_shared_getActiveElement = require('./getActiveElement.cjs');
2
-
3
- //#region src/shared/trap-focus.ts
4
- function trapFocus(element) {
5
- if (element) {
6
- const focusableEls = [...Array.from(element.querySelectorAll("a[href], button, input, textarea, select, details,[tabindex]:not([tabindex=\"-1\"])"))].filter((el) => !el.hasAttribute("disabled") && !el.getAttribute("aria-hidden"));
7
- const firstFocusableEl = focusableEls[0];
8
- const lastFocusableEl = focusableEls.at(-1);
9
- const KEYCODE_TAB = 9;
10
- if (firstFocusableEl) firstFocusableEl.focus();
11
- element.addEventListener("keydown", (e) => {
12
- const isTabPressed = e.key === "Tab" || e.keyCode === KEYCODE_TAB;
13
- if (!isTabPressed) return;
14
- if (e.shiftKey) {
15
- if (require_shared_getActiveElement.getActiveElement() === firstFocusableEl) {
16
- lastFocusableEl.focus();
17
- e.preventDefault();
18
- }
19
- } else if (require_shared_getActiveElement.getActiveElement() === lastFocusableEl) {
20
- firstFocusableEl.focus();
21
- e.preventDefault();
22
- }
23
- });
24
- return firstFocusableEl;
25
- }
26
- }
27
-
28
- //#endregion
29
- Object.defineProperty(exports, 'trapFocus', {
30
- enumerable: true,
31
- get: function () {
32
- return trapFocus;
33
- }
34
- });
35
- //# sourceMappingURL=trap-focus.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"trap-focus.cjs","names":["element: HTMLElement"],"sources":["../../src/shared/trap-focus.ts"],"sourcesContent":[],"mappings":";;;AAEA,SAAgB,UAAUA,SAAsB;AAC9C,KAAI,SAAS;EACX,MAAM,eAAe,CACnB,GAAG,MAAM,KACP,QAAQ,iBACN,sFACD,CACF,AACF,EAAC,OACA,CAAC,QAAQ,GAAG,aAAa,WAAW,KAAK,GAAG,aAAa,cAAc,CACxE;EACD,MAAM,mBAAmB,aAAa;EACtC,MAAM,kBAAkB,aAAa,GAAG,GAAG;EAC3C,MAAM,cAAc;AAEpB,MAAI,iBACF,kBAAiB,OAAO;AAG1B,UAAQ,iBAAiB,WAAW,CAAC,MAAM;GACzC,MAAM,eAAe,EAAE,QAAQ,SAAS,EAAE,YAAY;AAEtD,QAAK,aACH;AAGF,OAAI,EAAE,UACc;QAAI,kDAAkB,KAAK,kBAAkB;AAC7D,qBAAgB,OAAO;AACvB,OAAE,gBAAgB;IACnB;cAGG,kDAAkB,KAAK,iBAAiB;AAC1C,qBAAiB,OAAO;AACxB,MAAE,gBAAgB;GACnB;EAEJ,EAAC;AACF,SAAO;CACR;AACF"}
@@ -1,30 +0,0 @@
1
- import { getActiveElement } from "./getActiveElement.js";
2
-
3
- //#region src/shared/trap-focus.ts
4
- function trapFocus(element) {
5
- if (element) {
6
- const focusableEls = [...Array.from(element.querySelectorAll("a[href], button, input, textarea, select, details,[tabindex]:not([tabindex=\"-1\"])"))].filter((el) => !el.hasAttribute("disabled") && !el.getAttribute("aria-hidden"));
7
- const firstFocusableEl = focusableEls[0];
8
- const lastFocusableEl = focusableEls.at(-1);
9
- const KEYCODE_TAB = 9;
10
- if (firstFocusableEl) firstFocusableEl.focus();
11
- element.addEventListener("keydown", (e) => {
12
- const isTabPressed = e.key === "Tab" || e.keyCode === KEYCODE_TAB;
13
- if (!isTabPressed) return;
14
- if (e.shiftKey) {
15
- if (getActiveElement() === firstFocusableEl) {
16
- lastFocusableEl.focus();
17
- e.preventDefault();
18
- }
19
- } else if (getActiveElement() === lastFocusableEl) {
20
- firstFocusableEl.focus();
21
- e.preventDefault();
22
- }
23
- });
24
- return firstFocusableEl;
25
- }
26
- }
27
-
28
- //#endregion
29
- export { trapFocus };
30
- //# sourceMappingURL=trap-focus.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"trap-focus.js","names":["element: HTMLElement"],"sources":["../../src/shared/trap-focus.ts"],"sourcesContent":[],"mappings":";;;AAEA,SAAgB,UAAUA,SAAsB;AAC9C,KAAI,SAAS;EACX,MAAM,eAAe,CACnB,GAAG,MAAM,KACP,QAAQ,iBACN,sFACD,CACF,AACF,EAAC,OACA,CAAC,QAAQ,GAAG,aAAa,WAAW,KAAK,GAAG,aAAa,cAAc,CACxE;EACD,MAAM,mBAAmB,aAAa;EACtC,MAAM,kBAAkB,aAAa,GAAG,GAAG;EAC3C,MAAM,cAAc;AAEpB,MAAI,iBACF,kBAAiB,OAAO;AAG1B,UAAQ,iBAAiB,WAAW,CAAC,MAAM;GACzC,MAAM,eAAe,EAAE,QAAQ,SAAS,EAAE,YAAY;AAEtD,QAAK,aACH;AAGF,OAAI,EAAE,UACc;QAAI,kBAAkB,KAAK,kBAAkB;AAC7D,qBAAgB,OAAO;AACvB,OAAE,gBAAgB;IACnB;cAGG,kBAAkB,KAAK,iBAAiB;AAC1C,qBAAiB,OAAO;AACxB,MAAE,gBAAgB;GACnB;EAEJ,EAAC;AACF,SAAO;CACR;AACF"}
@@ -1,44 +0,0 @@
1
- import { getActiveElement } from './getActiveElement';
2
-
3
- export function trapFocus(element: HTMLElement) {
4
- if (element) {
5
- const focusableEls = [
6
- ...Array.from(
7
- element.querySelectorAll(
8
- 'a[href], button, input, textarea, select, details,[tabindex]:not([tabindex="-1"])',
9
- ),
10
- ),
11
- ].filter(
12
- (el) => !el.hasAttribute('disabled') && !el.getAttribute('aria-hidden'),
13
- );
14
- const firstFocusableEl = focusableEls[0] as HTMLElement;
15
- const lastFocusableEl = focusableEls.at(-1) as HTMLElement;
16
- const KEYCODE_TAB = 9;
17
-
18
- if (firstFocusableEl) {
19
- firstFocusableEl.focus();
20
- }
21
-
22
- element.addEventListener('keydown', (e) => {
23
- const isTabPressed = e.key === 'Tab' || e.keyCode === KEYCODE_TAB;
24
-
25
- if (!isTabPressed) {
26
- return;
27
- }
28
-
29
- if (e.shiftKey) {
30
- /* shift + tab */ if (getActiveElement() === firstFocusableEl) {
31
- lastFocusableEl.focus();
32
- e.preventDefault();
33
- }
34
- } else {
35
- /* tab */
36
- if (getActiveElement() === lastFocusableEl) {
37
- firstFocusableEl.focus();
38
- e.preventDefault();
39
- }
40
- }
41
- });
42
- return firstFocusableEl;
43
- }
44
- }