akar 2.0.15 → 2.0.17

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 (249) hide show
  1. package/dist/Autocomplete/AutocompleteRoot.cjs +3 -0
  2. package/dist/Autocomplete/AutocompleteRoot.cjs.map +1 -1
  3. package/dist/Autocomplete/AutocompleteRoot.js +3 -0
  4. package/dist/Autocomplete/AutocompleteRoot.js.map +1 -1
  5. package/dist/Calendar/CalendarCell.cjs +1 -1
  6. package/dist/Calendar/CalendarCell.js +1 -1
  7. package/dist/Calendar/CalendarCellTrigger.cjs +2 -2
  8. package/dist/Calendar/CalendarCellTrigger.js +2 -2
  9. package/dist/Calendar/CalendarRoot.cjs +10 -6
  10. package/dist/Calendar/CalendarRoot.cjs.map +1 -1
  11. package/dist/Calendar/CalendarRoot.js +10 -6
  12. package/dist/Calendar/CalendarRoot.js.map +1 -1
  13. package/dist/Collection/Collection.cjs +6 -0
  14. package/dist/Collection/Collection.cjs.map +1 -1
  15. package/dist/Collection/Collection.js +6 -0
  16. package/dist/Collection/Collection.js.map +1 -1
  17. package/dist/Combobox/ComboboxContentImpl.cjs +5 -1
  18. package/dist/Combobox/ComboboxContentImpl.cjs.map +1 -1
  19. package/dist/Combobox/ComboboxContentImpl.js +6 -2
  20. package/dist/Combobox/ComboboxContentImpl.js.map +1 -1
  21. package/dist/Combobox/ComboboxRoot.cjs +9 -2
  22. package/dist/Combobox/ComboboxRoot.cjs.map +1 -1
  23. package/dist/Combobox/ComboboxRoot.js +9 -2
  24. package/dist/Combobox/ComboboxRoot.js.map +1 -1
  25. package/dist/Combobox/useComboboxContentPositioning.cjs +54 -0
  26. package/dist/Combobox/useComboboxContentPositioning.cjs.map +1 -0
  27. package/dist/Combobox/useComboboxContentPositioning.js +48 -0
  28. package/dist/Combobox/useComboboxContentPositioning.js.map +1 -0
  29. package/dist/DateField/DateFieldRoot.cjs +6 -6
  30. package/dist/DateField/DateFieldRoot.js +6 -6
  31. package/dist/DatePicker/DatePickerCell.cjs +1 -1
  32. package/dist/DatePicker/DatePickerCell.js +1 -1
  33. package/dist/DatePicker/DatePickerCellTrigger.cjs +2 -2
  34. package/dist/DatePicker/DatePickerCellTrigger.js +2 -2
  35. package/dist/DatePicker/DatePickerRoot.cjs +6 -6
  36. package/dist/DatePicker/DatePickerRoot.js +6 -6
  37. package/dist/DateRangeField/DateRangeFieldRoot.cjs +4 -4
  38. package/dist/DateRangeField/DateRangeFieldRoot.js +4 -4
  39. package/dist/DateRangePicker/DateRangePickerCell.cjs +1 -1
  40. package/dist/DateRangePicker/DateRangePickerCell.js +1 -1
  41. package/dist/DateRangePicker/DateRangePickerCellTrigger.cjs +2 -2
  42. package/dist/DateRangePicker/DateRangePickerCellTrigger.js +2 -2
  43. package/dist/DateRangePicker/DateRangePickerRoot.cjs +4 -4
  44. package/dist/DateRangePicker/DateRangePickerRoot.js +4 -4
  45. package/dist/Dialog/DialogContent.cjs +7 -6
  46. package/dist/Dialog/DialogContent.cjs.map +1 -1
  47. package/dist/Dialog/DialogContent.js +8 -7
  48. package/dist/Dialog/DialogContent.js.map +1 -1
  49. package/dist/Dialog/DialogOverlay.cjs +6 -4
  50. package/dist/Dialog/DialogOverlay.cjs.map +1 -1
  51. package/dist/Dialog/DialogOverlay.js +7 -5
  52. package/dist/Dialog/DialogOverlay.js.map +1 -1
  53. package/dist/DismissableLayer/DismissableLayer.cjs +1 -1
  54. package/dist/DismissableLayer/DismissableLayer.cjs.map +1 -1
  55. package/dist/DismissableLayer/DismissableLayer.js +1 -1
  56. package/dist/DismissableLayer/DismissableLayer.js.map +1 -1
  57. package/dist/DismissableLayer/DismissableLayerBranch.cjs +7 -2
  58. package/dist/DismissableLayer/DismissableLayerBranch.cjs.map +1 -1
  59. package/dist/DismissableLayer/DismissableLayerBranch.js +7 -2
  60. package/dist/DismissableLayer/DismissableLayerBranch.js.map +1 -1
  61. package/dist/DismissableLayer/utils.cjs +2 -0
  62. package/dist/DismissableLayer/utils.cjs.map +1 -1
  63. package/dist/DismissableLayer/utils.js +2 -0
  64. package/dist/DismissableLayer/utils.js.map +1 -1
  65. package/dist/Drawer/DrawerContent.cjs +11 -4
  66. package/dist/Drawer/DrawerContent.cjs.map +1 -1
  67. package/dist/Drawer/DrawerContent.js +11 -4
  68. package/dist/Drawer/DrawerContent.js.map +1 -1
  69. package/dist/Drawer/DrawerContentImpl.cjs +16 -4
  70. package/dist/Drawer/DrawerContentImpl.cjs.map +1 -1
  71. package/dist/Drawer/DrawerContentImpl.js +16 -4
  72. package/dist/Drawer/DrawerContentImpl.js.map +1 -1
  73. package/dist/Drawer/DrawerRoot.cjs +12 -9
  74. package/dist/Drawer/DrawerRoot.cjs.map +1 -1
  75. package/dist/Drawer/DrawerRoot.js +12 -9
  76. package/dist/Drawer/DrawerRoot.js.map +1 -1
  77. package/dist/Drawer/DrawerTrigger.cjs +3 -2
  78. package/dist/Drawer/DrawerTrigger.cjs.map +1 -1
  79. package/dist/Drawer/DrawerTrigger.js +3 -2
  80. package/dist/Drawer/DrawerTrigger.js.map +1 -1
  81. package/dist/FocusScope/FocusScope.cjs +2 -0
  82. package/dist/FocusScope/FocusScope.cjs.map +1 -1
  83. package/dist/FocusScope/FocusScope.js +2 -0
  84. package/dist/FocusScope/FocusScope.js.map +1 -1
  85. package/dist/Listbox/ListboxItem.cjs +2 -1
  86. package/dist/Listbox/ListboxItem.cjs.map +1 -1
  87. package/dist/Listbox/ListboxItem.js +2 -1
  88. package/dist/Listbox/ListboxItem.js.map +1 -1
  89. package/dist/Listbox/ListboxRoot.cjs +22 -4
  90. package/dist/Listbox/ListboxRoot.cjs.map +1 -1
  91. package/dist/Listbox/ListboxRoot.js +17 -5
  92. package/dist/Listbox/ListboxRoot.js.map +1 -1
  93. package/dist/Listbox/ListboxVirtualizer.cjs +2 -2
  94. package/dist/Listbox/ListboxVirtualizer.cjs.map +1 -1
  95. package/dist/Listbox/ListboxVirtualizer.js +2 -2
  96. package/dist/Listbox/ListboxVirtualizer.js.map +1 -1
  97. package/dist/Menu/MenuItemImpl.cjs +2 -1
  98. package/dist/Menu/MenuItemImpl.cjs.map +1 -1
  99. package/dist/Menu/MenuItemImpl.js +2 -1
  100. package/dist/Menu/MenuItemImpl.js.map +1 -1
  101. package/dist/MonthPicker/MonthPickerCell.cjs +1 -1
  102. package/dist/MonthPicker/MonthPickerCell.js +1 -1
  103. package/dist/MonthPicker/MonthPickerCellTrigger.cjs +1 -1
  104. package/dist/MonthPicker/MonthPickerCellTrigger.js +1 -1
  105. package/dist/MonthPicker/MonthPickerRoot.cjs +10 -6
  106. package/dist/MonthPicker/MonthPickerRoot.cjs.map +1 -1
  107. package/dist/MonthPicker/MonthPickerRoot.js +10 -6
  108. package/dist/MonthPicker/MonthPickerRoot.js.map +1 -1
  109. package/dist/MonthRangePicker/MonthRangePickerCell.cjs +1 -1
  110. package/dist/MonthRangePicker/MonthRangePickerCell.js +1 -1
  111. package/dist/MonthRangePicker/MonthRangePickerCellTrigger.cjs +1 -1
  112. package/dist/MonthRangePicker/MonthRangePickerCellTrigger.js +1 -1
  113. package/dist/MonthRangePicker/MonthRangePickerRoot.cjs +4 -4
  114. package/dist/MonthRangePicker/MonthRangePickerRoot.js +4 -4
  115. package/dist/PinInput/PinInputInput.cjs +29 -6
  116. package/dist/PinInput/PinInputInput.cjs.map +1 -1
  117. package/dist/PinInput/PinInputInput.js +29 -6
  118. package/dist/PinInput/PinInputInput.js.map +1 -1
  119. package/dist/Popover/PopoverTrigger.cjs +2 -1
  120. package/dist/Popover/PopoverTrigger.cjs.map +1 -1
  121. package/dist/Popover/PopoverTrigger.js +2 -1
  122. package/dist/Popover/PopoverTrigger.js.map +1 -1
  123. package/dist/RadioGroup/Radio.cjs +1 -1
  124. package/dist/RadioGroup/Radio.cjs.map +1 -1
  125. package/dist/RadioGroup/Radio.js +1 -1
  126. package/dist/RadioGroup/Radio.js.map +1 -1
  127. package/dist/RangeCalendar/RangeCalendarCell.cjs +1 -1
  128. package/dist/RangeCalendar/RangeCalendarCell.js +1 -1
  129. package/dist/RangeCalendar/RangeCalendarCellTrigger.cjs +2 -2
  130. package/dist/RangeCalendar/RangeCalendarCellTrigger.js +2 -2
  131. package/dist/RangeCalendar/RangeCalendarRoot.cjs +4 -4
  132. package/dist/RangeCalendar/RangeCalendarRoot.js +4 -4
  133. package/dist/Rating/RatingItemIndicator.cjs +2 -1
  134. package/dist/Rating/RatingItemIndicator.cjs.map +1 -1
  135. package/dist/Rating/RatingItemIndicator.js +2 -1
  136. package/dist/Rating/RatingItemIndicator.js.map +1 -1
  137. package/dist/Select/SelectTrigger.cjs +1 -1
  138. package/dist/Select/SelectTrigger.cjs.map +1 -1
  139. package/dist/Select/SelectTrigger.js +1 -1
  140. package/dist/Select/SelectTrigger.js.map +1 -1
  141. package/dist/Tooltip/TooltipContentHoverable.cjs +11 -0
  142. package/dist/Tooltip/TooltipContentHoverable.cjs.map +1 -1
  143. package/dist/Tooltip/TooltipContentHoverable.js +11 -0
  144. package/dist/Tooltip/TooltipContentHoverable.js.map +1 -1
  145. package/dist/Tooltip/TooltipContentImpl.cjs +1 -1
  146. package/dist/Tooltip/TooltipContentImpl.cjs.map +1 -1
  147. package/dist/Tooltip/TooltipContentImpl.js +1 -1
  148. package/dist/Tooltip/TooltipContentImpl.js.map +1 -1
  149. package/dist/Tooltip/TooltipTrigger.cjs +4 -4
  150. package/dist/Tooltip/TooltipTrigger.cjs.map +1 -1
  151. package/dist/Tooltip/TooltipTrigger.js +5 -5
  152. package/dist/Tooltip/TooltipTrigger.js.map +1 -1
  153. package/dist/Tree/TreeItem.cjs +2 -2
  154. package/dist/Tree/TreeItem.cjs.map +1 -1
  155. package/dist/Tree/TreeItem.js +2 -2
  156. package/dist/Tree/TreeItem.js.map +1 -1
  157. package/dist/Tree/TreeRoot.cjs +21 -1
  158. package/dist/Tree/TreeRoot.cjs.map +1 -1
  159. package/dist/Tree/TreeRoot.js +21 -1
  160. package/dist/Tree/TreeRoot.js.map +1 -1
  161. package/dist/YearPicker/YearPickerCell.cjs +1 -1
  162. package/dist/YearPicker/YearPickerCell.js +1 -1
  163. package/dist/YearPicker/YearPickerCellTrigger.cjs +1 -1
  164. package/dist/YearPicker/YearPickerCellTrigger.js +1 -1
  165. package/dist/YearPicker/YearPickerRoot.cjs +10 -6
  166. package/dist/YearPicker/YearPickerRoot.cjs.map +1 -1
  167. package/dist/YearPicker/YearPickerRoot.js +10 -6
  168. package/dist/YearPicker/YearPickerRoot.js.map +1 -1
  169. package/dist/YearRangePicker/YearRangePickerCell.cjs +1 -1
  170. package/dist/YearRangePicker/YearRangePickerCell.js +1 -1
  171. package/dist/YearRangePicker/YearRangePickerCellTrigger.cjs +1 -1
  172. package/dist/YearRangePicker/YearRangePickerCellTrigger.js +1 -1
  173. package/dist/YearRangePicker/YearRangePickerRoot.cjs +4 -4
  174. package/dist/YearRangePicker/YearRangePickerRoot.js +4 -4
  175. package/dist/composables/useSwipeDismiss.cjs +47 -0
  176. package/dist/composables/useSwipeDismiss.cjs.map +1 -1
  177. package/dist/composables/useSwipeDismiss.js +47 -0
  178. package/dist/composables/useSwipeDismiss.js.map +1 -1
  179. package/dist/constant.d.cts.map +1 -1
  180. package/dist/date/comparators.cjs.map +1 -1
  181. package/dist/date/comparators.js.map +1 -1
  182. package/dist/index.cjs +1 -0
  183. package/dist/index.js +1 -0
  184. package/dist/index3.d.cts +26 -1
  185. package/dist/index3.d.cts.map +1 -1
  186. package/dist/index3.d.ts +26 -1
  187. package/dist/index3.d.ts.map +1 -1
  188. package/dist/index4.d.cts +660 -654
  189. package/dist/index4.d.cts.map +1 -1
  190. package/dist/index4.d.ts +684 -678
  191. package/dist/index4.d.ts.map +1 -1
  192. package/dist/internal.d.cts +2 -2
  193. package/dist/internal.d.cts.map +1 -1
  194. package/dist/internal.d.ts +2 -2
  195. package/dist/shared/useEmitAsProps.cjs +1 -0
  196. package/dist/shared/useEmitAsProps.cjs.map +1 -1
  197. package/dist/shared/useEmitAsProps.js +1 -0
  198. package/dist/shared/useEmitAsProps.js.map +1 -1
  199. package/dist/shared/useFilter.cjs +4 -5
  200. package/dist/shared/useFilter.cjs.map +1 -1
  201. package/dist/shared/useFilter.js +4 -5
  202. package/dist/shared/useFilter.js.map +1 -1
  203. package/dist/shared/useGraceArea.cjs +11 -8
  204. package/dist/shared/useGraceArea.cjs.map +1 -1
  205. package/dist/shared/useGraceArea.js +11 -8
  206. package/dist/shared/useGraceArea.js.map +1 -1
  207. package/dist/utils/registry.cjs +11 -0
  208. package/dist/utils/registry.cjs.map +1 -1
  209. package/dist/utils/registry.js +11 -0
  210. package/dist/utils/registry.js.map +1 -1
  211. package/package.json +10 -12
  212. package/src/Autocomplete/AutocompleteRoot.vue +3 -0
  213. package/src/Collection/Collection.ts +10 -1
  214. package/src/Combobox/ComboboxContentImpl.vue +11 -1
  215. package/src/Combobox/ComboboxRoot.vue +12 -2
  216. package/src/Combobox/useComboboxContentPositioning.ts +59 -0
  217. package/src/Dialog/DialogContent.vue +17 -6
  218. package/src/Dialog/DialogOverlay.vue +13 -5
  219. package/src/DismissableLayer/DismissableLayer.vue +6 -1
  220. package/src/DismissableLayer/DismissableLayerBranch.vue +11 -2
  221. package/src/DismissableLayer/utils.ts +16 -0
  222. package/src/Drawer/DrawerContent.vue +19 -3
  223. package/src/Drawer/DrawerContentImpl.vue +22 -2
  224. package/src/Drawer/DrawerRoot.vue +15 -11
  225. package/src/Drawer/DrawerTrigger.vue +1 -1
  226. package/src/Drawer/composables/useSwipeDismiss.ts +88 -0
  227. package/src/DropdownMenu/DropdownMenuFilter.vue +1 -1
  228. package/src/FocusScope/FocusScope.vue +11 -0
  229. package/src/Listbox/ListboxItem.vue +1 -1
  230. package/src/Listbox/ListboxRoot.vue +36 -4
  231. package/src/Listbox/ListboxVirtualizer.vue +3 -4
  232. package/src/Menu/MenuItemImpl.vue +2 -1
  233. package/src/PinInput/PinInputInput.vue +54 -16
  234. package/src/PinInput/PinInputRoot.vue +5 -5
  235. package/src/Popover/PopoverTrigger.vue +2 -1
  236. package/src/RadioGroup/Radio.vue +1 -1
  237. package/src/Rating/RatingItemIndicator.vue +11 -1
  238. package/src/Select/SelectTrigger.vue +1 -1
  239. package/src/Splitter/utils/registry.ts +22 -0
  240. package/src/Tooltip/TooltipContentHoverable.vue +26 -0
  241. package/src/Tooltip/TooltipContentImpl.vue +1 -1
  242. package/src/Tooltip/TooltipTrigger.vue +9 -5
  243. package/src/Tree/TreeItem.vue +2 -2
  244. package/src/Tree/TreeRoot.vue +24 -1
  245. package/src/shared/date/comparators.ts +2 -2
  246. package/src/shared/useEmitAsProps.test-d.ts +34 -1
  247. package/src/shared/useEmitAsProps.ts +52 -8
  248. package/src/shared/useFilter.ts +14 -4
  249. package/src/shared/useGraceArea.ts +11 -8
