akar 2.0.22 → 2.0.23

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 (87) hide show
  1. package/dist/Combobox/ComboboxCancel.cjs +1 -1
  2. package/dist/Combobox/ComboboxCancel.cjs.map +1 -1
  3. package/dist/Combobox/ComboboxCancel.js +1 -1
  4. package/dist/Combobox/ComboboxCancel.js.map +1 -1
  5. package/dist/Dialog/DialogContent.cjs.map +1 -1
  6. package/dist/Dialog/DialogContent.js.map +1 -1
  7. package/dist/DismissableLayer/DismissableLayer.cjs +6 -8
  8. package/dist/DismissableLayer/DismissableLayer.cjs.map +1 -1
  9. package/dist/DismissableLayer/DismissableLayer.js +6 -8
  10. package/dist/DismissableLayer/DismissableLayer.js.map +1 -1
  11. package/dist/DismissableLayer/DismissableLayerBranch.cjs +1 -1
  12. package/dist/DismissableLayer/DismissableLayerBranch.js +1 -1
  13. package/dist/DismissableLayer/context.cjs +0 -1
  14. package/dist/DismissableLayer/context.cjs.map +1 -1
  15. package/dist/DismissableLayer/context.js +0 -1
  16. package/dist/DismissableLayer/context.js.map +1 -1
  17. package/dist/Menu/MenuSubTrigger.cjs +4 -2
  18. package/dist/Menu/MenuSubTrigger.cjs.map +1 -1
  19. package/dist/Menu/MenuSubTrigger.js +4 -2
  20. package/dist/Menu/MenuSubTrigger.js.map +1 -1
  21. package/dist/RovingFocus/RovingFocusItem.cjs +13 -2
  22. package/dist/RovingFocus/RovingFocusItem.cjs.map +1 -1
  23. package/dist/RovingFocus/RovingFocusItem.js +14 -3
  24. package/dist/RovingFocus/RovingFocusItem.js.map +1 -1
  25. package/dist/TagsInput/TagsInputInput.cjs +2 -1
  26. package/dist/TagsInput/TagsInputInput.cjs.map +1 -1
  27. package/dist/TagsInput/TagsInputInput.js +2 -1
  28. package/dist/TagsInput/TagsInputInput.js.map +1 -1
  29. package/dist/Toast/ToastAction.cjs +1 -1
  30. package/dist/Toast/ToastAction.cjs.map +1 -1
  31. package/dist/Toast/ToastAction.js +1 -1
  32. package/dist/Toast/ToastAction.js.map +1 -1
  33. package/dist/Toast/ToastDescription.cjs +2 -2
  34. package/dist/Toast/ToastDescription.cjs.map +1 -1
  35. package/dist/Toast/ToastDescription.js +3 -3
  36. package/dist/Toast/ToastDescription.js.map +1 -1
  37. package/dist/Toast/ToastRootImpl.cjs.map +1 -1
  38. package/dist/Toast/ToastRootImpl.js.map +1 -1
  39. package/dist/Toast/ToastTitle.cjs +2 -2
  40. package/dist/Toast/ToastTitle.cjs.map +1 -1
  41. package/dist/Toast/ToastTitle.js +3 -3
  42. package/dist/Toast/ToastTitle.js.map +1 -1
  43. package/dist/constant.d.ts.map +1 -1
  44. package/dist/index.cjs +2 -1
  45. package/dist/index.js +2 -1
  46. package/dist/index2.d.cts +16 -16
  47. package/dist/index2.d.cts.map +1 -1
  48. package/dist/index2.d.ts +12 -12
  49. package/dist/index2.d.ts.map +1 -1
  50. package/dist/index3.d.cts +703 -702
  51. package/dist/index3.d.cts.map +1 -1
  52. package/dist/index3.d.ts +693 -692
  53. package/dist/index3.d.ts.map +1 -1
  54. package/dist/internal.cjs +2 -1
  55. package/dist/internal.d.cts +2 -2
  56. package/dist/internal.d.cts.map +1 -1
  57. package/dist/internal.d.ts +2 -2
  58. package/dist/internal.d.ts.map +1 -1
  59. package/dist/internal.js +2 -1
  60. package/dist/shared/bodyPointerEvents.cjs +46 -0
  61. package/dist/shared/bodyPointerEvents.cjs.map +1 -0
  62. package/dist/shared/bodyPointerEvents.js +34 -0
  63. package/dist/shared/bodyPointerEvents.js.map +1 -0
  64. package/dist/shared/useBodyScrollLock.cjs +8 -7
  65. package/dist/shared/useBodyScrollLock.cjs.map +1 -1
  66. package/dist/shared/useBodyScrollLock.js +8 -7
  67. package/dist/shared/useBodyScrollLock.js.map +1 -1
  68. package/dist/shared/useCalendarKeyboardNavigation.cjs +21 -2
  69. package/dist/shared/useCalendarKeyboardNavigation.cjs.map +1 -1
  70. package/dist/shared/useCalendarKeyboardNavigation.js +21 -2
  71. package/dist/shared/useCalendarKeyboardNavigation.js.map +1 -1
  72. package/dist/shared.cjs +1 -1
  73. package/dist/shared.js +1 -1
  74. package/package.json +4 -1
  75. package/src/Combobox/ComboboxCancel.vue +4 -3
  76. package/src/DismissableLayer/DismissableLayer.vue +21 -27
  77. package/src/DismissableLayer/context.ts +1 -1
  78. package/src/Menu/MenuSubTrigger.vue +10 -4
  79. package/src/RovingFocus/RovingFocusItem.vue +24 -16
  80. package/src/TagsInput/TagsInputInput.vue +11 -5
  81. package/src/Toast/ToastAction.vue +2 -1
  82. package/src/Toast/ToastDescription.vue +3 -1
  83. package/src/Toast/ToastRootImpl.vue +1 -1
  84. package/src/Toast/ToastTitle.vue +3 -1
  85. package/src/shared/bodyPointerEvents.ts +38 -0
  86. package/src/shared/useBodyScrollLock.ts +7 -10
  87. package/src/shared/useCalendarKeyboardNavigation.ts +20 -4
