akar 2.0.21 → 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.
- package/dist/Combobox/ComboboxCancel.cjs +1 -1
- package/dist/Combobox/ComboboxCancel.cjs.map +1 -1
- package/dist/Combobox/ComboboxCancel.js +1 -1
- package/dist/Combobox/ComboboxCancel.js.map +1 -1
- package/dist/Dialog/DialogContent.cjs.map +1 -1
- package/dist/Dialog/DialogContent.js.map +1 -1
- package/dist/DismissableLayer/DismissableLayer.cjs +6 -8
- package/dist/DismissableLayer/DismissableLayer.cjs.map +1 -1
- package/dist/DismissableLayer/DismissableLayer.js +6 -8
- package/dist/DismissableLayer/DismissableLayer.js.map +1 -1
- package/dist/DismissableLayer/DismissableLayerBranch.cjs +1 -1
- package/dist/DismissableLayer/DismissableLayerBranch.js +1 -1
- package/dist/DismissableLayer/context.cjs +0 -1
- package/dist/DismissableLayer/context.cjs.map +1 -1
- package/dist/DismissableLayer/context.js +0 -1
- package/dist/DismissableLayer/context.js.map +1 -1
- package/dist/Menu/MenuSubTrigger.cjs +4 -2
- package/dist/Menu/MenuSubTrigger.cjs.map +1 -1
- package/dist/Menu/MenuSubTrigger.js +4 -2
- package/dist/Menu/MenuSubTrigger.js.map +1 -1
- package/dist/NumberField/NumberFieldRoot.cjs +9 -2
- package/dist/NumberField/NumberFieldRoot.cjs.map +1 -1
- package/dist/NumberField/NumberFieldRoot.js +9 -2
- package/dist/NumberField/NumberFieldRoot.js.map +1 -1
- package/dist/RovingFocus/RovingFocusItem.cjs +13 -2
- package/dist/RovingFocus/RovingFocusItem.cjs.map +1 -1
- package/dist/RovingFocus/RovingFocusItem.js +14 -3
- package/dist/RovingFocus/RovingFocusItem.js.map +1 -1
- package/dist/TagsInput/TagsInputInput.cjs +2 -1
- package/dist/TagsInput/TagsInputInput.cjs.map +1 -1
- package/dist/TagsInput/TagsInputInput.js +2 -1
- package/dist/TagsInput/TagsInputInput.js.map +1 -1
- package/dist/Toast/ToastAction.cjs +1 -1
- package/dist/Toast/ToastAction.cjs.map +1 -1
- package/dist/Toast/ToastAction.js +1 -1
- package/dist/Toast/ToastAction.js.map +1 -1
- package/dist/Toast/ToastArrow.cjs.map +1 -1
- package/dist/Toast/ToastArrow.js.map +1 -1
- package/dist/Toast/ToastDescription.cjs +3 -3
- package/dist/Toast/ToastDescription.cjs.map +1 -1
- package/dist/Toast/ToastDescription.js +4 -4
- package/dist/Toast/ToastDescription.js.map +1 -1
- package/dist/Toast/ToastRootImpl.cjs +3 -3
- package/dist/Toast/ToastRootImpl.cjs.map +1 -1
- package/dist/Toast/ToastRootImpl.js +3 -3
- package/dist/Toast/ToastRootImpl.js.map +1 -1
- package/dist/Toast/ToastTitle.cjs +2 -2
- package/dist/Toast/ToastTitle.cjs.map +1 -1
- package/dist/Toast/ToastTitle.js +3 -3
- package/dist/Toast/ToastTitle.js.map +1 -1
- package/dist/Toast/createToastManager.cjs +1 -1
- package/dist/Toast/createToastManager.js +1 -1
- package/dist/Toast/useToastStore.cjs +1 -3
- package/dist/Toast/useToastStore.cjs.map +1 -1
- package/dist/Toast/useToastStore.js +1 -3
- package/dist/Toast/useToastStore.js.map +1 -1
- package/dist/constant.d.ts.map +1 -1
- package/dist/index.cjs +2 -1
- package/dist/index.js +2 -1
- package/dist/index2.d.cts +4 -4
- package/dist/index2.d.cts.map +1 -1
- package/dist/index2.d.ts +16 -16
- package/dist/index2.d.ts.map +1 -1
- package/dist/index3.d.cts +711 -708
- package/dist/index3.d.cts.map +1 -1
- package/dist/index3.d.ts +705 -702
- package/dist/index3.d.ts.map +1 -1
- package/dist/internal.cjs +2 -1
- package/dist/internal.d.cts +2 -2
- package/dist/internal.d.cts.map +1 -1
- package/dist/internal.d.ts +2 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +2 -1
- package/dist/shared/bodyPointerEvents.cjs +46 -0
- package/dist/shared/bodyPointerEvents.cjs.map +1 -0
- package/dist/shared/bodyPointerEvents.js +34 -0
- package/dist/shared/bodyPointerEvents.js.map +1 -0
- package/dist/shared/useBodyScrollLock.cjs +8 -7
- package/dist/shared/useBodyScrollLock.cjs.map +1 -1
- package/dist/shared/useBodyScrollLock.js +8 -7
- package/dist/shared/useBodyScrollLock.js.map +1 -1
- package/dist/shared/useCalendarKeyboardNavigation.cjs +21 -2
- package/dist/shared/useCalendarKeyboardNavigation.cjs.map +1 -1
- package/dist/shared/useCalendarKeyboardNavigation.js +21 -2
- package/dist/shared/useCalendarKeyboardNavigation.js.map +1 -1
- package/dist/shared.cjs +1 -1
- package/dist/shared.js +1 -1
- package/package.json +4 -1
- package/src/Combobox/ComboboxCancel.vue +4 -3
- package/src/DismissableLayer/DismissableLayer.vue +21 -27
- package/src/DismissableLayer/context.ts +1 -1
- package/src/Menu/MenuSubTrigger.vue +10 -4
- package/src/NumberField/NumberFieldRoot.vue +11 -2
- package/src/RovingFocus/RovingFocusItem.vue +24 -16
- package/src/TagsInput/TagsInputInput.vue +11 -5
- package/src/Toast/ToastAction.vue +8 -9
- package/src/Toast/ToastArrow.vue +0 -1
- package/src/Toast/ToastDescription.vue +4 -5
- package/src/Toast/ToastRootImpl.vue +5 -5
- package/src/Toast/ToastTitle.vue +3 -1
- package/src/Toast/createToastManager.ts +1 -1
- package/src/Toast/useToastStore.ts +1 -3
- package/src/shared/bodyPointerEvents.ts +38 -0
- package/src/shared/useBodyScrollLock.ts +7 -10
- 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
|
-
*
|
|
8
|
-
*
|
|
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, '
|
|
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="
|
|
150
|
+
v-bind="itemProps"
|
|
145
151
|
:id="subContext.triggerId"
|
|
146
152
|
:ref="
|
|
147
153
|
(vnode: Element | ComponentPublicInstance | null) => {
|
|
@@ -35,6 +35,8 @@ export interface NumberFieldRootProps extends PrimitiveProps, FormFieldProps {
|
|
|
35
35
|
invertWheelChange?: boolean;
|
|
36
36
|
/** Id of the element */
|
|
37
37
|
id?: string;
|
|
38
|
+
/** The value the first increment or decrement sets when the field is empty. It is clamped to `min`/`max` but not snapped to `step`. Defaults to `min`, or `0` when `min` is not set. */
|
|
39
|
+
startingValue?: number;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
// `undefined` is emitted when the input is cleared. Documented here rather than on the member
|
|
@@ -87,7 +89,7 @@ const props = withDefaults(defineProps<NumberFieldRootProps>(), {
|
|
|
87
89
|
focusOnChange: true,
|
|
88
90
|
});
|
|
89
91
|
const emits = defineEmits<NumberFieldRootEmits>();
|
|
90
|
-
const { disabled, readonly, disableWheelChange, invertWheelChange, min, max, step, stepSnapping, allowInvalid, formatOptions, id, locale: propLocale } = toRefs(props);
|
|
92
|
+
const { disabled, readonly, disableWheelChange, invertWheelChange, min, max, step, stepSnapping, allowInvalid, formatOptions, id, locale: propLocale, startingValue } = toRefs(props);
|
|
91
93
|
|
|
92
94
|
const modelValue = useVModel(props, 'modelValue', emits, {
|
|
93
95
|
defaultValue: props.defaultValue,
|
|
@@ -157,7 +159,14 @@ function handleChangingValue(type: 'increase' | 'decrease', multiplier = 1) {
|
|
|
157
159
|
if (isNaN(currentInputValue)) {
|
|
158
160
|
// Route the fallback through clampInputValue so the min/max contract still holds
|
|
159
161
|
// (e.g. a negative max would otherwise be violated by the bare 0 fallback).
|
|
160
|
-
|
|
162
|
+
// `startingValue` is used as given: kept within min/max, but not snapped to the step grid
|
|
163
|
+
// (a starting price of 40 with step 3 stays 40). The next tick aligns it via getNextValue.
|
|
164
|
+
modelValue.value = startingValue.value === undefined
|
|
165
|
+
? clampInputValue(min.value ?? 0)
|
|
166
|
+
: numberParser.parse(numberFormatter.format(clamp(startingValue.value, {
|
|
167
|
+
min: min.value,
|
|
168
|
+
max: max.value,
|
|
169
|
+
})));
|
|
161
170
|
return;
|
|
162
171
|
}
|
|
163
172
|
|
|
@@ -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
|
-
()
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
74
|
-
//
|
|
75
|
-
//
|
|
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) {
|
|
@@ -5,6 +5,8 @@ export interface ToastActionProps extends ToastCloseProps {
|
|
|
5
5
|
/**
|
|
6
6
|
* A short description for an alternate way to carry out the action. For screen reader users
|
|
7
7
|
* who will not be able to navigate to the button easily/quickly.
|
|
8
|
+
*
|
|
9
|
+
* A rendered action requires `altText`, unless the toast passed to `ToastRoot` has `actionProps.altText`.
|
|
8
10
|
* @example <ToastAction altText="Goto account settings to upgrade">Upgrade</ToastAction>
|
|
9
11
|
* @example <ToastAction altText="Undo (Alt+U)">Undo</ToastAction>
|
|
10
12
|
*/
|
|
@@ -25,17 +27,13 @@ import { useForwardExpose } from '@/shared';
|
|
|
25
27
|
import ToastAnnounceExclude from './ToastAnnounceExclude.vue';
|
|
26
28
|
import { injectToastRootContext } from './ToastRootImpl.vue';
|
|
27
29
|
|
|
28
|
-
const props = withDefaults(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
closeOnClick: true,
|
|
33
|
-
},
|
|
34
|
-
);
|
|
30
|
+
const props = withDefaults(defineProps<ToastActionProps>(), {
|
|
31
|
+
as: 'button',
|
|
32
|
+
closeOnClick: true,
|
|
33
|
+
});
|
|
35
34
|
|
|
36
35
|
const rootContext = injectToastRootContext();
|
|
37
36
|
const { forwardRef } = useForwardExpose();
|
|
38
|
-
|
|
39
37
|
const slots = useSlots();
|
|
40
38
|
|
|
41
39
|
const actionProps = computed(() => rootContext.toast.value?.actionProps);
|
|
@@ -50,7 +48,8 @@ if (isRendered.value && !altText.value) {
|
|
|
50
48
|
function handleClick(event: MouseEvent) {
|
|
51
49
|
actionProps.value?.onClick?.(event);
|
|
52
50
|
if (actionProps.value?.closeOnClick ?? props.closeOnClick) {
|
|
53
|
-
|
|
51
|
+
// Pass the event on, like `ToastClose`: a keyboard click hands focus to the viewport.
|
|
52
|
+
rootContext.onClose(event as PointerEvent);
|
|
54
53
|
}
|
|
55
54
|
}
|
|
56
55
|
</script>
|
package/src/Toast/ToastArrow.vue
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { PrimitiveProps } from '@/Primitive';
|
|
3
3
|
import { useForwardExpose } from '@/shared';
|
|
4
|
-
import { injectToastRootContext } from './ToastRootImpl.vue';
|
|
5
4
|
|
|
6
5
|
export interface ToastDescriptionProps extends PrimitiveProps {}
|
|
7
6
|
</script>
|
|
8
7
|
|
|
9
8
|
<script setup lang="ts">
|
|
10
9
|
import { Primitive } from '@/Primitive';
|
|
10
|
+
import { injectToastRootContext } from './ToastRootImpl.vue';
|
|
11
11
|
|
|
12
12
|
const props = defineProps<ToastDescriptionProps>();
|
|
13
|
-
|
|
14
13
|
useForwardExpose();
|
|
15
|
-
|
|
16
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.
|
|
17
18
|
</script>
|
|
18
19
|
|
|
19
20
|
<template>
|
|
20
|
-
<!-- A managed toast without a description renders nothing, unless slot content is given. -->
|
|
21
21
|
<Primitive
|
|
22
22
|
v-if="$slots.default || !rootContext?.toast.value || rootContext.toast.value.description"
|
|
23
23
|
v-bind="props"
|
|
24
24
|
>
|
|
25
25
|
<slot>{{ rootContext?.toast.value?.description }}</slot>
|
|
26
|
-
<slot />
|
|
27
26
|
</Primitive>
|
|
28
27
|
</template>
|
|
@@ -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">
|
|
@@ -112,7 +112,7 @@ function startTimer(duration: number) {
|
|
|
112
112
|
function handleClose(event?: PointerEvent) {
|
|
113
113
|
const isNonPointerEvent = event?.pointerType === '';
|
|
114
114
|
|
|
115
|
-
//
|
|
115
|
+
// akar: update to only perform focus when user focus via keyboard
|
|
116
116
|
// focus viewport if focus is within toast to read the remaining toast
|
|
117
117
|
// count to SR users and ensure focus isn't lost
|
|
118
118
|
const isFocusInToast = currentElement.value?.contains(getActiveElement());
|
|
@@ -269,9 +269,9 @@ provideToastRootContext({ onClose: handleClose, toast: toRef(props, 'toast') });
|
|
|
269
269
|
:inert="stack.limited || undefined"
|
|
270
270
|
:style="{
|
|
271
271
|
...(providerContext.disableSwipe.value ? undefined : { userSelect: 'none', touchAction: 'none' }),
|
|
272
|
-
'--
|
|
273
|
-
'--
|
|
274
|
-
'--
|
|
272
|
+
'--akar-toast-index': stack.index,
|
|
273
|
+
'--akar-toast-offset-y': `${stack.offsetY}px`,
|
|
274
|
+
'--akar-toast-height': stackEntry.height ? `${stackEntry.height}px` : undefined,
|
|
275
275
|
}"
|
|
276
276
|
@pointerdown.left="(event: PointerEvent) => {
|
|
277
277
|
if (providerContext.disableSwipe.value) return;
|
package/src/Toast/ToastTitle.vue
CHANGED
|
@@ -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"
|
|
@@ -59,9 +59,7 @@ export function useToastStore(): ToastStore {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
toasts.value = toasts.value.map((toast) => closing.includes(toast) ? { ...toast, open: false } : toast);
|
|
62
|
-
closing.forEach((toast) =>
|
|
63
|
-
toast.onClose?.();
|
|
64
|
-
});
|
|
62
|
+
closing.forEach((toast) => toast.onClose?.());
|
|
65
63
|
}
|
|
66
64
|
|
|
67
65
|
function update(id: string, updates: ToastUpdateOptions | ((prevToast: ToastObject) => ToastUpdateOptions)) {
|
|
@@ -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 {
|
|
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
|
-
|
|
36
|
-
//
|
|
37
|
-
|
|
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
|
|
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
|
|
89
|
-
candidateDay = minValue
|
|
104
|
+
if (minValue && compareDay(candidateDay, minValue) < 0) {
|
|
105
|
+
candidateDay = setDay(candidateDay, minValue);
|
|
90
106
|
}
|
|
91
107
|
|
|
92
|
-
if (maxValue && candidateDay
|
|
93
|
-
candidateDay = maxValue
|
|
108
|
+
if (maxValue && compareDay(candidateDay, maxValue) > 0) {
|
|
109
|
+
candidateDay = setDay(candidateDay, maxValue);
|
|
94
110
|
}
|
|
95
111
|
|
|
96
112
|
return candidateDay;
|