@@ -0,0 +1,59 @@
1
+ import type { Ref } from 'vue';
2
+ import { computed, ref } from 'vue';
3
+ import { provideListboxHighlightScrollContext } from '@/Listbox/ListboxRoot.vue';
4
+
5
+ export function useComboboxContentPositioning(
6
+ open: Readonly<Ref<boolean>>,
7
+ ) {
8
+ const contentPosition = ref<'inline' | 'popper'>('inline');
9
+ const contentPlaced = ref(false);
10
+ const currentContent = ref<symbol>();
11
+ const suppressHighlightScroll = computed(() => contentPosition.value === 'popper' && !contentPlaced.value);
12
+ let pendingHighlightScroll: (() => void) | undefined;
13
+
14
+ provideListboxHighlightScrollContext({
15
+ suppressHighlightScroll,
16
+ onHighlightScrollRequest(scroll) {
17
+ pendingHighlightScroll = scroll;
18
+ },
19
+ });
20
+
21
+ function onContentPositionChange(content: symbol, position: 'inline' | 'popper') {
22
+ if (currentContent.value !== content || contentPosition.value !== position) {
23
+ contentPlaced.value = false;
24
+ pendingHighlightScroll = undefined;
25
+ }
26
+ currentContent.value = content;
27
+ contentPosition.value = position;
28
+ }
29
+
30
+ function onContentPlaced(content: symbol) {
31
+ if (currentContent.value !== content || contentPosition.value !== 'popper' || contentPlaced.value) {
32
+ return;
33
+ }
34
+
35
+ contentPlaced.value = true;
36
+ const scroll = pendingHighlightScroll;
37
+ pendingHighlightScroll = undefined;
38
+ if (open.value) {
39
+ scroll?.();
40
+ }
41
+ }
42
+
43
+ function onContentUnmount(content: symbol) {
44
+ if (currentContent.value !== content) {
45
+ return;
46
+ }
47
+
48
+ currentContent.value = undefined;
49
+ contentPosition.value = 'inline';
50
+ contentPlaced.value = false;
51
+ pendingHighlightScroll = undefined;
52
+ }
53
+
54
+ return {
55
+ onContentPositionChange,
56
+ onContentPlaced,
57
+ onContentUnmount,
58
+ };
59
+ }
@@ -16,6 +16,7 @@ export interface DialogContentProps extends Omit<DialogContentImplProps, 'trapFo
16
16
  </script>
