akar 2.0.20 → 2.0.21
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/Autocomplete/AutocompleteRoot.cjs +8 -2
- package/dist/Autocomplete/AutocompleteRoot.cjs.map +1 -1
- package/dist/Autocomplete/AutocompleteRoot.js +8 -2
- package/dist/Autocomplete/AutocompleteRoot.js.map +1 -1
- package/dist/ColorSwatchPicker/ColorSwatchPickerRoot.cjs +5 -0
- package/dist/ColorSwatchPicker/ColorSwatchPickerRoot.cjs.map +1 -1
- package/dist/ColorSwatchPicker/ColorSwatchPickerRoot.js +5 -0
- package/dist/ColorSwatchPicker/ColorSwatchPickerRoot.js.map +1 -1
- package/dist/Combobox/ComboboxRoot.cjs +7 -1
- package/dist/Combobox/ComboboxRoot.cjs.map +1 -1
- package/dist/Combobox/ComboboxRoot.js +7 -1
- package/dist/Combobox/ComboboxRoot.js.map +1 -1
- package/dist/ContextMenu/ContextMenuRoot.cjs +12 -6
- package/dist/ContextMenu/ContextMenuRoot.cjs.map +1 -1
- package/dist/ContextMenu/ContextMenuRoot.js +13 -7
- package/dist/ContextMenu/ContextMenuRoot.js.map +1 -1
- package/dist/ContextMenu/ContextMenuTrigger.cjs +18 -2
- package/dist/ContextMenu/ContextMenuTrigger.cjs.map +1 -1
- package/dist/ContextMenu/ContextMenuTrigger.js +19 -3
- package/dist/ContextMenu/ContextMenuTrigger.js.map +1 -1
- package/dist/DateField/DateFieldRoot.cjs +1 -0
- package/dist/DateField/DateFieldRoot.cjs.map +1 -1
- package/dist/DateField/DateFieldRoot.js +1 -0
- package/dist/DateField/DateFieldRoot.js.map +1 -1
- package/dist/DateRangeField/DateRangeFieldRoot.cjs +1 -0
- package/dist/DateRangeField/DateRangeFieldRoot.cjs.map +1 -1
- package/dist/DateRangeField/DateRangeFieldRoot.js +1 -0
- package/dist/DateRangeField/DateRangeFieldRoot.js.map +1 -1
- package/dist/DismissableLayer/DismissableLayer.cjs +1 -1
- package/dist/DismissableLayer/DismissableLayer.cjs.map +1 -1
- package/dist/DismissableLayer/DismissableLayer.js +1 -1
- package/dist/DismissableLayer/DismissableLayer.js.map +1 -1
- package/dist/DismissableLayer/utils.cjs +8 -3
- package/dist/DismissableLayer/utils.cjs.map +1 -1
- package/dist/DismissableLayer/utils.js +8 -3
- package/dist/DismissableLayer/utils.js.map +1 -1
- package/dist/Drawer/DrawerContent.cjs +2 -1
- package/dist/Drawer/DrawerContent.cjs.map +1 -1
- package/dist/Drawer/DrawerContent.js +2 -1
- package/dist/Drawer/DrawerContent.js.map +1 -1
- package/dist/Drawer/DrawerContentImpl.cjs +10 -4
- package/dist/Drawer/DrawerContentImpl.cjs.map +1 -1
- package/dist/Drawer/DrawerContentImpl.js +11 -5
- package/dist/Drawer/DrawerContentImpl.js.map +1 -1
- package/dist/Drawer/DrawerRoot.cjs +14 -3
- package/dist/Drawer/DrawerRoot.cjs.map +1 -1
- package/dist/Drawer/DrawerRoot.js +14 -3
- package/dist/Drawer/DrawerRoot.js.map +1 -1
- package/dist/Drawer/DrawerSwipeArea.cjs +5 -2
- package/dist/Drawer/DrawerSwipeArea.cjs.map +1 -1
- package/dist/Drawer/DrawerSwipeArea.js +6 -3
- package/dist/Drawer/DrawerSwipeArea.js.map +1 -1
- package/dist/DropdownMenu/DropdownMenuTrigger.cjs +2 -1
- package/dist/DropdownMenu/DropdownMenuTrigger.cjs.map +1 -1
- package/dist/DropdownMenu/DropdownMenuTrigger.js +2 -1
- package/dist/DropdownMenu/DropdownMenuTrigger.js.map +1 -1
- package/dist/Listbox/ListboxRoot.cjs +25 -2
- package/dist/Listbox/ListboxRoot.cjs.map +1 -1
- package/dist/Listbox/ListboxRoot.js +25 -2
- package/dist/Listbox/ListboxRoot.js.map +1 -1
- package/dist/Menubar/MenubarTrigger.cjs +2 -1
- package/dist/Menubar/MenubarTrigger.cjs.map +1 -1
- package/dist/Menubar/MenubarTrigger.js +2 -1
- package/dist/Menubar/MenubarTrigger.js.map +1 -1
- package/dist/NavigationMenu/NavigationMenuTrigger.cjs +3 -2
- package/dist/NavigationMenu/NavigationMenuTrigger.cjs.map +1 -1
- package/dist/NavigationMenu/NavigationMenuTrigger.js +3 -2
- package/dist/NavigationMenu/NavigationMenuTrigger.js.map +1 -1
- package/dist/NumberField/NumberFieldRoot.cjs +12 -3
- package/dist/NumberField/NumberFieldRoot.cjs.map +1 -1
- package/dist/NumberField/NumberFieldRoot.js +12 -3
- package/dist/NumberField/NumberFieldRoot.js.map +1 -1
- package/dist/PinInput/PinInputRoot.cjs +1 -0
- package/dist/PinInput/PinInputRoot.cjs.map +1 -1
- package/dist/PinInput/PinInputRoot.js +1 -0
- package/dist/PinInput/PinInputRoot.js.map +1 -1
- package/dist/RovingFocus/RovingFocusItem.cjs +7 -2
- package/dist/RovingFocus/RovingFocusItem.cjs.map +1 -1
- package/dist/RovingFocus/RovingFocusItem.js +7 -2
- package/dist/RovingFocus/RovingFocusItem.js.map +1 -1
- package/dist/Select/SelectContent.cjs +4 -0
- package/dist/Select/SelectContent.cjs.map +1 -1
- package/dist/Select/SelectContent.js +4 -0
- package/dist/Select/SelectContent.js.map +1 -1
- package/dist/Select/SelectContentImpl.cjs +7 -2
- package/dist/Select/SelectContentImpl.cjs.map +1 -1
- package/dist/Select/SelectContentImpl.js +9 -4
- package/dist/Select/SelectContentImpl.js.map +1 -1
- package/dist/Select/SelectTrigger.cjs +24 -15
- package/dist/Select/SelectTrigger.cjs.map +1 -1
- package/dist/Select/SelectTrigger.js +25 -16
- package/dist/Select/SelectTrigger.js.map +1 -1
- package/dist/Tabs/TabsTrigger.cjs +4 -1
- package/dist/Tabs/TabsTrigger.cjs.map +1 -1
- package/dist/Tabs/TabsTrigger.js +4 -1
- package/dist/Tabs/TabsTrigger.js.map +1 -1
- package/dist/TimeField/TimeFieldRoot.cjs +1 -0
- package/dist/TimeField/TimeFieldRoot.cjs.map +1 -1
- package/dist/TimeField/TimeFieldRoot.js +1 -0
- package/dist/TimeField/TimeFieldRoot.js.map +1 -1
- package/dist/TimeRangeField/TimeRangeFieldRoot.cjs +1 -0
- package/dist/TimeRangeField/TimeRangeFieldRoot.cjs.map +1 -1
- package/dist/TimeRangeField/TimeRangeFieldRoot.js +1 -0
- package/dist/TimeRangeField/TimeRangeFieldRoot.js.map +1 -1
- package/dist/Toast/ToastAction.cjs +14 -6
- package/dist/Toast/ToastAction.cjs.map +1 -1
- package/dist/Toast/ToastAction.js +15 -7
- package/dist/Toast/ToastAction.js.map +1 -1
- package/dist/Toast/ToastArrow.cjs +53 -0
- package/dist/Toast/ToastArrow.cjs.map +1 -0
- package/dist/Toast/ToastArrow.js +47 -0
- package/dist/Toast/ToastArrow.js.map +1 -0
- package/dist/Toast/ToastDescription.cjs +5 -3
- package/dist/Toast/ToastDescription.cjs.map +1 -1
- package/dist/Toast/ToastDescription.js +6 -4
- package/dist/Toast/ToastDescription.js.map +1 -1
- package/dist/Toast/ToastPositioner.cjs +166 -0
- package/dist/Toast/ToastPositioner.cjs.map +1 -0
- package/dist/Toast/ToastPositioner.js +154 -0
- package/dist/Toast/ToastPositioner.js.map +1 -0
- package/dist/Toast/ToastProvider.cjs +74 -3
- package/dist/Toast/ToastProvider.cjs.map +1 -1
- package/dist/Toast/ToastProvider.js +75 -4
- package/dist/Toast/ToastProvider.js.map +1 -1
- package/dist/Toast/ToastRoot.cjs +38 -15
- package/dist/Toast/ToastRoot.cjs.map +1 -1
- package/dist/Toast/ToastRoot.js +39 -16
- package/dist/Toast/ToastRoot.js.map +1 -1
- package/dist/Toast/ToastRootImpl.cjs +69 -12
- package/dist/Toast/ToastRootImpl.cjs.map +1 -1
- package/dist/Toast/ToastRootImpl.js +74 -17
- package/dist/Toast/ToastRootImpl.js.map +1 -1
- package/dist/Toast/ToastTitle.cjs +5 -3
- package/dist/Toast/ToastTitle.cjs.map +1 -1
- package/dist/Toast/ToastTitle.js +6 -4
- package/dist/Toast/ToastTitle.js.map +1 -1
- package/dist/Toast/ToastViewport.cjs +40 -5
- package/dist/Toast/ToastViewport.cjs.map +1 -1
- package/dist/Toast/ToastViewport.js +41 -6
- package/dist/Toast/ToastViewport.js.map +1 -1
- package/dist/Toast/createToastManager.cjs +119 -0
- package/dist/Toast/createToastManager.cjs.map +1 -0
- package/dist/Toast/createToastManager.js +95 -0
- package/dist/Toast/createToastManager.js.map +1 -0
- package/dist/Toast/useToastManager.cjs +25 -0
- package/dist/Toast/useToastManager.cjs.map +1 -0
- package/dist/Toast/useToastManager.js +20 -0
- package/dist/Toast/useToastManager.js.map +1 -0
- package/dist/Toast/useToastStore.cjs +87 -0
- package/dist/Toast/useToastStore.cjs.map +1 -0
- package/dist/Toast/useToastStore.js +81 -0
- package/dist/Toast/useToastStore.js.map +1 -0
- package/dist/Toast/utils.cjs +2 -4
- package/dist/Toast/utils.cjs.map +1 -1
- package/dist/Toast/utils.js +2 -3
- package/dist/Toast/utils.js.map +1 -1
- package/dist/Tree/TreeRoot.cjs +9 -3
- package/dist/Tree/TreeRoot.cjs.map +1 -1
- package/dist/Tree/TreeRoot.js +9 -3
- package/dist/Tree/TreeRoot.js.map +1 -1
- package/dist/Tree/TreeVirtualizer.cjs +10 -1
- package/dist/Tree/TreeVirtualizer.cjs.map +1 -1
- package/dist/Tree/TreeVirtualizer.js +11 -2
- package/dist/Tree/TreeVirtualizer.js.map +1 -1
- package/dist/VisuallyHidden/VisuallyHidden.cjs +1 -1
- package/dist/VisuallyHidden/VisuallyHidden.cjs.map +1 -1
- package/dist/VisuallyHidden/VisuallyHidden.js +1 -1
- package/dist/VisuallyHidden/VisuallyHidden.js.map +1 -1
- package/dist/composables/useSwipeDismiss.cjs +26 -6
- package/dist/composables/useSwipeDismiss.cjs.map +1 -1
- package/dist/composables/useSwipeDismiss.js +26 -6
- package/dist/composables/useSwipeDismiss.js.map +1 -1
- package/dist/constant/components.cjs +6 -2
- package/dist/constant/components.cjs.map +1 -1
- package/dist/constant/components.js +6 -2
- package/dist/constant/components.js.map +1 -1
- package/dist/constant.d.cts +2 -2
- package/dist/constant.d.cts.map +1 -1
- package/dist/constant.d.ts +2 -2
- package/dist/constant.d.ts.map +1 -1
- package/dist/index.cjs +10 -0
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +7 -1
- package/dist/index2.d.cts +21 -9
- package/dist/index2.d.cts.map +1 -1
- package/dist/index2.d.ts +33 -21
- package/dist/index2.d.ts.map +1 -1
- package/dist/index3.d.cts +1681 -1435
- package/dist/index3.d.cts.map +1 -1
- package/dist/index3.d.ts +1678 -1432
- package/dist/index3.d.ts.map +1 -1
- package/dist/internal.cjs +1 -0
- package/dist/internal.d.cts +3 -3
- package/dist/internal.d.cts.map +1 -1
- package/dist/internal.d.ts +3 -3
- package/dist/internal.js +1 -0
- package/dist/namespaced/index.cjs +3 -1
- package/dist/namespaced/index.d.cts +3 -1
- package/dist/namespaced/index.d.mts +3 -1
- package/dist/namespaced/index.mjs +4 -2
- package/dist/shared/isHTMLElement.cjs +16 -0
- package/dist/shared/isHTMLElement.cjs.map +1 -0
- package/dist/shared/isHTMLElement.js +10 -0
- package/dist/shared/isHTMLElement.js.map +1 -0
- package/dist/shared/useForwardPropsEmits.cjs.map +1 -1
- package/dist/shared/useForwardPropsEmits.js.map +1 -1
- package/dist/shared.cjs +2 -0
- package/dist/shared.d.cts +2 -2
- package/dist/shared.d.ts +2 -2
- package/dist/shared.js +2 -1
- package/package.json +18 -18
- package/src/Autocomplete/AutocompleteRoot.vue +4 -1
- package/src/Combobox/ComboboxRoot.vue +2 -1
- package/src/ContextMenu/ContextMenuRoot.vue +8 -7
- package/src/ContextMenu/ContextMenuTrigger.vue +37 -3
- package/src/DateField/DateFieldRoot.vue +1 -0
- package/src/DatePicker/DatePickerContent.vue +1 -1
- package/src/DateRangeField/DateRangeFieldRoot.vue +1 -0
- package/src/DateRangePicker/DateRangePickerContent.vue +1 -1
- package/src/DismissableLayer/DismissableLayer.vue +4 -0
- package/src/DismissableLayer/utils.ts +20 -7
- package/src/Drawer/DrawerContent.vue +2 -2
- package/src/Drawer/DrawerContentImpl.vue +19 -8
- package/src/Drawer/DrawerRoot.vue +23 -5
- package/src/Drawer/DrawerSwipeArea.vue +10 -3
- package/src/Drawer/composables/useSwipeDismiss.ts +51 -5
- package/src/DropdownMenu/DropdownMenuTrigger.vue +2 -1
- package/src/Listbox/ListboxRoot.vue +30 -2
- package/src/Menubar/MenubarTrigger.vue +2 -1
- package/src/NavigationMenu/NavigationMenuTrigger.vue +7 -2
- package/src/NumberField/NumberFieldRoot.vue +28 -4
- package/src/PinInput/PinInputRoot.vue +1 -0
- package/src/RovingFocus/RovingFocusItem.vue +13 -2
- package/src/Select/SelectContentImpl.vue +13 -3
- package/src/Select/SelectTrigger.vue +52 -21
- package/src/Tabs/TabsTrigger.vue +4 -1
- package/src/TimeField/TimeFieldRoot.vue +1 -0
- package/src/TimeRangeField/TimeRangeFieldRoot.vue +1 -0
- package/src/Toast/ToastAction.vue +22 -7
- package/src/Toast/ToastArrow.vue +38 -0
- package/src/Toast/ToastDescription.vue +10 -1
- package/src/Toast/ToastPositioner.vue +76 -0
- package/src/Toast/ToastProvider.vue +113 -5
- package/src/Toast/ToastRoot.vue +39 -8
- package/src/Toast/ToastRootImpl.vue +67 -17
- package/src/Toast/ToastTitle.vue +8 -2
- package/src/Toast/ToastViewport.vue +41 -3
- package/src/Toast/createToastManager.ts +207 -0
- package/src/Toast/index.ts +15 -0
- package/src/Toast/useToastManager.ts +23 -0
- package/src/Toast/useToastStore.ts +92 -0
- package/src/Toast/utils.ts +2 -4
- package/src/Tree/TreeRoot.vue +6 -1
- package/src/Tree/TreeVirtualizer.vue +17 -2
- package/src/VisuallyHidden/VisuallyHidden.vue +11 -1
- package/src/internal.ts +2 -1
- package/src/shared/index.ts +1 -0
- package/src/shared/isHTMLElement.ts +9 -0
- package/src/shared/useForwardPropsEmits.ts +12 -5
|
@@ -13,8 +13,19 @@ export const CONTEXT_UPDATE = 'dismissableLayer.update';
|
|
|
13
13
|
export const POINTER_DOWN_OUTSIDE = 'dismissableLayer.pointerDownOutside';
|
|
14
14
|
export const FOCUS_OUTSIDE = 'dismissableLayer.focusOutside';
|
|
15
15
|
|
|
16
|
+
function isElement(node: unknown): node is Element {
|
|
17
|
+
if (typeof node !== 'object' || node === null) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
// Compare against the node's own window too, so elements from another
|
|
21
|
+
// realm (e.g. a layer rendered inside an iframe) are recognized
|
|
22
|
+
const ownerWindow = (node as Node).ownerDocument?.defaultView;
|
|
23
|
+
return (typeof Element !== 'undefined' && node instanceof Element)
|
|
24
|
+
|| (!!ownerWindow && node instanceof ownerWindow.Element);
|
|
25
|
+
}
|
|
26
|
+
|
|
16
27
|
export function isLayerExist(layerElement: HTMLElement, targetElement: HTMLElement) {
|
|
17
|
-
if (!(targetElement
|
|
28
|
+
if (!isElement(targetElement)) {
|
|
18
29
|
return false;
|
|
19
30
|
}
|
|
20
31
|
|
|
@@ -60,9 +71,6 @@ export function usePointerDownOutside(
|
|
|
60
71
|
element?: Ref<HTMLElement | undefined>,
|
|
61
72
|
enabled: MaybeRefOrGetter<boolean> = true,
|
|
62
73
|
) {
|
|
63
|
-
const ownerDocument: Document
|
|
64
|
-
= element?.value?.ownerDocument ?? globalThis?.document;
|
|
65
|
-
|
|
66
74
|
const isPointerInsideDOMTree = ref(false);
|
|
67
75
|
const handleClickRef = ref(() => {});
|
|
68
76
|
|
|
@@ -70,6 +78,11 @@ export function usePointerDownOutside(
|
|
|
70
78
|
if (!isClient || !toValue(enabled)) {
|
|
71
79
|
return;
|
|
72
80
|
}
|
|
81
|
+
// Resolved inside the effect so it tracks `element`: the layer is usually
|
|
82
|
+
// not mounted yet when this composable runs, and listening on the global
|
|
83
|
+
// `document` would miss events from a layer rendered inside an iframe.
|
|
84
|
+
const ownerDocument: Document
|
|
85
|
+
= element?.value?.ownerDocument ?? globalThis?.document;
|
|
73
86
|
const handlePointerDown = async (event: PointerEvent) => {
|
|
74
87
|
const target = event.target as HTMLElement | undefined;
|
|
75
88
|
|
|
@@ -169,14 +182,14 @@ export function useFocusOutside(
|
|
|
169
182
|
element?: Ref<HTMLElement | undefined>,
|
|
170
183
|
enabled: MaybeRefOrGetter<boolean> = true,
|
|
171
184
|
) {
|
|
172
|
-
const ownerDocument: Document
|
|
173
|
-
= element?.value?.ownerDocument ?? globalThis?.document;
|
|
174
|
-
|
|
175
185
|
const isFocusInsideDOMTree = ref(false);
|
|
176
186
|
watchEffect((cleanupFn) => {
|
|
177
187
|
if (!isClient || !toValue(enabled)) {
|
|
178
188
|
return;
|
|
179
189
|
}
|
|
190
|
+
// See `usePointerDownOutside`: resolved inside the effect to track `element`.
|
|
191
|
+
const ownerDocument: Document
|
|
192
|
+
= element?.value?.ownerDocument ?? globalThis?.document;
|
|
180
193
|
const handleFocus = async (event: FocusEvent) => {
|
|
181
194
|
if (!element?.value) {
|
|
182
195
|
return;
|
|
@@ -10,7 +10,7 @@ export interface DrawerContentProps extends Omit<DrawerContentImplProps, 'trapFo
|
|
|
10
10
|
<script setup lang="ts">
|
|
11
11
|
import { computed, ref } from 'vue';
|
|
12
12
|
import { Presence } from '@/Presence';
|
|
13
|
-
import { useEmitAsProps, useForwardExpose, useHideOthers } from '@/shared';
|
|
13
|
+
import { isHTMLElement, useEmitAsProps, useForwardExpose, useHideOthers } from '@/shared';
|
|
14
14
|
import DrawerContentImpl from './DrawerContentImpl.vue';
|
|
15
15
|
import { injectDrawerRootContext } from './DrawerRoot.vue';
|
|
16
16
|
|
|
@@ -43,7 +43,7 @@ function finalFocusElement() {
|
|
|
43
43
|
if (props.finalFocus === false) {
|
|
44
44
|
return undefined;
|
|
45
45
|
}
|
|
46
|
-
if (props.finalFocus
|
|
46
|
+
if (isHTMLElement(props.finalFocus)) {
|
|
47
47
|
return props.finalFocus;
|
|
48
48
|
}
|
|
49
49
|
return rootContext.triggerElement.value;
|
|
@@ -31,11 +31,11 @@ export interface DrawerContentImplProps extends DismissableLayerProps {
|
|
|
31
31
|
<script setup lang="ts">
|
|
32
32
|
import type { SwipeDirection } from './utils';
|
|
33
33
|
import { useResizeObserver } from '@vueuse/core';
|
|
34
|
-
import { computed, onMounted, onUnmounted, watch } from 'vue';
|
|
34
|
+
import { computed, nextTick, onMounted, onUnmounted, watch } from 'vue';
|
|
35
35
|
import { DismissableLayer } from '@/DismissableLayer';
|
|
36
36
|
import { FocusScope } from '@/FocusScope';
|
|
37
37
|
import { focus } from '@/FocusScope/utils';
|
|
38
|
-
import { useForwardExpose } from '@/shared';
|
|
38
|
+
import { isHTMLElement, useForwardExpose } from '@/shared';
|
|
39
39
|
import { useDrawerSnapPoints } from './composables/useDrawerSnapPoints';
|
|
40
40
|
import { useSwipeDismiss } from './composables/useSwipeDismiss';
|
|
41
41
|
import { injectDrawerRootContext } from './DrawerRoot.vue';
|
|
@@ -63,7 +63,7 @@ const { activeSnapPointOffset, snapToNearest } = useDrawerSnapPoints({
|
|
|
63
63
|
viewportRef: currentElement,
|
|
64
64
|
onSnapPointChange: (point) => {
|
|
65
65
|
if (point === null) {
|
|
66
|
-
rootContext.onOpenChange(false);
|
|
66
|
+
rootContext.onOpenChange(false, 'swipe');
|
|
67
67
|
} else {
|
|
68
68
|
rootContext.setActiveSnapPoint(point);
|
|
69
69
|
}
|
|
@@ -135,7 +135,7 @@ const swipeDirections = computed<Array<SwipeDirection>>(() => {
|
|
|
135
135
|
let lastRawDelta = { x: 0, y: 0 };
|
|
136
136
|
|
|
137
137
|
// Swipe dismiss
|
|
138
|
-
const { isSwiping } = useSwipeDismiss({
|
|
138
|
+
const { isSwiping, restore: restoreSwipe } = useSwipeDismiss({
|
|
139
139
|
enabled: computed(() => rootContext.open.value),
|
|
140
140
|
elementRef: currentElement,
|
|
141
141
|
directions: swipeDirections,
|
|
@@ -143,12 +143,23 @@ const { isSwiping } = useSwipeDismiss({
|
|
|
143
143
|
x: DRAWER_CSS_VARS.swipeMovementX,
|
|
144
144
|
y: DRAWER_CSS_VARS.swipeMovementY,
|
|
145
145
|
},
|
|
146
|
+
ignoreSelectorWhenTouch: false,
|
|
146
147
|
canStart: () => !rootContext.nestedSwiping.value,
|
|
147
148
|
onDismiss() {
|
|
148
|
-
if (!hasSnapPoints.value) {
|
|
149
|
-
rootContext.onOpenChange(false, 'swipe');
|
|
150
|
-
}
|
|
151
149
|
// With snap points, onRelease handles snapping
|
|
150
|
+
if (hasSnapPoints.value) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (!rootContext.onOpenChange(false, 'swipe')) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
// BaseUI parity: a controlled parent may ignore `update:open`. Its `open`
|
|
157
|
+
// prop settles by the next tick; if it is still open, undo the dismissal.
|
|
158
|
+
nextTick(() => {
|
|
159
|
+
if (rootContext.open.value) {
|
|
160
|
+
restoreSwipe();
|
|
161
|
+
}
|
|
162
|
+
});
|
|
152
163
|
},
|
|
153
164
|
onRelease(velocity) {
|
|
154
165
|
// Write the `--drawer-swipe-strength` CSS var so consumer transitions can
|
|
@@ -275,7 +286,7 @@ function onMountAutoFocus(event: Event) {
|
|
|
275
286
|
}
|
|
276
287
|
if (props.initialFocus === false) {
|
|
277
288
|
event.preventDefault();
|
|
278
|
-
} else if (props.initialFocus
|
|
289
|
+
} else if (isHTMLElement(props.initialFocus)) {
|
|
279
290
|
event.preventDefault();
|
|
280
291
|
focus(props.initialFocus, { select: true });
|
|
281
292
|
}
|
|
@@ -20,6 +20,10 @@ export type DrawerOpenChangeReason
|
|
|
20
20
|
|
|
21
21
|
export interface DrawerOpenChangeDetails {
|
|
22
22
|
reason?: DrawerOpenChangeReason;
|
|
23
|
+
/** Keeps the drawer in its current state. Call it while handling `update:open`. */
|
|
24
|
+
cancel: () => void;
|
|
25
|
+
/** Whether `cancel()` was called. */
|
|
26
|
+
readonly isCanceled: boolean;
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
export interface DrawerRootProps {
|
|
@@ -49,7 +53,7 @@ export interface DrawerRootProps {
|
|
|
49
53
|
}
|
|
50
54
|
|
|
51
55
|
export type DrawerRootEmits = {
|
|
52
|
-
'update:open': [value: boolean, details
|
|
56
|
+
'update:open': [value: boolean, details: DrawerOpenChangeDetails];
|
|
53
57
|
'update:openComplete': [value: boolean];
|
|
54
58
|
'update:snapPoint': [value: DrawerSnapPoint | null];
|
|
55
59
|
};
|
|
@@ -68,7 +72,8 @@ export interface DrawerRootContext {
|
|
|
68
72
|
nestedSwiping: Ref<boolean>;
|
|
69
73
|
isSwiping: Ref<boolean>;
|
|
70
74
|
nestedSwipeProgressStore: NestedSwipeProgressStore;
|
|
71
|
-
|
|
75
|
+
/** Returns `false` when a listener canceled the change. */
|
|
76
|
+
onOpenChange: (value: boolean, reason?: DrawerOpenChangeReason) => boolean;
|
|
72
77
|
onOpenToggle: () => void;
|
|
73
78
|
notifyOpenComplete: (value: boolean) => void;
|
|
74
79
|
setActiveSnapPoint: (point: DrawerSnapPoint | null) => void;
|
|
@@ -222,11 +227,24 @@ function handleClose() {
|
|
|
222
227
|
|
|
223
228
|
function handleOpenChange(value: boolean, reason?: DrawerOpenChangeReason) {
|
|
224
229
|
if (open.value === value) {
|
|
225
|
-
return;
|
|
230
|
+
return true;
|
|
226
231
|
}
|
|
227
|
-
|
|
228
|
-
|
|
232
|
+
let isCanceled = false;
|
|
233
|
+
const details: DrawerOpenChangeDetails = {
|
|
234
|
+
reason,
|
|
235
|
+
cancel() {
|
|
236
|
+
isCanceled = true;
|
|
237
|
+
},
|
|
238
|
+
get isCanceled() {
|
|
239
|
+
return isCanceled;
|
|
240
|
+
},
|
|
241
|
+
};
|
|
229
242
|
emit('update:open', value, details);
|
|
243
|
+
if (isCanceled) {
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
uncontrolledOpen.value = value;
|
|
247
|
+
return true;
|
|
230
248
|
}
|
|
231
249
|
|
|
232
250
|
function handleOpenToggle() {
|
|
@@ -11,7 +11,7 @@ export interface DrawerSwipeAreaProps extends PrimitiveProps {
|
|
|
11
11
|
</script>
|
|
12
12
|
|
|
13
13
|
<script setup lang="ts">
|
|
14
|
-
import { computed } from 'vue';
|
|
14
|
+
import { computed, nextTick } from 'vue';
|
|
15
15
|
import { Primitive } from '@/Primitive';
|
|
16
16
|
import { useForwardExpose } from '@/shared';
|
|
17
17
|
import { useSwipeDismiss } from './composables/useSwipeDismiss';
|
|
@@ -45,7 +45,7 @@ const enabled = computed(() => !props.disabled && !rootContext.open.value);
|
|
|
45
45
|
// the initial value only and ignore prop/state updates.
|
|
46
46
|
const directions = computed<Array<SwipeDirection>>(() => [openDirection.value]);
|
|
47
47
|
|
|
48
|
-
useSwipeDismiss({
|
|
48
|
+
const { restore: restoreSwipe } = useSwipeDismiss({
|
|
49
49
|
enabled,
|
|
50
50
|
elementRef: currentElement,
|
|
51
51
|
directions,
|
|
@@ -54,7 +54,14 @@ useSwipeDismiss({
|
|
|
54
54
|
y: DRAWER_CSS_VARS.swipeMovementY,
|
|
55
55
|
},
|
|
56
56
|
onDismiss() {
|
|
57
|
-
rootContext.onOpenChange(true, 'swipe')
|
|
57
|
+
if (!rootContext.onOpenChange(true, 'swipe')) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
nextTick(() => {
|
|
61
|
+
if (!rootContext.open.value) {
|
|
62
|
+
restoreSwipe();
|
|
63
|
+
}
|
|
64
|
+
});
|
|
58
65
|
},
|
|
59
66
|
onSwipingChange(swiping) {
|
|
60
67
|
rootContext.onNestedSwipingChange(swiping);
|
|
@@ -17,8 +17,15 @@ export interface UseSwipeDismissOptions {
|
|
|
17
17
|
movementCssVars: { x: string; y: string };
|
|
18
18
|
swipeThreshold?: number | ((opts: { element: HTMLElement; direction: SwipeDirection }) => number);
|
|
19
19
|
ignoreScrollableAncestors?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* When `false`, touch swipes may start on the interactive elements
|
|
22
|
+
* (buttons, links, labels, fields) that mouse and pen swipes skip.
|
|
23
|
+
* @default true
|
|
24
|
+
*/
|
|
25
|
+
ignoreSelectorWhenTouch?: boolean;
|
|
20
26
|
canStart?: () => boolean;
|
|
21
|
-
|
|
27
|
+
/** Return `false` when the dismissal was rejected, so the element settles back. */
|
|
28
|
+
onDismiss?: () => boolean | void;
|
|
22
29
|
onProgress?: (progress: number, details?: SwipeProgressDetails) => void;
|
|
23
30
|
onCancel?: () => void;
|
|
24
31
|
onSwipeStart?: () => void;
|
|
@@ -42,6 +49,13 @@ const AXIS_LOCK_BIAS = 2;
|
|
|
42
49
|
const MIN_RELEASE_VELOCITY_DURATION_MS = 16;
|
|
43
50
|
const MAX_RELEASE_VELOCITY_AGE_MS = 80;
|
|
44
51
|
const DEFAULT_IGNORE_SELECTOR = 'button,a,input,select,textarea,label,[role="button"]';
|
|
52
|
+
// Opts an element out of swipe dismissal for every input type. Ported from
|
|
53
|
+
// Base UI's `data-base-ui-swipe-ignore`.
|
|
54
|
+
const SWIPE_IGNORE_SELECTOR = '[data-akar-swipe-ignore]';
|
|
55
|
+
|
|
56
|
+
function isRangeInput(target: EventTarget): boolean {
|
|
57
|
+
return (target as Element).tagName === 'INPUT' && (target as HTMLInputElement).type === 'range';
|
|
58
|
+
}
|
|
45
59
|
|
|
46
60
|
function findScrollableAncestor(
|
|
47
61
|
el: Element | null,
|
|
@@ -121,6 +135,7 @@ export function useSwipeDismiss(options: UseSwipeDismissOptions) {
|
|
|
121
135
|
movementCssVars,
|
|
122
136
|
swipeThreshold: swipeThresholdProp,
|
|
123
137
|
canStart,
|
|
138
|
+
ignoreSelectorWhenTouch = true,
|
|
124
139
|
onDismiss,
|
|
125
140
|
onProgress,
|
|
126
141
|
onCancel,
|
|
@@ -449,6 +464,7 @@ export function useSwipeDismiss(options: UseSwipeDismissOptions) {
|
|
|
449
464
|
// would otherwise set a stray `data-swipe-dismissed` on a drawer that
|
|
450
465
|
// actually snapped to a point, or clear CSS vars onRelease already wrote.
|
|
451
466
|
const releaseHandled = onRelease?.(velocity) === true;
|
|
467
|
+
let dismissed = false;
|
|
452
468
|
|
|
453
469
|
if (!releaseHandled) {
|
|
454
470
|
const velInDirection = getDisplacement(
|
|
@@ -459,13 +475,13 @@ export function useSwipeDismiss(options: UseSwipeDismissOptions) {
|
|
|
459
475
|
const shouldDismiss = !cancelledSwipe
|
|
460
476
|
&& (displacement >= threshold || velInDirection > 0.3);
|
|
461
477
|
|
|
462
|
-
if (shouldDismiss) {
|
|
478
|
+
if (shouldDismiss && onDismiss?.() !== false) {
|
|
463
479
|
// BaseUI parity: on dismiss, keep the drag transform in place so the
|
|
464
480
|
// close animation runs smoothly from the dragged position. Clearing the
|
|
465
481
|
// CSS vars here would cause a one-frame snap-back to resting before the
|
|
466
482
|
// closing transition begins (visible as a flicker).
|
|
467
483
|
el.setAttribute('data-swipe-dismissed', '');
|
|
468
|
-
|
|
484
|
+
dismissed = true;
|
|
469
485
|
} else {
|
|
470
486
|
// On cancel, reset the drag transform so the drawer animates back to rest.
|
|
471
487
|
clearCssVars(el);
|
|
@@ -473,6 +489,12 @@ export function useSwipeDismiss(options: UseSwipeDismissOptions) {
|
|
|
473
489
|
}
|
|
474
490
|
}
|
|
475
491
|
|
|
492
|
+
// BaseUI parity (`settleInPlace`): a drawer that stays open settles back to
|
|
493
|
+
// rest, so drop the published progress along with the drag transform.
|
|
494
|
+
if (!dismissed) {
|
|
495
|
+
onProgress?.(0);
|
|
496
|
+
}
|
|
497
|
+
|
|
476
498
|
reset();
|
|
477
499
|
}
|
|
478
500
|
|
|
@@ -493,7 +515,7 @@ export function useSwipeDismiss(options: UseSwipeDismissOptions) {
|
|
|
493
515
|
}
|
|
494
516
|
|
|
495
517
|
const target = e.target as HTMLElement;
|
|
496
|
-
if (target?.closest(DEFAULT_IGNORE_SELECTOR)) {
|
|
518
|
+
if (target?.closest(`${DEFAULT_IGNORE_SELECTOR},${SWIPE_IGNORE_SELECTOR}`)) {
|
|
497
519
|
return;
|
|
498
520
|
}
|
|
499
521
|
|
|
@@ -572,7 +594,15 @@ export function useSwipeDismiss(options: UseSwipeDismissOptions) {
|
|
|
572
594
|
}
|
|
573
595
|
|
|
574
596
|
const target = e.target as HTMLElement;
|
|
575
|
-
if (target?.closest(
|
|
597
|
+
if (target?.closest(SWIPE_IGNORE_SELECTOR)) {
|
|
598
|
+
return;
|
|
599
|
+
}
|
|
600
|
+
// A tap that stays under the drag threshold still clicks, so touch can
|
|
601
|
+
// start a swipe on buttons and links; a range input's thumb drag cannot
|
|
602
|
+
// be told apart from a swipe, so it keeps the gesture.
|
|
603
|
+
if (ignoreSelectorWhenTouch
|
|
604
|
+
? target?.closest(DEFAULT_IGNORE_SELECTOR)
|
|
605
|
+
: e.composedPath().some(isRangeInput)) {
|
|
576
606
|
return;
|
|
577
607
|
}
|
|
578
608
|
|
|
@@ -734,9 +764,25 @@ export function useSwipeDismiss(options: UseSwipeDismissOptions) {
|
|
|
734
764
|
reset();
|
|
735
765
|
});
|
|
736
766
|
|
|
767
|
+
/**
|
|
768
|
+
* Undoes a dismissal that did not take effect, e.g. a controlled `open` the
|
|
769
|
+
* parent never updated. The element animates back to rest.
|
|
770
|
+
*/
|
|
771
|
+
function restore() {
|
|
772
|
+
const el = elementRef.value;
|
|
773
|
+
if (!el?.hasAttribute('data-swipe-dismissed')) {
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
el.removeAttribute('data-swipe-dismissed');
|
|
777
|
+
clearCssVars(el);
|
|
778
|
+
onProgress?.(0);
|
|
779
|
+
onCancel?.();
|
|
780
|
+
}
|
|
781
|
+
|
|
737
782
|
return {
|
|
738
783
|
isSwiping,
|
|
739
784
|
swipeDirection,
|
|
740
785
|
dragOffset,
|
|
786
|
+
restore,
|
|
741
787
|
};
|
|
742
788
|
}
|
|
@@ -47,6 +47,7 @@ rootContext.triggerId ||= useId(undefined, 'akar-dropdown-menu-trigger');
|
|
|
47
47
|
:data-state="rootContext.open.value ? 'open' : 'closed'"
|
|
48
48
|
@click="
|
|
49
49
|
async (event: MouseEvent) => {
|
|
50
|
+
if (event.defaultPrevented) return;
|
|
50
51
|
// only call handler if it's the left button (mousedown gets triggered by all mouse buttons)
|
|
51
52
|
// but not when the control key is pressed (avoiding MacOS right click)
|
|
52
53
|
if (!disabled && event.button === 0 && event.ctrlKey === false) {
|
|
@@ -60,7 +61,7 @@ rootContext.triggerId ||= useId(undefined, 'akar-dropdown-menu-trigger');
|
|
|
60
61
|
"
|
|
61
62
|
@keydown.enter.space.arrow-down="
|
|
62
63
|
(event: KeyboardEvent) => {
|
|
63
|
-
if (disabled) return;
|
|
64
|
+
if (disabled || event.defaultPrevented) return;
|
|
64
65
|
if (['Enter', ' '].includes(event.key)) rootContext.onOpenToggle();
|
|
65
66
|
if (event.key === 'ArrowDown') rootContext.onOpenChange(true);
|
|
66
67
|
// prevent keydown from scrolling window / first focused item to execute
|
|
@@ -15,6 +15,7 @@ type ListboxRootContext<T> = {
|
|
|
15
15
|
dir: Ref<Direction>;
|
|
16
16
|
disabled: Ref<boolean>;
|
|
17
17
|
highlightOnHover: Ref<boolean>;
|
|
18
|
+
loop: Ref<boolean>;
|
|
18
19
|
highlightedElement: Ref<HTMLElement | null>;
|
|
19
20
|
isVirtual: Ref<boolean>;
|
|
20
21
|
virtualFocusHook: EventHook<{ event?: Event; scroll: boolean }>;
|
|
@@ -69,6 +70,8 @@ export interface ListboxRootProps<T = AcceptableValue> extends PrimitiveProps, F
|
|
|
69
70
|
selectionBehavior?: 'toggle' | 'replace';
|
|
70
71
|
/** When `true`, hover over item will trigger highlight */
|
|
71
72
|
highlightOnHover?: boolean;
|
|
73
|
+
/** When `true`, keyboard navigation will loop from last item to first, and vice versa. */
|
|
74
|
+
loop?: boolean;
|
|
72
75
|
/** Use this to compare objects by a particular field, or pass your own comparison function for complete control over how objects are compared. */
|
|
73
76
|
by?: string | ((a: T, b: T) => boolean);
|
|
74
77
|
}
|
|
@@ -108,7 +111,7 @@ defineSlots<{
|
|
|
108
111
|
}) => any;
|
|
109
112
|
}>();
|
|
110
113
|
|
|
111
|
-
const { multiple, highlightOnHover, orientation, disabled, selectionBehavior, dir: propDir } = toRefs(props);
|
|
114
|
+
const { multiple, highlightOnHover, loop, orientation, disabled, selectionBehavior, dir: propDir } = toRefs(props);
|
|
112
115
|
const { getItems, getItem } = useCollection<{ value: T }>({ isProvider: true });
|
|
113
116
|
const { handleTypeaheadSearch } = useTypeahead();
|
|
114
117
|
const { primitiveElement, currentElement } = usePrimitiveElement();
|
|
@@ -310,6 +313,20 @@ function onEnter(event: Event) {
|
|
|
310
313
|
}
|
|
311
314
|
}
|
|
312
315
|
|
|
316
|
+
function isAtVirtualBoundary(intent: 'prev' | 'next') {
|
|
317
|
+
// A virtualized list only renders a window of items. Only wrap when that
|
|
318
|
+
// window reaches the end of the full options list; any rendered items past
|
|
319
|
+
// the highlighted one are disabled.
|
|
320
|
+
const rendered = getItems(true).map((i) => i.ref);
|
|
321
|
+
const edge = intent === 'next' ? rendered.at(-1) : rendered[0];
|
|
322
|
+
if (!edge) {
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
const position = Number(edge.getAttribute('aria-posinset'));
|
|
326
|
+
const size = Number(edge.getAttribute('aria-setsize'));
|
|
327
|
+
return intent === 'next' ? position === size : position === 1;
|
|
328
|
+
}
|
|
329
|
+
|
|
313
330
|
function onKeydownNavigation(event: KeyboardEvent) {
|
|
314
331
|
const intent = getFocusIntent(event, orientation.value, dir.value);
|
|
315
332
|
if (!intent) {
|
|
@@ -326,7 +343,17 @@ function onKeydownNavigation(event: KeyboardEvent) {
|
|
|
326
343
|
}
|
|
327
344
|
|
|
328
345
|
const currentIndex = collection.indexOf(highlightedElement.value);
|
|
329
|
-
|
|
346
|
+
const shouldLoop = loop.value && currentIndex === collection.length - 1;
|
|
347
|
+
if (shouldLoop && isVirtual.value) {
|
|
348
|
+
if (isAtVirtualBoundary(intent)) {
|
|
349
|
+
// Let the virtualizer scroll to and highlight the opposite end.
|
|
350
|
+
const key = intent === 'next' ? KEY_CODES.HOME : KEY_CODES.END;
|
|
351
|
+
return virtualKeydownHook.trigger(new KeyboardEvent('keydown', { key, shiftKey: event.shiftKey }));
|
|
352
|
+
}
|
|
353
|
+
collection = [];
|
|
354
|
+
} else {
|
|
355
|
+
collection = shouldLoop ? collection.slice(0, 1) : collection.slice(currentIndex + 1);
|
|
356
|
+
}
|
|
330
357
|
}
|
|
331
358
|
handleMultipleReplace(event, collection[0]);
|
|
332
359
|
}
|
|
@@ -437,6 +464,7 @@ provideListboxRootContext({
|
|
|
437
464
|
dir,
|
|
438
465
|
disabled,
|
|
439
466
|
highlightOnHover,
|
|
467
|
+
loop,
|
|
440
468
|
highlightedElement,
|
|
441
469
|
isVirtual,
|
|
442
470
|
virtualFocusHook,
|
|
@@ -61,6 +61,7 @@ onMounted(() => {
|
|
|
61
61
|
:disabled="disabled"
|
|
62
62
|
:data-value="menuContext.value"
|
|
63
63
|
@pointerdown="(event: PointerEvent) => {
|
|
64
|
+
if (event.defaultPrevented) return;
|
|
64
65
|
// only call handler if it's the left button (mousedown gets triggered by all mouse buttons)
|
|
65
66
|
// but not when the control key is pressed (avoiding MacOS right click)
|
|
66
67
|
if (!disabled && event.button === 0 && event.ctrlKey === false) {
|
|
@@ -78,7 +79,7 @@ onMounted(() => {
|
|
|
78
79
|
}
|
|
79
80
|
}"
|
|
80
81
|
@keydown.enter.space.arrow-down="(event: KeyboardEvent) => {
|
|
81
|
-
if (disabled) return;
|
|
82
|
+
if (disabled || event.defaultPrevented) return;
|
|
82
83
|
if (['Enter', ' '].includes(event.key)) rootContext.onMenuToggle(menuContext.value);
|
|
83
84
|
if (event.key === 'ArrowDown') rootContext.onMenuOpen(menuContext.value);
|
|
84
85
|
// prevent keydown from scrolling window / first focused item to execute
|
|
@@ -58,7 +58,7 @@ function handlePointerEnter() {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
function handlePointerMove(ev: PointerEvent) {
|
|
61
|
-
if (menuContext.disableHoverTrigger.value) {
|
|
61
|
+
if (ev.defaultPrevented || menuContext.disableHoverTrigger.value) {
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -92,6 +92,9 @@ function handlePointerLeave(ev: PointerEvent) {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
function handleClick(event: MouseEvent | PointerEvent) {
|
|
95
|
+
if (event.defaultPrevented) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
95
98
|
if (
|
|
96
99
|
(!('pointerType' in event) || event.pointerType === 'mouse')
|
|
97
100
|
&& menuContext.disableClickTrigger.value
|
|
@@ -114,6 +117,9 @@ function handleClick(event: MouseEvent | PointerEvent) {
|
|
|
114
117
|
}
|
|
115
118
|
|
|
116
119
|
function handleKeydown(ev: KeyboardEvent) {
|
|
120
|
+
if (ev.defaultPrevented) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
117
123
|
const verticalEntryKey = menuContext.dir.value === 'rtl' ? 'ArrowLeft' : 'ArrowRight';
|
|
118
124
|
const entryKey = { horizontal: 'ArrowDown', vertical: verticalEntryKey }[
|
|
119
125
|
menuContext.orientation
|
|
@@ -175,7 +181,6 @@ function handleVisuallyHiddenFocus(ev: FocusEvent) {
|
|
|
175
181
|
<template v-if="open">
|
|
176
182
|
<VisuallyHidden
|
|
177
183
|
:ref="setFocusProxyRef"
|
|
178
|
-
aria-hidden="true"
|
|
179
184
|
:tabindex="0"
|
|
180
185
|
@focus="handleVisuallyHiddenFocus"
|
|
181
186
|
/>
|
|
@@ -17,6 +17,8 @@ export interface NumberFieldRootProps extends PrimitiveProps, FormFieldProps {
|
|
|
17
17
|
step?: number;
|
|
18
18
|
/** When `false`, prevents the value from snapping to the nearest increment of the step value */
|
|
19
19
|
stepSnapping?: boolean;
|
|
20
|
+
/** When `true`, a typed value is kept as-is even if invalid (out of `min`/`max` range or off the step grid); step interactions still clamp and snap. The field does not flag the value as invalid (no `aria-invalid`/`data-invalid`), so validating and surfacing the error is up to the consumer. */
|
|
21
|
+
allowInvalid?: boolean;
|
|
20
22
|
/** When `true`, the input will be focused when the value changes. */
|
|
21
23
|
focusOnChange?: boolean;
|
|
22
24
|
/** Formatting options for the value displayed in the number field. This also affects what characters are allowed to be typed by the user. */
|
|
@@ -35,8 +37,11 @@ export interface NumberFieldRootProps extends PrimitiveProps, FormFieldProps {
|
|
|
35
37
|
id?: string;
|
|
36
38
|
}
|
|
37
39
|
|
|
40
|
+
// `undefined` is emitted when the input is cleared. Documented here rather than on the member
|
|
41
|
+
// itself: the docs generator keys event descriptions by name globally, so a comment on
|
|
42
|
+
// `update:modelValue` leaks into every other component that emits it.
|
|
38
43
|
export type NumberFieldRootEmits = {
|
|
39
|
-
'update:modelValue': [val: number];
|
|
44
|
+
'update:modelValue': [val: number | undefined];
|
|
40
45
|
};
|
|
41
46
|
|
|
42
47
|
interface NumberFieldRootContext {
|
|
@@ -82,7 +87,7 @@ const props = withDefaults(defineProps<NumberFieldRootProps>(), {
|
|
|
82
87
|
focusOnChange: true,
|
|
83
88
|
});
|
|
84
89
|
const emits = defineEmits<NumberFieldRootEmits>();
|
|
85
|
-
const { disabled, readonly, disableWheelChange, invertWheelChange, min, max, step, stepSnapping, formatOptions, id, locale: propLocale } = toRefs(props);
|
|
90
|
+
const { disabled, readonly, disableWheelChange, invertWheelChange, min, max, step, stepSnapping, allowInvalid, formatOptions, id, locale: propLocale } = toRefs(props);
|
|
86
91
|
|
|
87
92
|
const modelValue = useVModel(props, 'modelValue', emits, {
|
|
88
93
|
defaultValue: props.defaultValue,
|
|
@@ -156,7 +161,13 @@ function handleChangingValue(type: 'increase' | 'decrease', multiplier = 1) {
|
|
|
156
161
|
return;
|
|
157
162
|
}
|
|
158
163
|
|
|
159
|
-
|
|
164
|
+
const nextValue = getNextValue(type, currentInputValue, multiplier);
|
|
165
|
+
// An out-of-range value (e.g. typed with `allowInvalid`) would be clamped against the requested
|
|
166
|
+
// direction — ArrowUp above `max` would lower it. Do nothing instead, like HTML stepUp/stepDown.
|
|
167
|
+
if (type === 'increase' ? nextValue < currentInputValue : nextValue > currentInputValue) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
modelValue.value = nextValue;
|
|
160
171
|
}
|
|
161
172
|
|
|
162
173
|
function handleIncrease(multiplier = 1) {
|
|
@@ -193,6 +204,12 @@ const textValueFormatter = useNumberFormatter(locale, formatOptions);
|
|
|
193
204
|
const textValue = computed(() => isNullish(modelValue.value) || isNaN(modelValue.value) ? '' : textValueFormatter.format(modelValue.value));
|
|
194
205
|
|
|
195
206
|
function validate(val: string) {
|
|
207
|
+
// `allowInvalid` lets out-of-range values be typed, so the bounds are skipped here — they
|
|
208
|
+
// would otherwise reject a leading minus sign whenever `min >= 0`. The value still has to
|
|
209
|
+
// parse as a number, so non-numeric input stays rejected.
|
|
210
|
+
if (allowInvalid.value) {
|
|
211
|
+
return numberParser.isValidPartialNumber(val);
|
|
212
|
+
}
|
|
196
213
|
return numberParser.isValidPartialNumber(val, min.value, max.value);
|
|
197
214
|
}
|
|
198
215
|
|
|
@@ -217,7 +234,14 @@ function clampInputValue(val: number) {
|
|
|
217
234
|
|
|
218
235
|
function applyInputValue(val: string) {
|
|
219
236
|
const parsedValue = numberParser.parse(val);
|
|
220
|
-
|
|
237
|
+
if (isNaN(parsedValue)) {
|
|
238
|
+
modelValue.value = undefined;
|
|
239
|
+
} else if (allowInvalid.value) {
|
|
240
|
+
// Keep the typed value as-is, only normalize formatting precision
|
|
241
|
+
modelValue.value = numberParser.parse(numberFormatter.format(parsedValue));
|
|
242
|
+
} else {
|
|
243
|
+
modelValue.value = clampInputValue(parsedValue);
|
|
244
|
+
}
|
|
221
245
|
// Set to empty state if input value is empty
|
|
222
246
|
if (!val.length) {
|
|
223
247
|
return setInputValue(val);
|
|
@@ -16,10 +16,11 @@ export interface RovingFocusItemProps extends PrimitiveProps {
|
|
|
16
16
|
</script>
|
|
17
17
|
|
|
18
18
|
<script setup lang="ts">
|
|
19
|
+
import { useEventListener } from '@vueuse/core';
|
|
19
20
|
import { computed, nextTick, onMounted, onUnmounted, watch } from 'vue';
|
|
20
21
|
import { useCollection } from '@/Collection';
|
|
21
22
|
import { Primitive } from '@/Primitive';
|
|
22
|
-
import { useId } from '@/shared';
|
|
23
|
+
import { useForwardExpose, useId } from '@/shared';
|
|
23
24
|
import { injectRovingFocusGroupContext } from './RovingFocusGroup.vue';
|
|
24
25
|
import { focusFirst, getFocusIntent, wrapArray } from './utils';
|
|
25
26
|
|
|
@@ -64,6 +65,10 @@ watch(
|
|
|
64
65
|
);
|
|
65
66
|
|
|
66
67
|
function handleKeydown(event: KeyboardEvent) {
|
|
68
|
+
if (event.defaultPrevented) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
67
72
|
if (event.key === 'Tab' && event.shiftKey) {
|
|
68
73
|
context.onItemShiftTab();
|
|
69
74
|
return;
|
|
@@ -104,11 +109,18 @@ function handleKeydown(event: KeyboardEvent) {
|
|
|
104
109
|
nextTick(() => focusFirst(candidateNodes));
|
|
105
110
|
}
|
|
106
111
|
}
|
|
112
|
+
// Bound natively after mount rather than via `@keydown` so it runs after the
|
|
113
|
+
// item's own handlers. An `asChild` item (e.g. a `DropdownMenuTrigger` inside a
|
|
114
|
+
// `ToolbarButton`) or a consumer can then claim a key with `preventDefault()`,
|
|
115
|
+
// matching Radix, where the wrapped child's handler runs first.
|
|
116
|
+
const { forwardRef, currentElement } = useForwardExpose();
|
|
117
|
+
useEventListener(currentElement, 'keydown', handleKeydown);
|
|
107
118
|
</script>
|
|
108
119
|
|
|
109
120
|
<template>
|
|
110
121
|
<CollectionItem>
|
|
111
122
|
<Primitive
|
|
123
|
+
:ref="forwardRef"
|
|
112
124
|
:tabindex="isCurrentTabStop ? 0 : -1"
|
|
113
125
|
:data-orientation="context.orientation.value"
|
|
114
126
|
:data-active="active ? '' : undefined"
|
|
@@ -125,7 +137,6 @@ function handleKeydown(event: KeyboardEvent) {
|
|
|
125
137
|
}
|
|
126
138
|
"
|
|
127
139
|
@focus="context.onItemFocus(id)"
|
|
128
|
-
@keydown="handleKeydown"
|
|
129
140
|
>
|
|
130
141
|
<slot />
|
|
131
142
|
</Primitive>
|