akar 2.0.20 → 2.0.22
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 +20 -4
- package/dist/NumberField/NumberFieldRoot.cjs.map +1 -1
- package/dist/NumberField/NumberFieldRoot.js +20 -4
- 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 +85 -0
- package/dist/Toast/useToastStore.cjs.map +1 -0
- package/dist/Toast/useToastStore.js +79 -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 +33 -21
- package/dist/index2.d.cts.map +1 -1
- package/dist/index2.d.ts +21 -9
- package/dist/index2.d.ts.map +1 -1
- package/dist/index3.d.cts +1685 -1437
- package/dist/index3.d.cts.map +1 -1
- package/dist/index3.d.ts +1681 -1433
- 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.d.ts.map +1 -1
- 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 +38 -5
- 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 +27 -14
- package/src/Toast/ToastArrow.vue +37 -0
- package/src/Toast/ToastDescription.vue +8 -2
- 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 +90 -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
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
useTypeahead,
|
|
16
16
|
} from '@/shared';
|
|
17
17
|
import { useBodyScrollLock } from '@/shared/useBodyScrollLock';
|
|
18
|
+
import { wrapArray } from '@/shared/useTypeahead';
|
|
18
19
|
import { valueComparator } from './utils';
|
|
19
20
|
|
|
20
21
|
export interface SelectContentContext {
|
|
@@ -74,6 +75,11 @@ export interface SelectContentImplProps extends PopperContentProps, DismissableL
|
|
|
74
75
|
* @defaultValue true
|
|
75
76
|
*/
|
|
76
77
|
bodyLock?: boolean;
|
|
78
|
+
/**
|
|
79
|
+
* When `true`, keyboard navigation will loop from last item to first, and vice versa.
|
|
80
|
+
* @defaultValue false
|
|
81
|
+
*/
|
|
82
|
+
loop?: boolean;
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
export const [injectSelectContentContext, provideSelectContentContext]
|
|
@@ -81,7 +87,7 @@ export const [injectSelectContentContext, provideSelectContentContext]
|
|
|
81
87
|
</script>
|
|
82
88
|
|
|
83
89
|
<script setup lang="ts">
|
|
84
|
-
import { unrefElement } from '@vueuse/core';
|
|
90
|
+
import { reactiveOmit, unrefElement } from '@vueuse/core';
|
|
85
91
|
import {
|
|
86
92
|
computed,
|
|
87
93
|
ref,
|
|
@@ -217,16 +223,20 @@ function handleKeyDown(event: KeyboardEvent) {
|
|
|
217
223
|
if (['ArrowUp', 'ArrowDown'].includes(event.key)) {
|
|
218
224
|
const currentElement = event.target as HTMLElement;
|
|
219
225
|
const currentIndex = candidateNodes.indexOf(currentElement);
|
|
220
|
-
candidateNodes =
|
|
226
|
+
candidateNodes = props.loop
|
|
227
|
+
? wrapArray(candidateNodes, currentIndex + 1)
|
|
228
|
+
: candidateNodes.slice(currentIndex + 1);
|
|
221
229
|
}
|
|
222
230
|
setTimeout(() => focusFirst(candidateNodes));
|
|
223
231
|
event.preventDefault();
|
|
224
232
|
}
|
|
225
233
|
}
|
|
226
234
|
|
|
235
|
+
// `loop` drives keyboard navigation here and is not a positioning prop
|
|
236
|
+
const positionProps = reactiveOmit(props, 'loop');
|
|
227
237
|
const pickedProps = computed(() => {
|
|
228
238
|
if (props.position === 'popper') {
|
|
229
|
-
return
|
|
239
|
+
return positionProps;
|
|
230
240
|
} else {
|
|
231
241
|
return {};
|
|
232
242
|
}
|
|
@@ -102,7 +102,14 @@ function isPlainLeftClick(event: MouseEvent) {
|
|
|
102
102
|
// `click` workaround below does not re-focus the trigger after opening.
|
|
103
103
|
let openedFromPointerDown = false;
|
|
104
104
|
|
|
105
|
+
// Consumer listeners run before these handlers (attrs are merged first), so a
|
|
106
|
+
// consumer can opt out of the default behavior with `event.preventDefault()`,
|
|
107
|
+
// matching Radix's `composeEventHandlers`.
|
|
105
108
|
function onTriggerPointerDown(event: PointerEvent) {
|
|
109
|
+
if (event.defaultPrevented) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
106
113
|
// Prevent opening on touch down.
|
|
107
114
|
if (event.pointerType === 'touch') {
|
|
108
115
|
return event.preventDefault();
|
|
@@ -124,6 +131,10 @@ function onTriggerPointerDown(event: PointerEvent) {
|
|
|
124
131
|
}
|
|
125
132
|
|
|
126
133
|
function onTriggerMouseDown(event: MouseEvent) {
|
|
134
|
+
if (event.defaultPrevented) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
127
138
|
// Prevent trigger from stealing focus from the active item after opening.
|
|
128
139
|
// We avoid calling `preventDefault` in `pointerdown` because that suppresses
|
|
129
140
|
// compatibility mouse events (`mousedown`, `mouseup`, `click`).
|
|
@@ -133,6 +144,11 @@ function onTriggerMouseDown(event: MouseEvent) {
|
|
|
133
144
|
}
|
|
134
145
|
|
|
135
146
|
function onTriggerClick(event: MouseEvent) {
|
|
147
|
+
if (event.defaultPrevented) {
|
|
148
|
+
openedFromPointerDown = false;
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
|
|
136
152
|
// Safari: label-associated clicks may not run `pointerdown` on the trigger.
|
|
137
153
|
// Direct mouse clicks open in `pointerdown` and must not re-focus the trigger
|
|
138
154
|
// here — `mousedown` `preventDefault` does not suppress `click`.
|
|
@@ -142,6 +158,40 @@ function onTriggerClick(event: MouseEvent) {
|
|
|
142
158
|
|
|
143
159
|
openedFromPointerDown = false;
|
|
144
160
|
}
|
|
161
|
+
|
|
162
|
+
function onTriggerPointerUp(event: PointerEvent) {
|
|
163
|
+
if (event.defaultPrevented) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
event.preventDefault();
|
|
167
|
+
|
|
168
|
+
// Only open on pointer up when using touch devices
|
|
169
|
+
if (event.pointerType === 'touch') {
|
|
170
|
+
handlePointerOpen(event);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function onTriggerKeyDown(event: KeyboardEvent) {
|
|
175
|
+
if (event.defaultPrevented) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const isTypingAhead = search.value !== '';
|
|
180
|
+
const isModifierKey = event.ctrlKey || event.altKey || event.metaKey;
|
|
181
|
+
// Only printable characters extend the search; otherwise keys like `Shift`
|
|
182
|
+
// or `ArrowLeft` would be appended and swallow the next `Space`.
|
|
183
|
+
if (!isModifierKey && event.key.length === 1) {
|
|
184
|
+
handleTypeaheadSearch(event.key, getItems());
|
|
185
|
+
}
|
|
186
|
+
if (isTypingAhead && event.key === ' ') {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (OPEN_KEYS.includes(event.key)) {
|
|
191
|
+
handleOpen();
|
|
192
|
+
event.preventDefault();
|
|
193
|
+
}
|
|
194
|
+
}
|
|
145
195
|
</script>
|
|
146
196
|
|
|
147
197
|
<template>
|
|
@@ -170,27 +220,8 @@ function onTriggerClick(event: MouseEvent) {
|
|
|
170
220
|
@mousedown="onTriggerMouseDown"
|
|
171
221
|
@focus="handleFieldFocus"
|
|
172
222
|
@blur="handleFieldBlur"
|
|
173
|
-
@pointerup
|
|
174
|
-
|
|
175
|
-
// Only open on pointer up when using touch devices
|
|
176
|
-
if (event.pointerType === 'touch')
|
|
177
|
-
handlePointerOpen(event)
|
|
178
|
-
}
|
|
179
|
-
"
|
|
180
|
-
@keydown="
|
|
181
|
-
(event: KeyboardEvent) => {
|
|
182
|
-
const isTypingAhead = search !== '';
|
|
183
|
-
const isModifierKey = event.ctrlKey || event.altKey || event.metaKey;
|
|
184
|
-
if (!isModifierKey && event.key.length === 1)
|
|
185
|
-
if (isTypingAhead && event.key === ' ') return;
|
|
186
|
-
|
|
187
|
-
handleTypeaheadSearch(event.key, getItems());
|
|
188
|
-
if (OPEN_KEYS.includes(event.key)) {
|
|
189
|
-
handleOpen();
|
|
190
|
-
event.preventDefault();
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
"
|
|
223
|
+
@pointerup="onTriggerPointerUp"
|
|
224
|
+
@keydown="onTriggerKeyDown"
|
|
194
225
|
>
|
|
195
226
|
<slot />
|
|
196
227
|
</Primitive>
|
package/src/Tabs/TabsTrigger.vue
CHANGED
|
@@ -52,6 +52,7 @@ const isSelected = computed(() => props.value === rootContext.modelValue.value);
|
|
|
52
52
|
:data-disabled="disabled ? '' : undefined"
|
|
53
53
|
:data-orientation="rootContext.orientation.value"
|
|
54
54
|
@mousedown.left="(event: MouseEvent) => {
|
|
55
|
+
if (event.defaultPrevented) return;
|
|
55
56
|
// only call handler if it's the left button (mousedown gets triggered by all mouse buttons)
|
|
56
57
|
// but not when the control key is pressed (avoiding MacOS right click)
|
|
57
58
|
if (!disabled && event.ctrlKey === false) {
|
|
@@ -62,7 +63,9 @@ const isSelected = computed(() => props.value === rootContext.modelValue.value);
|
|
|
62
63
|
event.preventDefault();
|
|
63
64
|
}
|
|
64
65
|
}"
|
|
65
|
-
@keydown.enter.space="
|
|
66
|
+
@keydown.enter.space="(event: KeyboardEvent) => {
|
|
67
|
+
if (!event.defaultPrevented) rootContext.changeModelValue(value);
|
|
68
|
+
}"
|
|
66
69
|
@focus="() => {
|
|
67
70
|
// handle 'automatic' activation if necessary
|
|
68
71
|
// ie. activate tab following focus
|
|
@@ -5,10 +5,12 @@ 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
|
*/
|
|
11
|
-
altText
|
|
13
|
+
altText?: string;
|
|
12
14
|
/**
|
|
13
15
|
* Whether the action should close the toast when clicked.
|
|
14
16
|
*
|
|
@@ -19,30 +21,41 @@ export interface ToastActionProps extends ToastCloseProps {
|
|
|
19
21
|
</script>
|
|
20
22
|
|
|
21
23
|
<script setup lang="ts">
|
|
24
|
+
import { computed, useSlots } from 'vue';
|
|
22
25
|
import { Primitive } from '@/Primitive';
|
|
23
26
|
import { useForwardExpose } from '@/shared';
|
|
24
27
|
import ToastAnnounceExclude from './ToastAnnounceExclude.vue';
|
|
25
28
|
import { injectToastRootContext } from './ToastRootImpl.vue';
|
|
26
29
|
|
|
27
|
-
const props = withDefaults(
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
);
|
|
30
|
+
const props = withDefaults(defineProps<ToastActionProps>(), {
|
|
31
|
+
as: 'button',
|
|
32
|
+
closeOnClick: true,
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const rootContext = injectToastRootContext();
|
|
36
|
+
const { forwardRef } = useForwardExpose();
|
|
37
|
+
const slots = useSlots();
|
|
38
|
+
|
|
39
|
+
const actionProps = computed(() => rootContext.toast.value?.actionProps);
|
|
40
|
+
// A managed toast without `actionProps` renders no action, unless slot content is given.
|
|
41
|
+
const isRendered = computed(() => !!slots.default || !rootContext.toast.value || !!actionProps.value);
|
|
42
|
+
const altText = computed(() => props.altText ?? actionProps.value?.altText);
|
|
34
43
|
|
|
35
|
-
if (!
|
|
44
|
+
if (isRendered.value && !altText.value) {
|
|
36
45
|
throw new Error('Missing prop `altText` expected on `ToastAction`');
|
|
37
46
|
}
|
|
38
47
|
|
|
39
|
-
|
|
40
|
-
|
|
48
|
+
function handleClick(event: MouseEvent) {
|
|
49
|
+
actionProps.value?.onClick?.(event);
|
|
50
|
+
if (actionProps.value?.closeOnClick ?? props.closeOnClick) {
|
|
51
|
+
rootContext.onClose();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
41
54
|
</script>
|
|
42
55
|
|
|
43
56
|
<template>
|
|
44
57
|
<ToastAnnounceExclude
|
|
45
|
-
v-if="altText"
|
|
58
|
+
v-if="isRendered && altText"
|
|
46
59
|
:alt-text="altText"
|
|
47
60
|
as-child
|
|
48
61
|
>
|
|
@@ -51,9 +64,9 @@ const { forwardRef } = useForwardExpose();
|
|
|
51
64
|
:as="as"
|
|
52
65
|
:as-child="asChild"
|
|
53
66
|
:type="as === 'button' ? 'button' : undefined"
|
|
54
|
-
@click="
|
|
67
|
+
@click="handleClick"
|
|
55
68
|
>
|
|
56
|
-
<slot
|
|
69
|
+
<slot>{{ actionProps?.label }}</slot>
|
|
57
70
|
</Primitive>
|
|
58
71
|
</ToastAnnounceExclude>
|
|
59
72
|
</template>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { PrimitiveProps } from '@/Primitive';
|
|
3
|
+
import { useForwardExpose } from '@/shared';
|
|
4
|
+
|
|
5
|
+
export interface ToastArrowProps extends PrimitiveProps {
|
|
6
|
+
/**
|
|
7
|
+
* The width of the arrow in pixels.
|
|
8
|
+
*
|
|
9
|
+
* @defaultValue 10
|
|
10
|
+
*/
|
|
11
|
+
width?: number;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The height of the arrow in pixels.
|
|
15
|
+
*
|
|
16
|
+
* @defaultValue 5
|
|
17
|
+
*/
|
|
18
|
+
height?: number;
|
|
19
|
+
}
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<script setup lang="ts">
|
|
23
|
+
import { PopperArrow } from '@/Popper';
|
|
24
|
+
|
|
25
|
+
const props = withDefaults(defineProps<ToastArrowProps>(), {
|
|
26
|
+
width: 10,
|
|
27
|
+
height: 5,
|
|
28
|
+
as: 'svg',
|
|
29
|
+
});
|
|
30
|
+
useForwardExpose();
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<template>
|
|
34
|
+
<PopperArrow v-bind="props">
|
|
35
|
+
<slot />
|
|
36
|
+
</PopperArrow>
|
|
37
|
+
</template>
|
|
@@ -7,13 +7,19 @@ export interface ToastDescriptionProps extends PrimitiveProps {}
|
|
|
7
7
|
|
|
8
8
|
<script setup lang="ts">
|
|
9
9
|
import { Primitive } from '@/Primitive';
|
|
10
|
+
import { injectToastRootContext } from './ToastRootImpl.vue';
|
|
10
11
|
|
|
11
12
|
const props = defineProps<ToastDescriptionProps>();
|
|
12
13
|
useForwardExpose();
|
|
14
|
+
const rootContext = injectToastRootContext(null);
|
|
13
15
|
</script>
|
|
14
16
|
|
|
15
17
|
<template>
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
<!-- A managed toast without a description renders nothing, unless slot content is given. -->
|
|
19
|
+
<Primitive
|
|
20
|
+
v-if="$slots.default || !rootContext?.toast.value || rootContext.toast.value.description"
|
|
21
|
+
v-bind="props"
|
|
22
|
+
>
|
|
23
|
+
<slot>{{ rootContext?.toast.value?.description }}</slot>
|
|
18
24
|
</Primitive>
|
|
19
25
|
</template>
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { ReferenceElement } from '@floating-ui/vue';
|
|
3
|
+
import type { ToastObject } from './createToastManager';
|
|
4
|
+
import type { PopperContentProps } from '@/Popper';
|
|
5
|
+
import { createContext, useForwardExpose } from '@/shared';
|
|
6
|
+
|
|
7
|
+
export interface ToastPositionerProps extends Omit<PopperContentProps, 'reference' | 'memoDependencies'> {
|
|
8
|
+
/** The toast to position. Its `positionerProps` are used for any prop that is not set. */
|
|
9
|
+
toast: ToastObject;
|
|
10
|
+
/** The element to position the toast against. Defaults to `toast.positionerProps.anchor`. */
|
|
11
|
+
anchor?: ReferenceElement | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const [injectToastPositionerContext, provideToastPositionerContext]
|
|
15
|
+
= createContext<object>('ToastPositioner');
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<script setup lang="ts">
|
|
19
|
+
import { computed } from 'vue';
|
|
20
|
+
import { PopperContent, PopperContentPropsDefaultValue, PopperRoot } from '@/Popper';
|
|
21
|
+
|
|
22
|
+
defineOptions({
|
|
23
|
+
inheritAttrs: false,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const props = withDefaults(defineProps<ToastPositionerProps>(), {
|
|
27
|
+
// Leave booleans unset so `toast.positionerProps` can fill them in.
|
|
28
|
+
sideFlip: undefined,
|
|
29
|
+
alignFlip: undefined,
|
|
30
|
+
avoidCollisions: undefined,
|
|
31
|
+
hideShiftedArrow: undefined,
|
|
32
|
+
hideWhenDetached: undefined,
|
|
33
|
+
disableUpdateOnLayoutShift: undefined,
|
|
34
|
+
prioritizePosition: undefined,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const { forwardRef } = useForwardExpose();
|
|
38
|
+
|
|
39
|
+
const DEFAULTS = {
|
|
40
|
+
...PopperContentPropsDefaultValue,
|
|
41
|
+
side: 'top',
|
|
42
|
+
collisionPadding: 5,
|
|
43
|
+
arrowPadding: 5,
|
|
44
|
+
} as const;
|
|
45
|
+
|
|
46
|
+
const resolvedProps = computed(() => {
|
|
47
|
+
const fromToast = props.toast.positionerProps ?? {};
|
|
48
|
+
const resolved: Record<string, unknown> = {};
|
|
49
|
+
for (const key of Object.keys(props) as Array<keyof ToastPositionerProps>) {
|
|
50
|
+
if (key === 'toast' || key === 'anchor') {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
resolved[key] = props[key] ?? fromToast[key as keyof typeof fromToast] ?? DEFAULTS[key as keyof typeof DEFAULTS];
|
|
54
|
+
}
|
|
55
|
+
if (typeof resolved.collisionBoundary === 'function') {
|
|
56
|
+
resolved.collisionBoundary = resolved.collisionBoundary();
|
|
57
|
+
}
|
|
58
|
+
return resolved as PopperContentProps;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const anchor = computed(() => props.anchor ?? props.toast.positionerProps?.anchor ?? undefined);
|
|
62
|
+
|
|
63
|
+
provideToastPositionerContext({});
|
|
64
|
+
</script>
|
|
65
|
+
|
|
66
|
+
<template>
|
|
67
|
+
<PopperRoot>
|
|
68
|
+
<PopperContent
|
|
69
|
+
v-bind="{ ...resolvedProps, ...$attrs }"
|
|
70
|
+
:ref="forwardRef"
|
|
71
|
+
:reference="anchor"
|
|
72
|
+
>
|
|
73
|
+
<slot />
|
|
74
|
+
</PopperContent>
|
|
75
|
+
</PopperRoot>
|
|
76
|
+
</template>
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import type { Ref } from 'vue';
|
|
2
|
+
import type { ComputedRef, Ref } from 'vue';
|
|
3
|
+
import type { GlobalToastManager } from './createToastManager';
|
|
4
|
+
import type { ToastStore } from './useToastStore';
|
|
3
5
|
import type { SwipeDirection } from './utils';
|
|
4
6
|
import { useCollection } from '@/Collection';
|
|
5
7
|
import { createContext } from '@/shared';
|
|
@@ -17,8 +19,34 @@ type ToastProviderContext = {
|
|
|
17
19
|
onToastRemove: () => void;
|
|
18
20
|
isFocusedToastEscapeKeyDownRef: Ref<boolean>;
|
|
19
21
|
isClosePausedRef: Ref<boolean>;
|
|
22
|
+
toastStore: ToastStore;
|
|
23
|
+
hovering: Ref<boolean>;
|
|
24
|
+
focused: Ref<boolean>;
|
|
25
|
+
expanded: ComputedRef<boolean>;
|
|
26
|
+
frontmostHeight: ComputedRef<number | undefined>;
|
|
27
|
+
closingCount: ComputedRef<number>;
|
|
28
|
+
registerToast: (entry: ToastStackEntry) => () => void;
|
|
29
|
+
reopenToast: (entry: ToastStackEntry) => void;
|
|
30
|
+
getToastStack: (entry: ToastStackEntry) => ToastStackState;
|
|
20
31
|
};
|
|
21
32
|
|
|
33
|
+
export interface ToastStackEntry {
|
|
34
|
+
/** Order of the toast; higher is newer. */
|
|
35
|
+
seq: number;
|
|
36
|
+
/** Measured natural height in pixels. */
|
|
37
|
+
height: number;
|
|
38
|
+
open: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ToastStackState {
|
|
42
|
+
/** Position among open toasts, newest first. Closing toasts keep their position in the whole list. */
|
|
43
|
+
index: number;
|
|
44
|
+
/** Sum of the heights of the newer open toasts. */
|
|
45
|
+
offsetY: number;
|
|
46
|
+
/** Whether the toast is beyond the `limit` of the provider. */
|
|
47
|
+
limited: boolean;
|
|
48
|
+
}
|
|
49
|
+
|
|
22
50
|
export interface ToastProviderProps {
|
|
23
51
|
/**
|
|
24
52
|
* An author-localized label for each toast. Used to help screen reader users
|
|
@@ -46,6 +74,17 @@ export interface ToastProviderProps {
|
|
|
46
74
|
* @defaultValue 50
|
|
47
75
|
*/
|
|
48
76
|
swipeThreshold?: number;
|
|
77
|
+
/**
|
|
78
|
+
* The maximum number of toasts shown at once. Older toasts beyond the limit get
|
|
79
|
+
* `data-limited` and `inert` rather than being removed, so they can be hidden or animated.
|
|
80
|
+
* No limit is applied when unset.
|
|
81
|
+
*/
|
|
82
|
+
limit?: number;
|
|
83
|
+
/**
|
|
84
|
+
* A manager created with `createToastManager()`, to add toasts from outside
|
|
85
|
+
* components. Its toasts are listed by `useToastManager()`.
|
|
86
|
+
*/
|
|
87
|
+
toastManager?: GlobalToastManager;
|
|
49
88
|
}
|
|
50
89
|
|
|
51
90
|
export const [injectToastProviderContext, provideToastProviderContext]
|
|
@@ -53,8 +92,9 @@ export const [injectToastProviderContext, provideToastProviderContext]
|
|
|
53
92
|
</script>
|
|
54
93
|
|
|
55
94
|
<script setup lang="ts">
|
|
56
|
-
import {
|
|
57
|
-
import {
|
|
95
|
+
import { computed, onMounted, ref, shallowReactive, toRefs, watch } from 'vue';
|
|
96
|
+
import { TOAST_MANAGER_SUBSCRIBE } from './createToastManager';
|
|
97
|
+
import { useToastStore } from './useToastStore';
|
|
58
98
|
|
|
59
99
|
defineOptions({
|
|
60
100
|
inheritAttrs: false,
|
|
@@ -74,7 +114,54 @@ const toastCount = ref(0);
|
|
|
74
114
|
const isFocusedToastEscapeKeyDownRef = ref(false);
|
|
75
115
|
const isClosePausedRef = ref(false);
|
|
76
116
|
|
|
77
|
-
|
|
117
|
+
const toastStore = useToastStore();
|
|
118
|
+
|
|
119
|
+
onMounted(() => {
|
|
120
|
+
// Subscribe on mount only: a module-level manager outlives SSR requests.
|
|
121
|
+
watch(() => props.toastManager, (manager, _, onCleanup) => {
|
|
122
|
+
if (!manager) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
const unsubscribe = manager[TOAST_MANAGER_SUBSCRIBE]((event) => {
|
|
126
|
+
if (event.action === 'add') {
|
|
127
|
+
toastStore.add(event.options);
|
|
128
|
+
} else if (event.action === 'close') {
|
|
129
|
+
toastStore.close(event.id);
|
|
130
|
+
} else {
|
|
131
|
+
toastStore.update(event.id, event.updates);
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
onCleanup(unsubscribe);
|
|
135
|
+
}, { immediate: true });
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const entries = shallowReactive<Array<ToastStackEntry>>([]);
|
|
139
|
+
let seq = 0;
|
|
140
|
+
|
|
141
|
+
const stack = computed(() => {
|
|
142
|
+
const ordered = [...entries].sort((a, b) => b.seq - a.seq);
|
|
143
|
+
const states = new Map<ToastStackEntry, ToastStackState>();
|
|
144
|
+
let visibleIndex = 0;
|
|
145
|
+
let offsetY = 0;
|
|
146
|
+
ordered.forEach((entry, index) => {
|
|
147
|
+
const closing = !entry.open;
|
|
148
|
+
states.set(entry, {
|
|
149
|
+
index: closing ? index : visibleIndex,
|
|
150
|
+
offsetY,
|
|
151
|
+
limited: !closing && props.limit !== undefined && visibleIndex >= props.limit,
|
|
152
|
+
});
|
|
153
|
+
if (!closing) {
|
|
154
|
+
offsetY += entry.height;
|
|
155
|
+
visibleIndex++;
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
return { ordered, states };
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const hovering = ref(false);
|
|
162
|
+
const focused = ref(false);
|
|
163
|
+
|
|
164
|
+
if (props.label && typeof props.label === 'string' && !props.label.trim()) {
|
|
78
165
|
const error = 'Invalid prop `label` supplied to `ToastProvider`. Expected non-empty `string`.';
|
|
79
166
|
throw new Error(error);
|
|
80
167
|
}
|
|
@@ -98,7 +185,28 @@ provideToastProviderContext({
|
|
|
98
185
|
},
|
|
99
186
|
isFocusedToastEscapeKeyDownRef,
|
|
100
187
|
isClosePausedRef,
|
|
101
|
-
|
|
188
|
+
toastStore,
|
|
189
|
+
hovering,
|
|
190
|
+
focused,
|
|
191
|
+
expanded: computed(() => hovering.value || focused.value),
|
|
192
|
+
frontmostHeight: computed(() => stack.value.ordered.find((entry) => entry.open)?.height || undefined),
|
|
193
|
+
closingCount: computed(() => entries.filter((entry) => !entry.open).length),
|
|
194
|
+
registerToast(entry) {
|
|
195
|
+
entry.seq = ++seq;
|
|
196
|
+
entries.push(entry);
|
|
197
|
+
return () => {
|
|
198
|
+
const index = entries.indexOf(entry);
|
|
199
|
+
if (index !== -1) {
|
|
200
|
+
entries.splice(index, 1);
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
},
|
|
204
|
+
reopenToast(entry) {
|
|
205
|
+
entry.seq = ++seq;
|
|
206
|
+
},
|
|
207
|
+
getToastStack(entry) {
|
|
208
|
+
return stack.value.states.get(entry) ?? { index: 0, offsetY: 0, limited: false };
|
|
209
|
+
},
|
|
102
210
|
});
|
|
103
211
|
</script>
|
|
104
212
|
|
package/src/Toast/ToastRoot.vue
CHANGED
|
@@ -21,7 +21,9 @@ export interface ToastRootProps extends ToastRootImplProps {
|
|
|
21
21
|
|
|
22
22
|
<script setup lang="ts">
|
|
23
23
|
import { useVModel } from '@vueuse/core';
|
|
24
|
+
import { computed, ref, watch } from 'vue';
|
|
24
25
|
import { Presence } from '@/Presence';
|
|
26
|
+
import { injectToastProviderContext } from './ToastProvider.vue';
|
|
25
27
|
import ToastRootImpl from './ToastRootImpl.vue';
|
|
26
28
|
|
|
27
29
|
const props = withDefaults(defineProps<ToastRootProps>(), {
|
|
@@ -36,7 +38,7 @@ const emits = defineEmits<ToastRootEmits>();
|
|
|
36
38
|
defineSlots<{
|
|
37
39
|
default?: (props: {
|
|
38
40
|
/** Current open state */
|
|
39
|
-
open:
|
|
41
|
+
open: boolean;
|
|
40
42
|
/** Remaining time (in ms) */
|
|
41
43
|
remaining: number;
|
|
42
44
|
/** Total time the toast will remain visible for (in ms) */
|
|
@@ -49,20 +51,49 @@ const open = useVModel(props, 'open', emits, {
|
|
|
49
51
|
defaultValue: props.defaultOpen,
|
|
50
52
|
passive: (props.open === undefined) as false,
|
|
51
53
|
}) as Ref<boolean>;
|
|
54
|
+
|
|
55
|
+
const providerContext = injectToastProviderContext();
|
|
56
|
+
|
|
57
|
+
const isOpen = computed(() => props.toast ? props.toast.open : open.value);
|
|
58
|
+
const resolvedType = computed(() => props.toast?.type ?? props.type);
|
|
59
|
+
const resolvedDuration = computed(() => props.toast?.status === 'loading'
|
|
60
|
+
? Number.POSITIVE_INFINITY
|
|
61
|
+
: props.toast?.duration ?? props.duration);
|
|
62
|
+
|
|
63
|
+
function close() {
|
|
64
|
+
if (props.toast) {
|
|
65
|
+
providerContext.toastStore.close(props.toast.id);
|
|
66
|
+
emits('update:open', false);
|
|
67
|
+
} else {
|
|
68
|
+
open.value = false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// A managed toast leaves the list once it is closed and its exit animation has
|
|
73
|
+
// unmounted the content (or it closed before the content ever mounted).
|
|
74
|
+
const isContentMounted = ref(false);
|
|
75
|
+
watch([() => props.toast, isContentMounted], ([toast, mounted]) => {
|
|
76
|
+
if (toast && !toast.open && !mounted) {
|
|
77
|
+
providerContext.toastStore.remove(toast.id);
|
|
78
|
+
}
|
|
79
|
+
}, { immediate: true });
|
|
52
80
|
</script>
|
|
53
81
|
|
|
54
82
|
<template>
|
|
55
|
-
<Presence :present="forceMount ||
|
|
83
|
+
<Presence :present="forceMount || isOpen">
|
|
56
84
|
<ToastRootImpl
|
|
57
85
|
:ref="forwardRef"
|
|
58
86
|
v-slot="{ remaining, duration: _duration }"
|
|
59
|
-
:open="
|
|
60
|
-
:type="
|
|
87
|
+
:open="isOpen"
|
|
88
|
+
:type="resolvedType"
|
|
61
89
|
:as="as"
|
|
62
90
|
:as-child="asChild"
|
|
63
|
-
:duration="
|
|
91
|
+
:duration="resolvedDuration"
|
|
92
|
+
:toast="toast"
|
|
64
93
|
v-bind="$attrs"
|
|
65
|
-
@
|
|
94
|
+
@vue:mounted="isContentMounted = true"
|
|
95
|
+
@vue:unmounted="isContentMounted = false"
|
|
96
|
+
@close="close"
|
|
66
97
|
@pause="emits('pause')"
|
|
67
98
|
@resume="emits('resume')"
|
|
68
99
|
@escape-key-down="emits('escapeKeyDown', $event)"
|
|
@@ -103,14 +134,14 @@ const open = useVModel(props, 'open', emits, {
|
|
|
103
134
|
target.style.removeProperty('--akar-toast-swipe-move-y');
|
|
104
135
|
target.style.setProperty('--akar-toast-swipe-end-x', `${x}px`);
|
|
105
136
|
target.style.setProperty('--akar-toast-swipe-end-y', `${y}px`);
|
|
106
|
-
|
|
137
|
+
close();
|
|
107
138
|
}
|
|
108
139
|
}"
|
|
109
140
|
>
|
|
110
141
|
<slot
|
|
111
142
|
:remaining="remaining"
|
|
112
143
|
:duration="_duration"
|
|
113
|
-
:open="
|
|
144
|
+
:open="isOpen"
|
|
114
145
|
/>
|
|
115
146
|
</ToastRootImpl>
|
|
116
147
|
</Presence>
|