17
17
 
18
18
  <script setup lang="ts">
19
+ import { computed } from 'vue';
19
20
  import { Presence } from '@/Presence';
20
21
  import { useEmitAsProps, useForwardExpose } from '@/shared';
21
22
  import DialogContentModal from './DialogContentModal.vue';
@@ -38,28 +39,38 @@ const rootContext = injectDialogRootContext();
38
39
 
39
40
  const emitsAsProps = useEmitAsProps(emits);
40
41
  const { forwardRef } = useForwardExpose();
42
+
43
+ // The node stays in the DOM across open/close when force-mounted, or when the
44
+ // root opts out of unmounting. Only then does the child need the real presence
45
+ // state: mount-keyed behaviour (`FocusScope`'s auto-focus, layer stacks) has to
46
+ // be re-keyed on `present` because no physical unmount happens. When the node
47
+ // does unmount on close, keep passing a constant `true` so the child is never
48
+ // briefly told it is absent while `usePresence` settles on `MOUNT`.
49
+ const staysMounted = computed(
50
+ () => props.forceMount || !rootContext.unmountOnHide.value,
51
+ );
41
52
  </script>
42
53
 
43
54
  <template>
44
55
  <Presence
45
56
  v-slot="{ present }"
46
- :present="forceMount || rootContext.open.value"
47
- :force-mount="forceMount || !rootContext.unmountOnHide.value"
57
+ :present="rootContext.open.value"
58
+ :force-mount="staysMounted"
48
59
  >