@@ -4,8 +4,9 @@ import type { Side } from './utils';
4
4
 
5
5
  export interface MenuSubTriggerProps extends MenuItemImplProps {
6
6
  /**
7
- * Time in milliseconds to keep a submenu open while the pointer moves from
8
- * its trigger to the submenu.
7
+ * How long (in milliseconds) the pointer is given to reach the submenu after leaving the trigger.
8
+ * While it moves towards the submenu within this time, hovering other items won't close the submenu.
9
+ * Increase it for users who move the pointer slowly or on devices under heavy load.
9
10
  * @defaultValue 300
10
11
  */
11
12
  graceDuration?: number;
@@ -14,6 +15,7 @@ export interface MenuSubTriggerProps extends MenuItemImplProps {
14
15
 
15
16
  <script setup lang="ts">
16
17
  import type { ComponentPublicInstance } from 'vue';
18
+ import { reactiveOmit } from '@vueuse/shared';
17
19
  import { nextTick, onUnmounted, ref, watch } from 'vue';
18
20
  import { useId } from '@/shared';
19
21
  import MenuAnchor from './MenuAnchor.vue';
@@ -26,6 +28,8 @@ import { getOpenState, isMouseEvent, SUB_OPEN_KEYS } from './utils';
26
28
  const props = withDefaults(defineProps<MenuSubTriggerProps>(), {
27
29
  graceDuration: 300,
28
30
  });
31
+ // `graceDuration` is not a `MenuItemImpl` prop, so it would land on the DOM element.
32
+ const itemProps = reactiveOmit(props, 'graceDuration');
29
33
 
30
34
  const menuContext = injectMenuContext();
31
35
  const rootContext = injectMenuRootContext();
@@ -45,7 +49,7 @@ watch(menuContext.open, (open) => {
45
49
 
46
50
  const openTimerRef = ref<number | null>(null);
47
51
 
48
- subContext.triggerId ||= useId(undefined, 'akar-menu-sub-trigger');
52
+ subContext.triggerId ||= useId(undefined, 'reka-menu-sub-trigger');
49
53
 
50
54
  function clearOpenTimer() {
51
55
  if (openTimerRef.value) {
@@ -84,6 +88,8 @@ async function handlePointerLeave(event: PointerEvent) {
84
88
 
85
89
  const contentRect = menuContext.content.value?.getBoundingClientRect();
86
90
  if (contentRect?.width) {
91
+ // TODO (Radix UI): make sure to update this when we change positioning logic
92
+ // https://github.com/radix-ui/primitives/blob/main/packages/react/menu/src/Menu.tsx#L1088
87
93
  const side = menuContext.content.value?.dataset.side as Side;
88
94
 
89
95
  const rightSide = side === 'right';
@@ -141,7 +147,7 @@ async function handleKeyDown(event: KeyboardEvent) {
141
147
  <template>
142
148
  <MenuAnchor as-child>
143
149
  <MenuItemImpl
144
- v-bind="props"
150
+ v-bind="itemProps"
145
151
  :id="subContext.triggerId"
146
152
  :ref="
147
153
  (vnode: Element | ComponentPublicInstance | null) => {
@@ -17,7 +17,7 @@ export interface RovingFocusItemProps extends PrimitiveProps {
17
17
 
18
18
  <script setup lang="ts">
19
19
  import { useEventListener } from '@vueuse/core';
20
- import { computed, nextTick, onMounted, onUnmounted, watch } from 'vue';
20
+ import { computed, nextTick, onMounted, onUnmounted, shallowRef, watch } from 'vue';
21
21
  import { useCollection } from '@/Collection';
22
22
  import { Primitive } from '@/Primitive';
23
23
  import { useForwardExpose, useId } from '@/shared';
@@ -43,26 +43,22 @@ onMounted(() => {
43
43
  context.onFocusableItemAdd();
44
44
  }
45
45
  });
46
-
47
46
  onUnmounted(() => {
48
47
  if (props.focusable) {
49
48
  context.onFocusableItemRemove();
50
49
  }
51
50
  });
52
51
 
53
- watch(
54
- () => props.focusable,
55
- (newVal, oldVal) => {
56
- if (newVal === oldVal) {
57
- return;
58
- }
59
- if (newVal) {
60
- context.onFocusableItemAdd();
61
- } else {
62
- context.onFocusableItemRemove();
63
- }
64
- },
65
- );
52
+ watch(() => props.focusable, (newVal, oldVal) => {
53
+ if (newVal === oldVal) {
54
+ return;
55
+ }
56
+ if (newVal) {
57
+ context.onFocusableItemAdd();
58
+ } else {
59
+ context.onFocusableItemRemove();
60
+ }
61
+ });
66
62
 
67
63
  function handleKeydown(event: KeyboardEvent) {
68
64
  if (event.defaultPrevented) {
@@ -114,7 +110,18 @@ function handleKeydown(event: KeyboardEvent) {
114
110
  // `ToolbarButton`) or a consumer can then claim a key with `preventDefault()`,
115
111
  // matching Radix, where the wrapped child's handler runs first.
116
112
  const { forwardRef, currentElement } = useForwardExpose();
117
- useEventListener(currentElement, 'keydown', handleKeydown);
113
+ const itemElement = shallowRef<HTMLElement>();
114
+ watch(currentElement, (element) => {
115
+ itemElement.value = element;
116
+ }, { immediate: true, flush: 'post' });
117
+ useEventListener(itemElement, 'keydown', handleKeydown);
118
+
119
+ // An `asChild` child can replace its root element without this component
120
+ // re-rendering, which would leave the listener on the detached element. Focus
121
+ // reaches the item before any key does, so rebind from there.
122
+ function handleFocusIn(event: FocusEvent) {
123
+ itemElement.value = event.currentTarget as HTMLElement;
124
+ }
118
125
  </script>
119
126
 
120
127
  <template>
@@ -137,6 +144,7 @@ useEventListener(currentElement, 'keydown', handleKeydown);
137
144
  }
138
145
  "
139
146
  @focus="context.onItemFocus(id)"
147
+ @focusin="handleFocusIn"
140
148
  >
141
149
  <slot />
142
150
  </Primitive>
@@ -60,19 +60,20 @@ function handleTab(event: KeyboardEvent) {
60
60
  return handleCustomKeydown(event);
61
61
  }
62
62
 
63
- const { isComposing, handleCompositionStart, handleCompositionEnd } = useComposing();
64
63
  function handleEnter(event: KeyboardEvent) {
65
64
  return handleCustomKeydown(event, { preventImplicitSubmit: true });
66
65
  }
67
66
 
67
+ const { isComposing, handleCompositionStart, handleCompositionEnd } = useComposing();
68
68
  async function handleCustomKeydown(event: KeyboardEvent, { preventImplicitSubmit = false } = {}) {
69
69
  if (isComposing.value) {
70
70
  return;
71
71
  }
72
72
 
73
- // Detect consumer listeners that prevent the key after this handler runs.
74
- // `defaultPrevented` alone cannot distinguish their call from our own
75
- // synchronous cancellation of a form's implicit Enter submission.
73
+ // If keydown `Enter` or `Tab` was prevented, we let user handle updating the value themselves.
74
+ // Listeners that run after this one (e.g. `@keydown.enter.prevent`, or a wrapping `ComboboxInput`
75
+ // selecting its highlighted item) can only be observed after dispatch, and by then
76
+ // `defaultPrevented` may already be set by us, so their `preventDefault()` calls are tracked here.
76
77
  let isPreventedByOthers = event.defaultPrevented;
77
78
  const nativePreventDefault = event.preventDefault.bind(event);
78
79
  event.preventDefault = () => {
@@ -81,12 +82,13 @@ async function handleCustomKeydown(event: KeyboardEvent, { preventImplicitSubmit
81
82
  };
82
83
 
83
84
  const target = event.target as HTMLInputElement;
85
+ // A form submits implicitly as soon as the `Enter` keydown dispatch finishes,
86
+ // so it has to be cancelled synchronously. An empty draft keeps submitting the form.
84
87
  if (preventImplicitSubmit && target.value && !isPreventedByOthers) {
85
88
  nativePreventDefault();
86
89
  }
87
90
 
88
91
  await nextTick();
89
- // if keydown 'Enter' or `Tab` was prevented, we let user handle updating the value themselves
90
92
  if (isPreventedByOthers) {
91
93
  return;
92
94
  }
@@ -99,6 +101,10 @@ async function handleCustomKeydown(event: KeyboardEvent, { preventImplicitSubmit
99
101
  if (isAdded) {
100
102
  target.value = '';
101
103
  }
104
+
105
+ // Keep focus in the input after `Tab` adds a tag. A browser still honours this
106
+ // from a microtask of the keydown dispatch; `Enter` was already cancelled above.
107
+ nativePreventDefault();
102
108
  }
103
109
 
104
110
  function handleInput(event: InputEvent) {
@@ -48,7 +48,8 @@ if (isRendered.value && !altText.value) {
48
48
  function handleClick(event: MouseEvent) {
49
49
  actionProps.value?.onClick?.(event);
50
50
  if (actionProps.value?.closeOnClick ?? props.closeOnClick) {
51
- rootContext.onClose();
51
+ // Pass the event on, like `ToastClose`: a keyboard click hands focus to the viewport.
52
+ rootContext.onClose(event as PointerEvent);
52
53
  }
53
54
  }
54
55
  </script>
@@ -12,10 +12,12 @@ import { injectToastRootContext } from './ToastRootImpl.vue';
12
12
  const props = defineProps<ToastDescriptionProps>();
13
13
  useForwardExpose();
14
14
  const rootContext = injectToastRootContext(null);
15
+ // A managed toast without a description renders nothing, unless slot content is given.
16
+ // Keep this note out of the template: a root comment turns the root into a
17
+ // fragment, which drops `class` and other fallthrough attrs in production.
15
18
  </script>
16
19
 
17
20
  <template>
18
- <!-- A managed toast without a description renders nothing, unless slot content is given. -->
19
21
  <Primitive
20
22
  v-if="$slots.default || !rootContext?.toast.value || rootContext.toast.value.description"
21
23
  v-bind="props"
@@ -49,7 +49,7 @@ export interface ToastRootImplProps extends PrimitiveProps {
49
49
  }
50
50
 
51
51
  export const [injectToastRootContext, provideToastRootContext]
52
- = createContext<{ onClose: () => void; toast: Ref<ToastObject | undefined> }>('ToastRoot');
52
+ = createContext<{ onClose: (event?: PointerEvent) => void; toast: Ref<ToastObject | undefined> }>('ToastRoot');
53
53
  </script>
54
54
 
55
55
  <script setup lang="ts">
@@ -12,10 +12,12 @@ import { injectToastRootContext } from './ToastRootImpl.vue';
12
12
  const props = defineProps<ToastTitleProps>();
13
13
  useForwardExpose();
14
14
  const rootContext = injectToastRootContext(null);
15
+ // A managed toast without a title renders nothing, unless slot content is given.
16
+ // Keep this note out of the template: a root comment turns the root into a
17
+ // fragment, which drops `class` and other fallthrough attrs in production.
15
18
  </script>
16
19
 
17
20
  <template>
18
- <!-- A managed toast without a title renders nothing, unless slot content is given. -->
19
21
  <Primitive
20
22
  v-if="$slots.default || !rootContext?.toast.value || rootContext.toast.value.title"
21
23
  v-bind="props"
@@ -0,0 +1,38 @@
1
+ // `useBodyScrollLock` and every `DismissableLayer` with
2
+ // `disableOutsidePointerEvents` lock `body.style.pointerEvents` through this
3
+ // shared, ref-counted owner, in whatever order they come and go.
4
+ interface BodyPointerEventsLock {
5
+ owners: Set<unknown>;
6
+ original: string;
7
+ }
8
+
9
+ const locks = new WeakMap<Document, BodyPointerEventsLock>();
10
+
11
+ /**
12
+ * Adds `owner` to the body `pointer-events` lock of `doc` and sets it to `none`.
13
+ * The first owner saves the body's current inline value.
14
+ */
15
+ export function acquireBodyPointerEvents(doc: Document, owner: unknown) {
16
+ let lock = locks.get(doc);
17
+ if (!lock) {
18
+ lock = { owners: new Set(), original: doc.body.style.pointerEvents };
19
+ locks.set(doc, lock);
20
+ }
21
+ lock.owners.add(owner);
22
+ doc.body.style.pointerEvents = 'none';
23
+ }
24
+
25
+ /**
26
+ * Removes `owner` from the lock of `doc`; the last owner out restores the saved
27
+ * value. Releasing an owner that never acquired is a no-op.
28
+ */
29
+ export function releaseBodyPointerEvents(doc: Document, owner: unknown) {
30
+ const lock = locks.get(doc);
31
+ if (!lock?.owners.delete(owner)) {
32
+ return;
33
+ }
34
+ if (lock.owners.size === 0) {
35
+ locks.delete(doc);
36
+ doc.body.style.pointerEvents = lock.original;
37
+ }
38
+ }
@@ -8,7 +8,9 @@ import { isClient, isIOS, tryOnBeforeUnmount } from '@vueuse/shared';
8
8
  import { defu } from 'defu';
9
9
  import { computed, nextTick, ref, watch } from 'vue';
10
10
  import { injectConfigProviderContext } from '@/ConfigProvider/ConfigProvider.vue';
11
- import { context as dismissableLayerContext } from '@/DismissableLayer/context';
11
+ import { acquireBodyPointerEvents, releaseBodyPointerEvents } from './bodyPointerEvents';
12
+ // The whole lock stack holds a single share of the body pointer-events owner.
13
+ const pointerEventsOwner = Symbol('useBodyScrollLock');
12
14
 
13
15
  const useBodyLockStackCount = createSharedComposable(() => {
14
16
  const map = ref<Map<string, boolean>>(new Map());
@@ -32,14 +34,9 @@ const useBodyLockStackCount = createSharedComposable(() => {
32
34
  const resetBodyStyle = () => {
33
35
  document.body.style.paddingRight = '';
34
36
  document.body.style.marginRight = '';
35
- // A mounted `DismissableLayer` with `disableOutsidePointerEvents` may
36
- // still own the body pointer-events lock (e.g. a modal Dialog rendered
37
- // without the Overlay that would hold a scroll lock). Clearing it here
38
- // would make everything behind that layer clickable again; the
39
- // layer restores it once its last disabling layer is gone.
40
- if (dismissableLayerContext.layersWithOutsidePointerEventsDisabled.size === 0) {
41
- document.body.style.pointerEvents = '';
42
- }
37
+
38
+ // Only restored once no `DismissableLayer` still holds it either.
39
+ releaseBodyPointerEvents(document, pointerEventsOwner);
43
40
  document.documentElement.style.removeProperty('--scrollbar-width');
44
41
  document.body.style.overflow = initialOverflow.value ?? '';
45
42
  isIOS && stopTouchMoveListener?.();
@@ -97,7 +94,7 @@ const useBodyLockStackCount = createSharedComposable(() => {
97
94
  if (!locked.value) {
98
95
  return;
99
96
  }
100
- document.body.style.pointerEvents = 'none';
97
+ acquireBodyPointerEvents(document, pointerEventsOwner);
101
98
  document.body.style.overflow = 'hidden';
102
99
  });
103
100
  }, { immediate: true, flush: 'sync' });
@@ -1,5 +1,6 @@
1
1
  import type { DateValue } from '@internationalized/date';
2
2
  import type { WeekStartsOn } from '@/date';
3
+ import { toCalendar, toCalendarDate } from '@internationalized/date';
3
4
  import { nextTick } from 'vue';
4
5
  import { getDaysInMonth, getLastFirstDayOfWeek, getNextLastDayOfWeek } from '@/date';
5
6
 
@@ -82,15 +83,30 @@ export function getTargetMonthDay(date: DateValue, unit: 'month' | 'year', amoun
82
83
  return targetBase.set({ day: targetDay });
83
84
  }
84
85
 
86
+ /** Compares the calendar days of two dates, ignoring their time and type. */
87
+ function compareDay(date: DateValue, reference: DateValue) {
88
+ return toCalendarDate(date).compare(toCalendarDate(reference));
89
+ }
90
+
91
+ /**
92
+ * Moves `date` to the day of `bound`. The result keeps the type, time and
93
+ * calendar of `date`, because the grid cells it has to match are built from
94
+ * the placeholder and not from `minValue` / `maxValue`.
95
+ */
96
+ function setDay(date: DateValue, bound: DateValue): DateValue {
97
+ const day = toCalendar(toCalendarDate(bound), date.calendar);
98
+ return date.set({ era: day.era, year: day.year, month: day.month, day: day.day });
99
+ }
100
+
85
101
  export function clampTargetDate(date: DateValue, minValue?: DateValue, maxValue?: DateValue): DateValue {
86
102
  let candidateDay = date;
87
103
 
88
- if (minValue && candidateDay.compare(minValue) < 0) {
89
- candidateDay = minValue.copy();
104
+ if (minValue && compareDay(candidateDay, minValue) < 0) {
105
+ candidateDay = setDay(candidateDay, minValue);
90
106
  }
91
107
 
92
- if (maxValue && candidateDay.compare(maxValue) > 0) {
93
- candidateDay = maxValue.copy();
108
+ if (maxValue && compareDay(candidateDay, maxValue) > 0) {
109
+ candidateDay = setDay(candidateDay, maxValue);
94
110
  }
95
111
 
96
112
  return candidateDay;