49
60
  <DialogContentModal
50
61
  v-if="rootContext.modal.value"
51
- v-show="rootContext.unmountOnHide.value || present"
62
+ v-show="forceMount || rootContext.unmountOnHide.value || present"
52
63
  :ref="forwardRef"
53
- :present="rootContext.unmountOnHide.value || present"
64
+ :present="staysMounted ? present : true"
54
65
  v-bind="{ ...props, ...emitsAsProps, ...$attrs }"
55
66
  >
56
67
  <slot />
57
68
  </DialogContentModal>
58
69
  <DialogContentNonModal
59
70
  v-else
60
- v-show="rootContext.unmountOnHide.value || present"
71
+ v-show="forceMount || rootContext.unmountOnHide.value || present"
61
72
  :ref="forwardRef"
62
- :present="rootContext.unmountOnHide.value || present"
73
+ :present="staysMounted ? present : true"
63
74
  v-bind="{ ...props, ...emitsAsProps, ...$attrs }"
64
75
  >
65
76
  <slot />
@@ -13,29 +13,37 @@ export interface DialogOverlayProps extends DialogOverlayImplProps {
13
13
  </script>
14
14
 
15
15
  <script setup lang="ts">
16
+ import { computed } from 'vue';
16
17
  import { Presence } from '@/Presence';
17
18
  import { injectDialogRootContext } from './DialogRoot.vue';
18
19
 
19
- defineProps<DialogOverlayProps>();
20
+ const props = defineProps<DialogOverlayProps>();
20
21
  const rootContext = injectDialogRootContext();
21
22
 
22
23
  const { forwardRef } = useForwardExpose();
24
+
25
+ // See `DialogContent.vue`: when the overlay is kept mounted across open/close it
26
+ // must report the real presence state, otherwise `DialogOverlayImpl` keeps the
27
+ // body scroll locked after the dialog is dismissed.
28
+ const staysMounted = computed(
29
+ () => props.forceMount || !rootContext.unmountOnHide.value,
30
+ );
23
31
  </script>
24
32
 
25
33
  <template>
26
34
  <Presence
27
35
  v-if="rootContext?.modal.value"
28
36
  v-slot="{ present }"
29
- :present="forceMount || rootContext.open.value"
30
- :force-mount="forceMount || !rootContext.unmountOnHide.value"
37
+ :present="rootContext.open.value"
38
+ :force-mount="staysMounted"
31
39
  >
32
40
  <DialogOverlayImpl
33
- v-show="rootContext.unmountOnHide.value || present"
41
+ v-show="forceMount || rootContext.unmountOnHide.value || present"
34
42
  v-bind="$attrs"
35
43
  :ref="forwardRef"
36
44
  :as="as"
37
45
  :as-child="asChild"
38
- :present="rootContext.unmountOnHide.value || present"
46
+ :present="staysMounted ? present : true"
39
47
  >
40
48
  <slot />
41
49
  </DialogOverlayImpl>
@@ -109,6 +109,11 @@ const isPointerEventsEnabled = computed(() => {
109
109
  return index.value >= highestLayerWithOutsidePointerEventsDisabledIndex;
110
110
  });
111
111
 
112
+ // A layer that stays mounted while hidden (e.g. a Dialog with `unmountOnHide: false`)
113
+ // must not listen while it is not present, hence the `present` guard passed as `enabled`.
114
+ // On touch the dispatch is deferred to the `click` event, so a `pointerdown` captured
115
+ // while hidden would be delivered right after the layer opened and dismiss it on the
116
+ // very interaction that opened it.
112
117
  const pointerDownOutside = usePointerDownOutside(async (event) => {
113
118
  const isPointerDownOnBranch = [...context.branches].some((branch) =>
114
119
  branch?.contains(event.target as HTMLElement),
@@ -123,7 +128,7 @@ const pointerDownOutside = usePointerDownOutside(async (event) => {
123
128
  if (!event.defaultPrevented) {
124
129
  emits('dismiss');
125
130
  }
126
- }, layerElement);
131
+ }, layerElement, () => props.present);
127
132
 
128
133
  const focusOutside = useFocusOutside((event) => {
129
134
  const isFocusInBranch = [...context.branches].some((branch) =>
@@ -13,11 +13,20 @@ import { context } from './context';
13
13
  const props = defineProps<DismissableLayerBranchProps>();
14
14
 
15
15
  const { forwardRef, currentElement } = useForwardExpose();
16
+
17
+ let registeredElement: HTMLElement | null = null;
18
+
16
19
  onMounted(() => {
17
- context.branches.add(currentElement.value);
20
+ registeredElement = currentElement.value;
21
+ if (registeredElement) {
22
+ context.branches.add(registeredElement);
23
+ }
18
24
  });
19
25
  onUnmounted(() => {
20
- context.branches.delete(currentElement.value);
26
+ if (registeredElement) {
27
+ context.branches.delete(registeredElement);
28
+ registeredElement = null;
29
+ }
21
30
  });
22
31
  </script>
23
32
 
@@ -18,6 +18,17 @@ export function isLayerExist(layerElement: HTMLElement, targetElement: HTMLEleme
18
18
  return false;
19
19
  }
20
20
 
21
+ // Anything inside the layer's own root element is inside the layer. The root
22
+ // can differ from the `[data-dismissable-layer]` element when the layer is
23
+ // rendered `asChild` into a component whose root is not the element that
24
+ // receives its attrs (e.g. `PopperContent`'s wrapper `div`). `FocusScope`
25
+ // resolves the same root as its container and may focus it as a fallback
26
+ // when the content has no tabbable children; that focus must not read as
27
+ // focus-outside and dismiss the layer it belongs to.
28
+ if (layerElement.contains(targetElement)) {
29
+ return true;
30
+ }
31
+
21
32
  const targetLayer = targetElement.closest(
22
33
  '[data-dismissable-layer]',
23
34
  );
@@ -67,6 +78,11 @@ export function usePointerDownOutside(
67
78
  }
68
79
 
69
80
  if (isLayerExist(element.value, target)) {
81
+ // A touch `pointerdown` outside arms a one-shot `click` listener that
82
+ // never fires when the tap becomes a scroll/drag. Drop it here so the
83
+ // next tap inside a layer cannot trigger the stale dismissal (mirrors
84
+ // Radix's inside-tree branch, radix-ui/primitives#2171).
85
+ ownerDocument.removeEventListener('click', handleClickRef.value);
70
86
  isPointerInsideDOMTree.value = false;
71
87
  return;
72
88
  }
@@ -14,7 +14,13 @@ import { useEmitAsProps, useForwardExpose, useHideOthers } from '@/shared';
14
14
  import DrawerContentImpl from './DrawerContentImpl.vue';
15
15
  import { injectDrawerRootContext } from './DrawerRoot.vue';
16
16
 
17
- const props = defineProps<DrawerContentProps>();
17
+ const props = withDefaults(
18
+ defineProps<DrawerContentProps>(),
19
+ {
20
+ initialFocus: true,
21
+ finalFocus: true,
22
+ },
23
+ );
18
24
  const emits = defineEmits<DrawerContentEmits>();
19
25
 
20
26
  const rootContext = injectDrawerRootContext();
@@ -33,12 +39,22 @@ const shouldTrapFocus = computed(() => (isFullModal.value || isTrapFocusOnly.val
33
39
  const shouldHideOthers = computed(() => isFullModal.value ? currentElement.value : undefined);
34
40
  useHideOthers(shouldHideOthers);
35
41
 
42
+ function finalFocusElement() {
43
+ if (props.finalFocus === false) {
44
+ return undefined;
45
+ }
46
+ if (props.finalFocus instanceof HTMLElement) {
47
+ return props.finalFocus;
48
+ }
49
+ return rootContext.triggerElement.value;
50
+ }
51
+
36
52
  // Non-modal handlers defined as named functions so the refs are accessed via
37
53
  // `.value` explicitly and the reads/writes are unambiguous.
38
54
  function onCloseAutoFocusNonModal(e: Event) {
39
55
  if (!e.defaultPrevented) {
40
56
  if (!hasInteractedOutside.value) {
41
- rootContext.triggerElement.value?.focus();
57
+ finalFocusElement()?.focus();
42
58
  }
43
59
  e.preventDefault();
44
60
  }
@@ -74,7 +90,7 @@ function onInteractOutsideNonModal(e: any) {
74
90
  @close-auto-focus="(e: Event) => {
75
91
  if (!e.defaultPrevented) {
76
92
  e.preventDefault()
77
- rootContext.triggerElement.value?.focus()
93
+ finalFocusElement()?.focus()
78
94
  }
79
95
  }"
80
96
  @pointer-down-outside="(e: any) => {
@@ -34,13 +34,20 @@ import { useResizeObserver } from '@vueuse/core';
34
34
  import { computed, onMounted, onUnmounted, watch } from 'vue';
35
35
  import { DismissableLayer } from '@/DismissableLayer';
36
36
  import { FocusScope } from '@/FocusScope';
37
+ import { focus } from '@/FocusScope/utils';
37
38
  import { useForwardExpose } from '@/shared';
38
39
  import { useDrawerSnapPoints } from './composables/useDrawerSnapPoints';
39
40
  import { useSwipeDismiss } from './composables/useSwipeDismiss';
40
41
  import { injectDrawerRootContext } from './DrawerRoot.vue';
41
42
  import { computeSwipeReleaseScalar, DRAWER_CSS_VARS, getDisplacement, registerDrawerCssProperties } from './utils';
42
43
 
43
- const props = defineProps<DrawerContentImplProps>();
44
+ const props = withDefaults(
45
+ defineProps<DrawerContentImplProps>(),
46
+ {
47
+ initialFocus: true,
48
+ finalFocus: true,
49
+ },
50
+ );
44
51
  const emits = defineEmits<DrawerContentImplEmits>();
45
52
 
46
53
  const rootContext = injectDrawerRootContext();
@@ -261,6 +268,19 @@ function onInteractOutside(event: any) {
261
268
  emits('interactOutside', event);
262
269
  }
263
270
 
271
+ function onMountAutoFocus(event: Event) {
272
+ emits('openAutoFocus', event);
273
+ if (event.defaultPrevented) {
274
+ return;
275
+ }
276
+ if (props.initialFocus === false) {
277
+ event.preventDefault();
278
+ } else if (props.initialFocus instanceof HTMLElement) {
279
+ event.preventDefault();
280
+ focus(props.initialFocus, { select: true });
281
+ }
282
+ }
283
+
264
284
  // --- update:openComplete wiring ---
265
285
  // Fire `update:openComplete` on the popup's own transitionend/animationend,
266
286
  // not on a microtask — consumers rely on this marker to know the enter/exit
@@ -370,7 +390,7 @@ if (process.env.NODE_ENV !== 'production') {
370
390
  as-child
371
391
  loop
372
392
  :trapped="props.trapFocus"
373
- @mount-auto-focus="emits('openAutoFocus', $event)"
393
+ @mount-auto-focus="onMountAutoFocus"
374
394
  @unmount-auto-focus="emits('closeAutoFocus', $event)"
375
395
  >
376
396
  <DismissableLayer
@@ -69,6 +69,7 @@ export interface DrawerRootContext {
69
69
  isSwiping: Ref<boolean>;
70
70
  nestedSwipeProgressStore: NestedSwipeProgressStore;
71
71
  onOpenChange: (value: boolean, reason?: DrawerOpenChangeReason) => void;
72
+ onOpenToggle: () => void;
72
73
  notifyOpenComplete: (value: boolean) => void;
73
74
  setActiveSnapPoint: (point: DrawerSnapPoint | null) => void;
74
75
  onPopupHeightChange: (height: number) => void;
@@ -165,14 +166,8 @@ provideDrawerRootContext({
165
166
  nestedSwiping,
166
167
  isSwiping,
167
168
  nestedSwipeProgressStore,
168
- onOpenChange(value, reason) {
169
- if (open.value === value) {
170
- return;
171
- }
172
- const details: DrawerOpenChangeDetails | undefined = reason ? { reason } : undefined;
173
- uncontrolledOpen.value = value;
174
- emit('update:open', value, details);
175
- },
169
+ onOpenChange: handleOpenChange,
170
+ onOpenToggle: handleOpenToggle,
176
171
  notifyOpenComplete(value) {
177
172
  emit('update:openComplete', value);
178
173
  },
@@ -219,11 +214,20 @@ provideDrawerRootContext({
219
214
  });
220
215
 
221
216
  function handleClose() {
222
- if (!open.value) {
217
+ handleOpenChange(false, 'close-press');
218
+ }
219
+
220
+ function handleOpenChange(value: boolean, reason?: DrawerOpenChangeReason) {
221
+ if (open.value === value) {
223
222
  return;
224
223
  }
225
- uncontrolledOpen.value = false;
226
- emit('update:open', false, { reason: 'close-press' });
224
+ const details: DrawerOpenChangeDetails | undefined = reason ? { reason } : undefined;
225
+ uncontrolledOpen.value = value;
226
+ emit('update:open', value, details);
227
+ }
228
+
229
+ function handleOpenToggle() {
230
+ handleOpenChange(!open.value, 'trigger-press');
227
231
  }
228
232
 
229
233
  // Sync open state with DrawerProvider
@@ -38,7 +38,7 @@ onUnmounted(() => {
38
38
  :aria-expanded="rootContext.open.value"
39
39
  :aria-controls="rootContext.open.value ? rootContext.contentId : undefined"
40
40
  :data-state="rootContext.open.value ? 'open' : 'closed'"
41
- @click="rootContext.onOpenChange(true, 'trigger-press')"
41
+ @click="rootContext.onOpenToggle"
42
42
  >
43
43
  <slot />
44
44
  </Primitive>
@@ -35,6 +35,10 @@ export interface UseSwipeDismissOptions {
35
35
  const DEFAULT_SWIPE_THRESHOLD = 40;
36
36
  const REVERSE_CANCEL_THRESHOLD = 10;
37
37
  const MIN_DRAG_THRESHOLD = 1;
38
+ // Travel an axis must cover from the touch origin to claim the gesture, and the
39
+ // margin the cross axis must beat the drawer axis by to win it.
40
+ const AXIS_LOCK_SLOP = 6;
41
+ const AXIS_LOCK_BIAS = 2;
38
42
  const MIN_RELEASE_VELOCITY_DURATION_MS = 16;
39
43
  const MAX_RELEASE_VELOCITY_AGE_MS = 80;
40
44
  const DEFAULT_IGNORE_SELECTOR = 'button,a,input,select,textarea,label,[role="button"]';
@@ -132,6 +136,15 @@ export function useSwipeDismiss(options: UseSwipeDismissOptions) {
132
136
  const allowLeft = computed(() => toValue(directions).includes('left'));
133
137
  const allowRight = computed(() => toValue(directions).includes('right'));
134
138
 
139
+ // The axis the drawer dismisses along, or `null` when both axes are
140
+ // dismissable and there is no cross axis to yield native scrolling to.
141
+ const drawerAxis = computed<'vertical' | 'horizontal' | null>(() => {
142
+ if (hasVertical.value === hasHorizontal.value) {
143
+ return null;
144
+ }
145
+ return hasVertical.value ? 'vertical' : 'horizontal';
146
+ });
147
+
135
148
  const isSwiping = ref(false);
136
149
  const swipeDirection = ref<SwipeDirection | undefined>(undefined);
137
150
  const dragOffset = ref({ x: 0, y: 0 });
@@ -146,6 +159,10 @@ export function useSwipeDismiss(options: UseSwipeDismissOptions) {
146
159
  let pendingSwipeStartPos: { x: number; y: number } | null = null;
147
160
  let swipeFromScrollable = false;
148
161
  let scrollableAncestor: HTMLElement | null = null;
162
+ // Cross-axis arbitration state (touch only), reset per gesture.
163
+ let crossAxisScrollable: HTMLElement | null = null;
164
+ let drawerAxisAttributed = false;
165
+ let preserveNativeCrossAxisScroll = false;
149
166
  let elementSize = { width: 0, height: 0 };
150
167
  let swipeProgress = 0;
151
168
  let lastDragSample: { x: number; y: number; time: number } | null = null;
@@ -217,6 +234,9 @@ export function useSwipeDismiss(options: UseSwipeDismissOptions) {
217
234
  resetGestureState();
218
235
  swipeFromScrollable = false;
219
236
  scrollableAncestor = null;
237
+ crossAxisScrollable = null;
238
+ drawerAxisAttributed = false;
239
+ preserveNativeCrossAxisScroll = false;
220
240
  activePointerId = null;
221
241
  pointerStarted = false;
222
242
  }
@@ -261,6 +281,54 @@ export function useSwipeDismiss(options: UseSwipeDismissOptions) {
261
281
  return { x: newDx, y: newDy };
262
282
  }
263
283
 
284
+ /**
285
+ * Arbitrates a touchmove between the drawer swipe and a native scroll on the
286
+ * cross axis. Returns `true` when the move must be left alone — the cross axis
287
+ * already won the gesture, or neither axis has passed the slop yet.
288
+ */
289
+ function shouldYieldTouchMove(e: TouchEvent, pos: { x: number; y: number }): boolean {
290
+ if (preserveNativeCrossAxisScroll) {
291
+ return true;
292
+ }
293
+
294
+ // Attribution happens once per gesture: the slop is measured from the touch
295
+ // origin, which is never re-baselined, so re-arbitrating mid-drag would
296
+ // freeze the drawer and drop `preventDefault()`.
297
+ if (drawerAxisAttributed || !crossAxisScrollable || !drawerAxis.value) {
298
+ return false;
299
+ }
300
+
301
+ // The browser has already committed the gesture to a native scroll.
302
+ if (!e.cancelable) {
303
+ preserveNativeCrossAxisScroll = true;
304
+ return true;
305
+ }
306
+
307
+ const isVerticalDrawerAxis = drawerAxis.value === 'vertical';
308
+ const drawerAxisDelta = isVerticalDrawerAxis ? pos.y - dragStartPos.y : pos.x - dragStartPos.x;
309
+ const crossAxisDelta = isVerticalDrawerAxis ? pos.x - dragStartPos.x : pos.y - dragStartPos.y;
310
+ const absDrawerAxisDelta = Math.abs(drawerAxisDelta);
311
+ const absCrossAxisDelta = Math.abs(crossAxisDelta);
312
+
313
+ if (
314
+ absCrossAxisDelta >= AXIS_LOCK_SLOP
315
+ && absCrossAxisDelta > absDrawerAxisDelta + AXIS_LOCK_BIAS
316
+ ) {
317
+ preserveNativeCrossAxisScroll = true;
318
+ return true;
319
+ }
320
+
321
+ if (absDrawerAxisDelta >= AXIS_LOCK_SLOP) {
322
+ drawerAxisAttributed = true;
323
+ return false;
324
+ }
325
+
326
+ // Unattributed. Leave the event alone: on iOS, `preventDefault()` on the
327
+ // first cancelable touchmove cancels native scrolling for the whole gesture,
328
+ // locking out a cross-axis scroll that only passes the slop on a later move.
329
+ return true;
330
+ }
331
+
264
332
  function processMove(el: HTMLElement, pos: { x: number; y: number }, time: number) {
265
333
  const rawDx = pos.x - dragStartPos.x;
266
334
  const rawDy = pos.y - dragStartPos.y;
@@ -513,6 +581,12 @@ export function useSwipeDismiss(options: UseSwipeDismissOptions) {
513
581
  return;
514
582
  }
515
583
 
584
+ // A gesture whose end we never saw would otherwise leak its verdict into
585
+ // this one, permanently muting the swipe.
586
+ crossAxisScrollable = null;
587
+ drawerAxisAttributed = false;
588
+ preserveNativeCrossAxisScroll = false;
589
+
516
590
  if (!options.ignoreScrollableAncestors) {
517
591
  const axis = hasVertical.value ? 'vertical' : 'horizontal';
518
592
  const scrollable = findScrollableAncestor(target, axis);
@@ -522,6 +596,15 @@ export function useSwipeDismiss(options: UseSwipeDismissOptions) {
522
596
  }
523
597
  }
524
598
 
599
+ // The scroller on the axis the drawer does NOT dismiss along, so
600
+ // `shouldYieldTouchMove` can hand the gesture to it. Deliberately not gated
601
+ // on `ignoreScrollableAncestors`: that option is about starting a swipe from
602
+ // inside a scroller on the dismiss axis.
603
+ if (drawerAxis.value) {
604
+ const crossAxis = drawerAxis.value === 'vertical' ? 'horizontal' : 'vertical';
605
+ crossAxisScrollable = findScrollableAncestor(target, crossAxis);
606
+ }
607
+
525
608
  const t = e.touches[0];
526
609
  if (!t) {
527
610
  return;
@@ -542,6 +625,11 @@ export function useSwipeDismiss(options: UseSwipeDismissOptions) {
542
625
 
543
626
  const pos = { x: t.clientX, y: t.clientY };
544
627
 
628
+ // Bailing here leaves the move untouched, so the browser can scroll natively.
629
+ if (shouldYieldTouchMove(e, pos)) {
630
+ return;
631
+ }
632
+
545
633
  if (swipeFromScrollable && pendingSwipe && scrollableAncestor) {
546
634
  const dx = pos.x - dragStartPos.x;
547
635
  const dy = pos.y - dragStartPos.y;
@@ -6,7 +6,7 @@ export interface DropdownMenuFilterProps extends PrimitiveProps {
6
6
  modelValue?: string;
7
7
  /** Focus on element when mounted. */
8
8
  autoFocus?: boolean;
9
- /** When `true`, prevents the user from interacting with item */
9
+ /** When `true`, prevents the user from interacting with the filter input */
10
10
  disabled?: boolean;
11
11
  }
12
12
 
@@ -157,6 +157,17 @@ watchEffect((cleanupFn) => {
157
157
  return;
158
158
  }
159
159
 
160
+ // Confirm focus was actually orphaned before pulling it back. `lastFocusedElement`
161
+ // is only tracked while the scope is not paused, so an open popper (which pauses
162
+ // this trap and only resumes it in a `setTimeout`) leaves it pointing at a stale
163
+ // element. Without this check, an element focused inside the container during that
164
+ // window — e.g. a view swapped in by the popper's `select` handler focusing its own
165
+ // input on mount — would be robbed of focus.
166
+ const activeElement = getActiveElement();
167
+ if (activeElement && container.contains(activeElement)) {
168
+ return;
169
+ }
170
+
160
171
  const isLastFocusedElementExist = container.contains(lastFocusedElement);
161
172
  if (!isLastFocusedElementExist) {
162
173
  focus(container);
@@ -77,7 +77,7 @@ provideListboxItemContext({
77
77
  :id="id"
78
78
  v-bind="$attrs"
79
79
  :ref="forwardRef"
80
- v-memo="[isHighlighted, isSelected, disabled, rootContext.focusable.value]"
80
+ v-memo="[isHighlighted, isSelected, disabled, rootContext.focusable.value, ...Object.entries($attrs).flat()]"
81
81
  role="option"
82
82
  :tabindex="rootContext.focusable.value ? isHighlighted ? '0' : '-1' : -1"
83
83
  :aria-selected="isSelected"
@@ -40,6 +40,15 @@ type ListboxRootContext<T> = {
40
40
  export const [injectListboxRootContext, provideListboxRootContext]
41
41
  = createContext<ListboxRootContext<AcceptableValue>>('ListboxRoot');
42
42
 
43
+ /** Controls highlight scrolling while a parent composite is being positioned. */
44
+ type ListboxHighlightScrollContext = {
45
+ suppressHighlightScroll: Readonly<Ref<boolean>>;
46
+ onHighlightScrollRequest: (scroll: (() => void) | undefined) => void;
47
+ };
48
+
49
+ export const [injectListboxHighlightScrollContext, provideListboxHighlightScrollContext]
50
+ = createContext<ListboxHighlightScrollContext>('ListboxHighlightScroll');
51
+
43
52
  export interface ListboxRootProps<T = AcceptableValue> extends PrimitiveProps, FormFieldProps {
44
53
  /** The controlled value of the listbox. Can be binded with `v-model`. */
45
54
  modelValue?: T | Array<T>;
@@ -100,11 +109,19 @@ defineSlots<{
100
109
  }>();
101
110
 
102
111
  const { multiple, highlightOnHover, orientation, disabled, selectionBehavior, dir: propDir } = toRefs(props);
103
- const { getItems } = useCollection<{ value: T }>({ isProvider: true });
112
+ const { getItems, getItem } = useCollection<{ value: T }>({ isProvider: true });
104
113
  const { handleTypeaheadSearch } = useTypeahead();
105
114
  const { primitiveElement, currentElement } = usePrimitiveElement();
106
115
  const dir = useDirection(propDir);
107
116
 
117
+ const highlightScrollContext = injectListboxHighlightScrollContext(null);
118
+
119
+ // Prevent nested Listbox roots from inheriting this root's scroll coordination.
120
+ provideListboxHighlightScrollContext({
121
+ suppressHighlightScroll: ref(false),
122
+ onHighlightScrollRequest: () => {},
123
+ });
124
+
108
125
  const isFormControl = useFormControl(currentElement);
109
126
 
110
127
  const firstValue = ref<T>();
@@ -162,14 +179,29 @@ function changeHighlight(el: HTMLElement, scrollIntoView = true, focus?: boolean
162
179
  }
163
180
 
164
181
  highlightedElement.value = el;
182
+ const suppressHighlightScroll = highlightScrollContext?.suppressHighlightScroll.value ?? false;
165
183
  if (focus ?? focusable.value) {
166
- highlightedElement.value.focus();
184
+ if (suppressHighlightScroll) {
185
+ highlightedElement.value.focus({ preventScroll: true });
186
+ } else {
187
+ highlightedElement.value.focus();
188
+ }
167
189
  }
168
- if (scrollIntoView) {
190
+
191
+ if (suppressHighlightScroll) {
192
+ highlightScrollContext?.onHighlightScrollRequest(scrollIntoView
193
+ ? () => {
194
+ const element = highlightedElement.value;
195
+ if (element?.isConnected) {
196
+ element.scrollIntoView({ block: 'nearest' });
197
+ }
198
+ }
199
+ : undefined);
200
+ } else if (scrollIntoView) {
169
201
  highlightedElement.value.scrollIntoView({ block: 'nearest' });
170
202
  }
171
203
 
172
- const highlightedItem = getItems().find((i) => i.ref === el);
204
+ const highlightedItem = getItem(el);
173
205
  emits('highlight', highlightedItem);
174
206
  }
175
207
 
@@ -136,10 +136,9 @@ rootContext.virtualFocusHook.on(({ event, scroll }) => {
136
136
  requestAnimationFrame(() => {
137
137
  const item = queryCheckedElement(parentEl.value);
138
138
  if (item) {
139
- rootContext.changeHighlight(item, scroll, scroll ? undefined : false);
140
- if (event) {
141
- item?.focus();
142
- }
139
+ // eslint-disable-next-line no-nested-ternary
140
+ const focus = event ? true : scroll ? undefined : false;
141
+ rootContext.changeHighlight(item, scroll, focus);
143
142
  }
144
143
  });
145
144
  } else if (scroll) {
@@ -93,10 +93,11 @@ async function handlePointerLeave(event: PointerEvent) {
93
93
  @pointerleave="handlePointerLeave"
94
94
  @focus="
95
95
  async (event: FocusEvent) => {
96
+ const item = event.currentTarget as HTMLElement;
96
97
  await nextTick();
97
98
  if (event.defaultPrevented || disabled) return;
98
99
  isFocused = true;
99
- contentContext.highlightedElement.value = event.currentTarget as HTMLElement
100
+ contentContext.highlightedElement.value = item;
100
101
  }
101
102
  "
102
103
  @blur="