akar 2.0.11 → 2.0.14
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/AlertDialog/AlertDialogContent.cjs +2 -1
- package/dist/AlertDialog/AlertDialogContent.cjs.map +1 -1
- package/dist/AlertDialog/AlertDialogContent.js +2 -1
- package/dist/AlertDialog/AlertDialogContent.js.map +1 -1
- package/dist/AlertDialog/AlertDialogRoot.cjs +4 -0
- package/dist/AlertDialog/AlertDialogRoot.cjs.map +1 -1
- package/dist/AlertDialog/AlertDialogRoot.js +4 -0
- package/dist/AlertDialog/AlertDialogRoot.js.map +1 -1
- package/dist/Calendar/CalendarCellTrigger.cjs +3 -2
- package/dist/Calendar/CalendarCellTrigger.cjs.map +1 -1
- package/dist/Calendar/CalendarCellTrigger.js +4 -3
- package/dist/Calendar/CalendarCellTrigger.js.map +1 -1
- package/dist/Checkbox/CheckboxRoot.cjs +27 -18
- package/dist/Checkbox/CheckboxRoot.cjs.map +1 -1
- package/dist/Checkbox/CheckboxRoot.js +28 -19
- package/dist/Checkbox/CheckboxRoot.js.map +1 -1
- package/dist/Combobox/ComboboxContent.cjs +4 -0
- package/dist/Combobox/ComboboxContent.cjs.map +1 -1
- package/dist/Combobox/ComboboxContent.js +4 -0
- package/dist/Combobox/ComboboxContent.js.map +1 -1
- package/dist/Combobox/ComboboxContentImpl.cjs +4 -0
- package/dist/Combobox/ComboboxContentImpl.cjs.map +1 -1
- package/dist/Combobox/ComboboxContentImpl.js +4 -0
- package/dist/Combobox/ComboboxContentImpl.js.map +1 -1
- package/dist/ConfigProvider/ConfigProvider.cjs +6 -1
- package/dist/ConfigProvider/ConfigProvider.cjs.map +1 -1
- package/dist/ConfigProvider/ConfigProvider.js +6 -1
- package/dist/ConfigProvider/ConfigProvider.js.map +1 -1
- package/dist/DatePicker/DatePickerContent.cjs +4 -0
- package/dist/DatePicker/DatePickerContent.cjs.map +1 -1
- package/dist/DatePicker/DatePickerContent.js +4 -0
- package/dist/DatePicker/DatePickerContent.js.map +1 -1
- package/dist/DateRangePicker/DateRangePickerContent.cjs +4 -0
- package/dist/DateRangePicker/DateRangePickerContent.cjs.map +1 -1
- package/dist/DateRangePicker/DateRangePickerContent.js +4 -0
- package/dist/DateRangePicker/DateRangePickerContent.js.map +1 -1
- package/dist/Dialog/DialogContent.cjs +14 -9
- package/dist/Dialog/DialogContent.cjs.map +1 -1
- package/dist/Dialog/DialogContent.js +15 -10
- package/dist/Dialog/DialogContent.js.map +1 -1
- package/dist/Dialog/DialogContentImpl.cjs +8 -1
- package/dist/Dialog/DialogContentImpl.cjs.map +1 -1
- package/dist/Dialog/DialogContentImpl.js +8 -1
- package/dist/Dialog/DialogContentImpl.js.map +1 -1
- package/dist/Dialog/DialogContentModal.cjs +20 -3
- package/dist/Dialog/DialogContentModal.cjs.map +1 -1
- package/dist/Dialog/DialogContentModal.js +21 -4
- package/dist/Dialog/DialogContentModal.js.map +1 -1
- package/dist/Dialog/DialogContentNonModal.cjs +18 -2
- package/dist/Dialog/DialogContentNonModal.cjs.map +1 -1
- package/dist/Dialog/DialogContentNonModal.js +19 -3
- package/dist/Dialog/DialogContentNonModal.js.map +1 -1
- package/dist/Dialog/DialogOverlay.cjs +12 -6
- package/dist/Dialog/DialogOverlay.cjs.map +1 -1
- package/dist/Dialog/DialogOverlay.js +13 -7
- package/dist/Dialog/DialogOverlay.js.map +1 -1
- package/dist/Dialog/DialogOverlayImpl.cjs +10 -1
- package/dist/Dialog/DialogOverlayImpl.cjs.map +1 -1
- package/dist/Dialog/DialogOverlayImpl.js +11 -2
- package/dist/Dialog/DialogOverlayImpl.js.map +1 -1
- package/dist/Dialog/DialogRoot.cjs +7 -1
- package/dist/Dialog/DialogRoot.cjs.map +1 -1
- package/dist/Dialog/DialogRoot.js +7 -1
- package/dist/Dialog/DialogRoot.js.map +1 -1
- package/dist/DismissableLayer/DismissableLayer.cjs +20 -4
- package/dist/DismissableLayer/DismissableLayer.cjs.map +1 -1
- package/dist/DismissableLayer/DismissableLayer.js +20 -4
- package/dist/DismissableLayer/DismissableLayer.js.map +1 -1
- package/dist/FocusScope/FocusScope.cjs +32 -11
- package/dist/FocusScope/FocusScope.cjs.map +1 -1
- package/dist/FocusScope/FocusScope.js +33 -12
- package/dist/FocusScope/FocusScope.js.map +1 -1
- package/dist/HoverCard/HoverCardContent.cjs +4 -0
- package/dist/HoverCard/HoverCardContent.cjs.map +1 -1
- package/dist/HoverCard/HoverCardContent.js +4 -0
- package/dist/HoverCard/HoverCardContent.js.map +1 -1
- package/dist/HoverCard/HoverCardContentImpl.cjs +4 -0
- package/dist/HoverCard/HoverCardContentImpl.cjs.map +1 -1
- package/dist/HoverCard/HoverCardContentImpl.js +4 -0
- package/dist/HoverCard/HoverCardContentImpl.js.map +1 -1
- package/dist/Listbox/ListboxRoot.cjs +1 -0
- package/dist/Listbox/ListboxRoot.cjs.map +1 -1
- package/dist/Listbox/ListboxRoot.js +1 -0
- package/dist/Listbox/ListboxRoot.js.map +1 -1
- package/dist/Menu/MenuContentImpl.cjs +2 -1
- package/dist/Menu/MenuContentImpl.cjs.map +1 -1
- package/dist/Menu/MenuContentImpl.js +2 -1
- package/dist/Menu/MenuContentImpl.js.map +1 -1
- package/dist/MonthPicker/MonthPickerCellTrigger.cjs +3 -2
- package/dist/MonthPicker/MonthPickerCellTrigger.cjs.map +1 -1
- package/dist/MonthPicker/MonthPickerCellTrigger.js +4 -3
- package/dist/MonthPicker/MonthPickerCellTrigger.js.map +1 -1
- package/dist/MonthRangePicker/MonthRangePickerCellTrigger.cjs +3 -2
- package/dist/MonthRangePicker/MonthRangePickerCellTrigger.cjs.map +1 -1
- package/dist/MonthRangePicker/MonthRangePickerCellTrigger.js +4 -3
- package/dist/MonthRangePicker/MonthRangePickerCellTrigger.js.map +1 -1
- package/dist/NumberField/NumberFieldRoot.cjs +27 -5
- package/dist/NumberField/NumberFieldRoot.cjs.map +1 -1
- package/dist/NumberField/NumberFieldRoot.js +27 -5
- package/dist/NumberField/NumberFieldRoot.js.map +1 -1
- package/dist/Popover/PopoverContent.cjs +4 -0
- package/dist/Popover/PopoverContent.cjs.map +1 -1
- package/dist/Popover/PopoverContent.js +4 -0
- package/dist/Popover/PopoverContent.js.map +1 -1
- package/dist/Popover/PopoverContentImpl.cjs +4 -0
- package/dist/Popover/PopoverContentImpl.cjs.map +1 -1
- package/dist/Popover/PopoverContentImpl.js +4 -0
- package/dist/Popover/PopoverContentImpl.js.map +1 -1
- package/dist/Popover/PopoverContentModal.cjs +4 -0
- package/dist/Popover/PopoverContentModal.cjs.map +1 -1
- package/dist/Popover/PopoverContentModal.js +4 -0
- package/dist/Popover/PopoverContentModal.js.map +1 -1
- package/dist/Popover/PopoverContentNonModal.cjs +4 -0
- package/dist/Popover/PopoverContentNonModal.cjs.map +1 -1
- package/dist/Popover/PopoverContentNonModal.js +4 -0
- package/dist/Popover/PopoverContentNonModal.js.map +1 -1
- package/dist/Popper/PopperContent.cjs +14 -4
- package/dist/Popper/PopperContent.cjs.map +1 -1
- package/dist/Popper/PopperContent.js +14 -4
- package/dist/Popper/PopperContent.js.map +1 -1
- package/dist/Popper/utils.cjs +10 -5
- package/dist/Popper/utils.cjs.map +1 -1
- package/dist/Popper/utils.js +10 -5
- package/dist/Popper/utils.js.map +1 -1
- package/dist/Presence/usePresence.cjs +6 -0
- package/dist/Presence/usePresence.cjs.map +1 -1
- package/dist/Presence/usePresence.js +6 -0
- package/dist/Presence/usePresence.js.map +1 -1
- package/dist/RadioGroup/Radio.cjs +27 -22
- package/dist/RadioGroup/Radio.cjs.map +1 -1
- package/dist/RadioGroup/Radio.js +28 -23
- package/dist/RadioGroup/Radio.js.map +1 -1
- package/dist/RadioGroup/RadioGroupItem.cjs +3 -0
- package/dist/RadioGroup/RadioGroupItem.cjs.map +1 -1
- package/dist/RadioGroup/RadioGroupItem.js +3 -0
- package/dist/RadioGroup/RadioGroupItem.js.map +1 -1
- package/dist/RangeCalendar/RangeCalendarCellTrigger.cjs +1 -0
- package/dist/RangeCalendar/RangeCalendarCellTrigger.cjs.map +1 -1
- package/dist/RangeCalendar/RangeCalendarCellTrigger.js +1 -0
- package/dist/RangeCalendar/RangeCalendarCellTrigger.js.map +1 -1
- package/dist/RovingFocus/RovingFocusItem.cjs +5 -0
- package/dist/RovingFocus/RovingFocusItem.cjs.map +1 -1
- package/dist/RovingFocus/RovingFocusItem.js +6 -1
- package/dist/RovingFocus/RovingFocusItem.js.map +1 -1
- package/dist/ScrollArea/ScrollAreaThumb.cjs +2 -2
- package/dist/ScrollArea/ScrollAreaThumb.cjs.map +1 -1
- package/dist/ScrollArea/ScrollAreaThumb.js +2 -2
- package/dist/ScrollArea/ScrollAreaThumb.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 +4 -0
- package/dist/Select/SelectContentImpl.cjs.map +1 -1
- package/dist/Select/SelectContentImpl.js +4 -0
- package/dist/Select/SelectContentImpl.js.map +1 -1
- package/dist/Select/SelectPopperPosition.cjs +4 -0
- package/dist/Select/SelectPopperPosition.cjs.map +1 -1
- package/dist/Select/SelectPopperPosition.js +4 -0
- package/dist/Select/SelectPopperPosition.js.map +1 -1
- package/dist/Splitter/SplitterGroup.cjs +2 -2
- package/dist/Splitter/SplitterGroup.cjs.map +1 -1
- package/dist/Splitter/SplitterGroup.js +2 -2
- package/dist/Splitter/SplitterGroup.js.map +1 -1
- package/dist/Switch/SwitchRoot.cjs +25 -18
- package/dist/Switch/SwitchRoot.cjs.map +1 -1
- package/dist/Switch/SwitchRoot.js +26 -19
- package/dist/Switch/SwitchRoot.js.map +1 -1
- package/dist/Teleport/Teleport.cjs +6 -3
- package/dist/Teleport/Teleport.cjs.map +1 -1
- package/dist/Teleport/Teleport.js +7 -4
- package/dist/Teleport/Teleport.js.map +1 -1
- package/dist/Toggle/Toggle.cjs +21 -16
- package/dist/Toggle/Toggle.cjs.map +1 -1
- package/dist/Toggle/Toggle.js +22 -17
- package/dist/Toggle/Toggle.js.map +1 -1
- package/dist/ToggleGroup/ToggleGroupItem.cjs +6 -1
- package/dist/ToggleGroup/ToggleGroupItem.cjs.map +1 -1
- package/dist/ToggleGroup/ToggleGroupItem.js +6 -1
- package/dist/ToggleGroup/ToggleGroupItem.js.map +1 -1
- package/dist/Toolbar/ToolbarToggleItem.cjs +5 -2
- package/dist/Toolbar/ToolbarToggleItem.cjs.map +1 -1
- package/dist/Toolbar/ToolbarToggleItem.js +5 -2
- package/dist/Toolbar/ToolbarToggleItem.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/YearPicker/YearPickerCellTrigger.cjs +3 -2
- package/dist/YearPicker/YearPickerCellTrigger.cjs.map +1 -1
- package/dist/YearPicker/YearPickerCellTrigger.js +4 -3
- package/dist/YearPicker/YearPickerCellTrigger.js.map +1 -1
- package/dist/YearRangePicker/YearRangePickerCellTrigger.cjs +3 -2
- package/dist/YearRangePicker/YearRangePickerCellTrigger.cjs.map +1 -1
- package/dist/YearRangePicker/YearRangePickerCellTrigger.js +4 -3
- package/dist/YearRangePicker/YearRangePickerCellTrigger.js.map +1 -1
- package/dist/constant/components.cjs +15 -0
- package/dist/constant/components.cjs.map +1 -1
- package/dist/constant/components.js +15 -0
- package/dist/constant/components.js.map +1 -1
- package/dist/constant.d.cts +1 -0
- package/dist/constant.d.cts.map +1 -1
- package/dist/constant.d.ts +1 -0
- package/dist/constant.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/index2.d.cts.map +1 -1
- package/dist/index2.d.ts.map +1 -1
- package/dist/index3.d.cts +38 -20
- package/dist/index3.d.cts.map +1 -1
- package/dist/index3.d.ts +27 -9
- package/dist/index3.d.ts.map +1 -1
- package/dist/index4.d.cts +686 -658
- package/dist/index4.d.cts.map +1 -1
- package/dist/index4.d.ts +712 -684
- package/dist/index4.d.ts.map +1 -1
- package/dist/internal.cjs +1 -1
- package/dist/internal.d.cts +2 -2
- package/dist/internal.d.ts +2 -2
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +1 -1
- package/dist/namespaced/index.cjs +16 -0
- package/dist/namespaced/index.d.cts +17 -2
- package/dist/namespaced/index.d.mts +17 -2
- package/dist/namespaced/index.mjs +17 -2
- package/dist/nuxt/index.d.cts +2 -1
- package/dist/nuxt/index.d.mts +2 -1
- package/dist/resolver/index.d.cts +2 -1
- package/dist/resolver/index.d.mts +2 -1
- package/dist/shared/useForwardScopeId.cjs +34 -0
- package/dist/shared/useForwardScopeId.cjs.map +1 -0
- package/dist/shared/useForwardScopeId.js +28 -0
- package/dist/shared/useForwardScopeId.js.map +1 -0
- package/dist/shared.cjs +2 -2
- package/dist/shared.d.cts +2 -2
- package/dist/shared.d.ts +2 -2
- package/dist/shared.js +2 -2
- package/package.json +1 -1
- package/src/AlertDialog/AlertDialogContent.vue +9 -1
- package/src/Calendar/CalendarCellTrigger.vue +5 -1
- package/src/Checkbox/CheckboxRoot.vue +30 -16
- package/src/ConfigProvider/ConfigProvider.vue +10 -1
- package/src/Dialog/DialogContent.vue +9 -1
- package/src/Dialog/DialogContentImpl.vue +9 -2
- package/src/Dialog/DialogContentModal.vue +21 -3
- package/src/Dialog/DialogContentNonModal.vue +22 -3
- package/src/Dialog/DialogOverlay.vue +4 -0
- package/src/Dialog/DialogOverlayImpl.vue +8 -2
- package/src/Dialog/DialogRoot.vue +10 -1
- package/src/DismissableLayer/DismissableLayer.vue +44 -8
- package/src/FocusScope/FocusScope.vue +97 -24
- package/src/Listbox/ListboxRoot.vue +6 -0
- package/src/Menu/MenuContentImpl.vue +8 -1
- package/src/MonthPicker/MonthPickerCellTrigger.vue +5 -1
- package/src/MonthRangePicker/MonthRangePickerCellTrigger.vue +6 -1
- package/src/NumberField/NumberFieldRoot.vue +51 -23
- package/src/Popper/PopperContent.vue +11 -3
- package/src/Popper/utils.ts +21 -11
- package/src/Presence/usePresence.ts +8 -0
- package/src/RadioGroup/Radio.vue +29 -18
- package/src/RadioGroup/RadioGroupItem.vue +15 -6
- package/src/RangeCalendar/RangeCalendarCellTrigger.vue +6 -0
- package/src/RovingFocus/RovingFocusItem.vue +16 -1
- package/src/ScrollArea/ScrollAreaThumb.vue +2 -2
- package/src/Splitter/SplitterGroup.vue +4 -2
- package/src/Switch/SwitchRoot.vue +29 -18
- package/src/Teleport/Teleport.vue +8 -4
- package/src/Toggle/Toggle.vue +25 -13
- package/src/ToggleGroup/ToggleGroupItem.vue +5 -2
- package/src/Toolbar/ToolbarToggleItem.vue +4 -1
- package/src/Tree/TreeRoot.vue +2 -2
- package/src/VisuallyHidden/VisuallyHidden.vue +1 -1
- package/src/YearPicker/YearPickerCellTrigger.vue +7 -1
- package/src/YearRangePicker/YearRangePickerCellTrigger.vue +5 -1
- package/src/shared/index.ts +1 -1
- package/src/shared/useForwardScopeId.ts +26 -0
- package/dist/shared/trap-focus.cjs +0 -35
- package/dist/shared/trap-focus.cjs.map +0 -1
- package/dist/shared/trap-focus.js +0 -30
- package/dist/shared/trap-focus.js.map +0 -1
- package/src/shared/trap-focus.ts +0 -44
|
@@ -5,7 +5,7 @@ import type { PrimitiveProps } from '@/Primitive';
|
|
|
5
5
|
import type { AcceptableValue, FormFieldProps } from '@/shared/types';
|
|
6
6
|
import { isDeepEqual, isNullish } from '@vinicunca/perkakas';
|
|
7
7
|
import { useVModel } from '@vueuse/core';
|
|
8
|
-
import { createContext, isValueEqualOrExist, useFormControl, useForwardExpose } from '@/shared';
|
|
8
|
+
import { createContext, isValueEqualOrExist, useFormControl, useForwardExpose, useForwardScopeId } from '@/shared';
|
|
9
9
|
import { injectCheckboxGroupRootContext } from './CheckboxGroupRoot.vue';
|
|
10
10
|
|
|
11
11
|
export interface CheckboxRootProps<T = boolean> extends PrimitiveProps, FormFieldProps {
|
|
@@ -47,7 +47,7 @@ export const [injectCheckboxRootContext, provideCheckboxRootContext]
|
|
|
47
47
|
</script>
|
|
48
48
|
|
|
49
49
|
<script setup lang="ts" generic="T = boolean">
|
|
50
|
-
import { computed } from 'vue';
|
|
50
|
+
import { computed, useAttrs } from 'vue';
|
|
51
51
|
import { Primitive } from '@/Primitive';
|
|
52
52
|
import { RovingFocusItem } from '@/RovingFocus';
|
|
53
53
|
import { VisuallyHiddenInput } from '@/VisuallyHidden';
|
|
@@ -119,9 +119,22 @@ function handleClick() {
|
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
const isFormControl = useFormControl(currentElement);
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
// The hidden form input is rendered as a sibling (not nested) of the interactive
|
|
123
|
+
// control to avoid the `nested-interactive` a11y violation. That makes this a
|
|
124
|
+
// multi-root component, so the parent's scoped-style id must be forwarded manually.
|
|
125
|
+
const scopeIdAttrs = useForwardScopeId();
|
|
126
|
+
|
|
127
|
+
const attrs = useAttrs();
|
|
128
|
+
const ariaLabel = computed(() => {
|
|
129
|
+
// An explicit `aria-label` always wins, so skip the (potentially expensive)
|
|
130
|
+
// label lookup entirely — this matters when rendering many checkboxes at once.
|
|
131
|
+
if (attrs['aria-label']) {
|
|
132
|
+
return undefined;
|
|
133
|
+
}
|
|
134
|
+
return props.id && currentElement.value
|
|
135
|
+
? (document.querySelector(`[for="${props.id}"]`) as HTMLLabelElement)?.innerText
|
|
136
|
+
: undefined;
|
|
137
|
+
});
|
|
125
138
|
|
|
126
139
|
provideCheckboxRootContext({
|
|
127
140
|
disabled,
|
|
@@ -131,7 +144,7 @@ provideCheckboxRootContext({
|
|
|
131
144
|
|
|
132
145
|
<template>
|
|
133
146
|
<component
|
|
134
|
-
v-bind="
|
|
147
|
+
v-bind="{ ...$attrs, ...scopeIdAttrs }"
|
|
135
148
|
:is="checkboxGroupContext?.rovingFocus.value ? RovingFocusItem : Primitive"
|
|
136
149
|
:id="id"
|
|
137
150
|
:ref="forwardRef"
|
|
@@ -155,15 +168,16 @@ provideCheckboxRootContext({
|
|
|
155
168
|
:model-value="modelValue"
|
|
156
169
|
:state="checkboxState"
|
|
157
170
|
/>
|
|
158
|
-
|
|
159
|
-
<VisuallyHiddenInput
|
|
160
|
-
v-if="isFormControl && name && !checkboxGroupContext"
|
|
161
|
-
type="checkbox"
|
|
162
|
-
:checked="!!checkboxState"
|
|
163
|
-
:name="name"
|
|
164
|
-
:value="value"
|
|
165
|
-
:disabled="disabled"
|
|
166
|
-
:required="required"
|
|
167
|
-
/>
|
|
168
171
|
</component>
|
|
172
|
+
|
|
173
|
+
<VisuallyHiddenInput
|
|
174
|
+
v-if="isFormControl && name && !checkboxGroupContext"
|
|
175
|
+
type="checkbox"
|
|
176
|
+
:checked="!!checkboxState"
|
|
177
|
+
:name="name"
|
|
178
|
+
:value="value"
|
|
179
|
+
:disabled="disabled"
|
|
180
|
+
:required="required"
|
|
181
|
+
v-bind="scopeIdAttrs"
|
|
182
|
+
/>
|
|
169
183
|
</template>
|
|
@@ -8,6 +8,7 @@ interface ConfigProviderContextValue {
|
|
|
8
8
|
locale?: Ref<string>;
|
|
9
9
|
scrollBody?: Ref<boolean | ScrollBodyOption>;
|
|
10
10
|
nonce?: Ref<string | undefined>;
|
|
11
|
+
teleportTo?: Ref<string | HTMLElement | undefined>;
|
|
11
12
|
useId?: () => string;
|
|
12
13
|
}
|
|
13
14
|
|
|
@@ -35,6 +36,13 @@ export interface ConfigProviderProps {
|
|
|
35
36
|
* @type string
|
|
36
37
|
*/
|
|
37
38
|
nonce?: string;
|
|
39
|
+
/**
|
|
40
|
+
* The global default teleport target for all portalled primitives (e.g. `Dialog`, `Popover`, `Tooltip`).
|
|
41
|
+
* Individual `*Portal` components can still override this via their own `to` prop.
|
|
42
|
+
* Useful when rendering inside a custom element / shadow DOM.
|
|
43
|
+
* @type string | HTMLElement
|
|
44
|
+
*/
|
|
45
|
+
teleportTo?: string | HTMLElement;
|
|
38
46
|
/**
|
|
39
47
|
* The global `useId` injection as a workaround for preventing hydration issue.
|
|
40
48
|
*/
|
|
@@ -57,13 +65,14 @@ const props = withDefaults(defineProps<ConfigProviderProps>(), {
|
|
|
57
65
|
useId: undefined,
|
|
58
66
|
});
|
|
59
67
|
|
|
60
|
-
const { dir, locale, scrollBody, nonce } = toRefs(props);
|
|
68
|
+
const { dir, locale, scrollBody, nonce, teleportTo } = toRefs(props);
|
|
61
69
|
|
|
62
70
|
provideConfigProviderContext({
|
|
63
71
|
dir,
|
|
64
72
|
locale,
|
|
65
73
|
scrollBody,
|
|
66
74
|
nonce,
|
|
75
|
+
teleportTo,
|
|
67
76
|
useId: props.useId,
|
|
68
77
|
});
|
|
69
78
|
</script>
|
|
@@ -41,17 +41,25 @@ const { forwardRef } = useForwardExpose();
|
|
|
41
41
|
</script>
|
|
42
42
|
|
|
43
43
|
<template>
|
|
44
|
-
<Presence
|
|
44
|
+
<Presence
|
|
45
|
+
v-slot="{ present }"
|
|
46
|
+
:present="forceMount || rootContext.open.value"
|
|
47
|
+
:force-mount="forceMount || !rootContext.unmountOnHide.value"
|
|
48
|
+
>
|
|
45
49
|
<DialogContentModal
|
|
46
50
|
v-if="rootContext.modal.value"
|
|
51
|
+
v-show="rootContext.unmountOnHide.value || present"
|
|
47
52
|
:ref="forwardRef"
|
|
53
|
+
:present="rootContext.unmountOnHide.value || present"
|
|
48
54
|
v-bind="{ ...props, ...emitsAsProps, ...$attrs }"
|
|
49
55
|
>
|
|
50
56
|
<slot />
|
|
51
57
|
</DialogContentModal>
|
|
52
58
|
<DialogContentNonModal
|
|
53
59
|
v-else
|
|
60
|
+
v-show="rootContext.unmountOnHide.value || present"
|
|
54
61
|
:ref="forwardRef"
|
|
62
|
+
:present="rootContext.unmountOnHide.value || present"
|
|
55
63
|
v-bind="{ ...props, ...emitsAsProps, ...$attrs }"
|
|
56
64
|
>
|
|
57
65
|
<slot />
|
|
@@ -21,7 +21,7 @@ export type DialogContentImplEmits = DismissableLayerEmits & {
|
|
|
21
21
|
export interface DialogContentImplProps extends DismissableLayerProps {
|
|
22
22
|
/**
|
|
23
23
|
* Used to force mounting when more control is needed. Useful when
|
|
24
|
-
* controlling
|
|
24
|
+
* controlling transition with Vue native transition or other animation libraries.
|
|
25
25
|
*/
|
|
26
26
|
forceMount?: boolean;
|
|
27
27
|
/**
|
|
@@ -41,7 +41,12 @@ import { getOpenState } from '@/Menu/utils';
|
|
|
41
41
|
import { injectDialogRootContext } from './DialogRoot.vue';
|
|
42
42
|
import { useWarning } from './utils';
|
|
43
43
|
|
|
44
|
-
const props = defineProps<DialogContentImplProps
|
|
44
|
+
const props = defineProps<DialogContentImplProps & {
|
|
45
|
+
/** Whether the content is currently visible. Forwarded to `FocusScope` and
|
|
46
|
+
* `DismissableLayer` so a force-mounted dialog (`unmountOnHide: false`)
|
|
47
|
+
* auto-focuses on show and leaves the layer/scope stacks while hidden. */
|
|
48
|
+
present?: boolean;
|
|
49
|
+
}>();
|
|
45
50
|
const emits = defineEmits<DialogContentImplEmits>();
|
|
46
51
|
|
|
47
52
|
const rootContext = injectDialogRootContext();
|
|
@@ -76,6 +81,7 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
76
81
|
as-child
|
|
77
82
|
loop
|
|
78
83
|
:trapped="props.trapFocus"
|
|
84
|
+
:present="props.present"
|
|
79
85
|
@mount-auto-focus="emits('openAutoFocus', $event)"
|
|
80
86
|
@unmount-auto-focus="emits('closeAutoFocus', $event)"
|
|
81
87
|
>
|
|
@@ -84,6 +90,7 @@ if (process.env.NODE_ENV !== 'production') {
|
|
|
84
90
|
:ref="forwardRef"
|
|
85
91
|
:as="as"
|
|
86
92
|
:as-child="asChild"
|
|
93
|
+
:present="props.present"
|
|
87
94
|
:disable-outside-pointer-events="disableOutsidePointerEvents"
|
|
88
95
|
role="dialog"
|
|
89
96
|
:aria-describedby="rootContext.descriptionId"
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { DialogContentImplEmits, DialogContentImplProps } from './DialogContentImpl.vue';
|
|
3
|
+
import { computed, watch } from 'vue';
|
|
3
4
|
import { useEmitAsProps, useForwardExpose, useHideOthers } from '@/shared';
|
|
4
5
|
import DialogContentImpl from './DialogContentImpl.vue';
|
|
5
6
|
import { injectDialogRootContext } from './DialogRoot.vue';
|
|
6
7
|
|
|
7
8
|
const props = withDefaults(
|
|
8
|
-
defineProps<DialogContentImplProps>(),
|
|
9
|
+
defineProps<DialogContentImplProps & { present: boolean }>(),
|
|
9
10
|
{
|
|
10
11
|
disableOutsidePointerEvents: true,
|
|
11
12
|
},
|
|
@@ -17,13 +18,30 @@ const rootContext = injectDialogRootContext();
|
|
|
17
18
|
const emitsAsProps = useEmitAsProps(emits);
|
|
18
19
|
|
|
19
20
|
const { forwardRef, currentElement } = useForwardExpose();
|
|
20
|
-
|
|
21
|
+
|
|
22
|
+
const ariaHiddenTarget = computed(() => props.present ? currentElement.value : undefined);
|
|
23
|
+
useHideOthers(ariaHiddenTarget);
|
|
24
|
+
|
|
25
|
+
const forwardedProps = computed(() => {
|
|
26
|
+
const { present: _, ...rest } = props;
|
|
27
|
+
return rest;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// When `unmountOnHide` is `false` the content stays mounted on close, so
|
|
31
|
+
// `FocusScope` never unmounts and `close-auto-focus` never fires. Restore
|
|
32
|
+
// focus to the trigger manually once the content is no longer present.
|
|
33
|
+
watch(() => props.present, (isPresent, wasPresent) => {
|
|
34
|
+
if (!isPresent && wasPresent) {
|
|
35
|
+
rootContext.triggerElement.value?.focus();
|
|
36
|
+
}
|
|
37
|
+
});
|
|
21
38
|
</script>
|
|
22
39
|
|
|
23
40
|
<template>
|
|
24
41
|
<DialogContentImpl
|
|
25
|
-
v-bind="{ ...
|
|
42
|
+
v-bind="{ ...forwardedProps, ...emitsAsProps }"
|
|
26
43
|
:ref="forwardRef"
|
|
44
|
+
:present="props.present"
|
|
27
45
|
:trap-focus="rootContext.open.value"
|
|
28
46
|
:disable-outside-pointer-events="props.disableOutsidePointerEvents"
|
|
29
47
|
@close-auto-focus="
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { DialogContentImplEmits, DialogContentImplProps } from './DialogContentImpl.vue';
|
|
3
|
-
import { ref } from 'vue';
|
|
3
|
+
import { computed, ref, watch } from 'vue';
|
|
4
4
|
import { useEmitAsProps, useForwardExpose } from '@/shared';
|
|
5
5
|
import DialogContentImpl from './DialogContentImpl.vue';
|
|
6
6
|
import { injectDialogRootContext } from './DialogRoot.vue';
|
|
7
7
|
|
|
8
|
-
const props = defineProps<DialogContentImplProps>();
|
|
8
|
+
const props = defineProps<DialogContentImplProps & { present: boolean }>();
|
|
9
9
|
const emits = defineEmits<DialogContentImplEmits>();
|
|
10
10
|
|
|
11
11
|
const emitsAsProps = useEmitAsProps(emits);
|
|
@@ -14,11 +14,30 @@ useForwardExpose();
|
|
|
14
14
|
const rootContext = injectDialogRootContext();
|
|
15
15
|
const hasInteractedOutsideRef = ref(false);
|
|
16
16
|
const hasPointerDownOutsideRef = ref(false);
|
|
17
|
+
|
|
18
|
+
const forwardedProps = computed(() => {
|
|
19
|
+
const { present: _, ...rest } = props;
|
|
20
|
+
return rest;
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// When `unmountOnHide` is `false` the content stays mounted on close, so
|
|
24
|
+
// `close-auto-focus` never fires. Restore focus to the trigger manually once
|
|
25
|
+
// the content is no longer present, unless the user interacted outside.
|
|
26
|
+
watch(() => props.present, (isPresent, wasPresent) => {
|
|
27
|
+
if (!isPresent && wasPresent) {
|
|
28
|
+
if (!hasInteractedOutsideRef.value) {
|
|
29
|
+
rootContext.triggerElement.value?.focus();
|
|
30
|
+
}
|
|
31
|
+
hasInteractedOutsideRef.value = false;
|
|
32
|
+
hasPointerDownOutsideRef.value = false;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
17
35
|
</script>
|
|
18
36
|
|
|
19
37
|
<template>
|
|
20
38
|
<DialogContentImpl
|
|
21
|
-
v-bind="{ ...
|
|
39
|
+
v-bind="{ ...forwardedProps, ...emitsAsProps }"
|
|
40
|
+
:present="present"
|
|
22
41
|
:trap-focus="false"
|
|
23
42
|
:disable-outside-pointer-events="false"
|
|
24
43
|
@close-auto-focus="
|
|
@@ -25,13 +25,17 @@ const { forwardRef } = useForwardExpose();
|
|
|
25
25
|
<template>
|
|
26
26
|
<Presence
|
|
27
27
|
v-if="rootContext?.modal.value"
|
|
28
|
+
v-slot="{ present }"
|
|
28
29
|
:present="forceMount || rootContext.open.value"
|
|
30
|
+
:force-mount="forceMount || !rootContext.unmountOnHide.value"
|
|
29
31
|
>
|
|
30
32
|
<DialogOverlayImpl
|
|
33
|
+
v-show="rootContext.unmountOnHide.value || present"
|
|
31
34
|
v-bind="$attrs"
|
|
32
35
|
:ref="forwardRef"
|
|
33
36
|
:as="as"
|
|
34
37
|
:as-child="asChild"
|
|
38
|
+
:present="rootContext.unmountOnHide.value || present"
|
|
35
39
|
>
|
|
36
40
|
<slot />
|
|
37
41
|
</DialogOverlayImpl>
|
|
@@ -5,15 +5,21 @@ export interface DialogOverlayImplProps extends PrimitiveProps {}
|
|
|
5
5
|
</script>
|
|
6
6
|
|
|
7
7
|
<script setup lang="ts">
|
|
8
|
+
import { watch } from 'vue';
|
|
8
9
|
import { Primitive } from '@/Primitive';
|
|
9
10
|
import { useForwardExpose } from '@/shared';
|
|
10
11
|
import { useBodyScrollLock } from '@/shared/useBodyScrollLock';
|
|
11
12
|
import { injectDialogRootContext } from './DialogRoot.vue';
|
|
12
13
|
|
|
13
|
-
defineProps<DialogOverlayImplProps>()
|
|
14
|
+
const props = withDefaults(defineProps<DialogOverlayImplProps & { present?: boolean }>(), {
|
|
15
|
+
present: true,
|
|
16
|
+
});
|
|
14
17
|
const rootContext = injectDialogRootContext();
|
|
15
18
|
|
|
16
|
-
useBodyScrollLock(
|
|
19
|
+
const scrollLocked = useBodyScrollLock(props.present);
|
|
20
|
+
watch(() => props.present, (val) => {
|
|
21
|
+
scrollLocked.value = val;
|
|
22
|
+
});
|
|
17
23
|
useForwardExpose();
|
|
18
24
|
</script>
|
|
19
25
|
|
|
@@ -12,6 +12,12 @@ export interface DialogRootProps {
|
|
|
12
12
|
* interaction with outside elements will be disabled and only dialog content will be visible to screen readers.
|
|
13
13
|
*/
|
|
14
14
|
modal?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* When set to `false`, the dialog content will not be unmounted when closed, but instead hidden with CSS. <br>
|
|
17
|
+
* Useful for SEO or when you want to improve performance by not remounting the component on every open.
|
|
18
|
+
* @defaultValue true
|
|
19
|
+
*/
|
|
20
|
+
unmountOnHide?: boolean;
|
|
15
21
|
}
|
|
16
22
|
|
|
17
23
|
export type DialogRootEmits = {
|
|
@@ -22,6 +28,7 @@ export type DialogRootEmits = {
|
|
|
22
28
|
export interface DialogRootContext {
|
|
23
29
|
open: Readonly<Ref<boolean>>;
|
|
24
30
|
modal: Ref<boolean>;
|
|
31
|
+
unmountOnHide: Ref<boolean>;
|
|
25
32
|
openModal: () => void;
|
|
26
33
|
onOpenChange: (value: boolean) => void;
|
|
27
34
|
onOpenToggle: () => void;
|
|
@@ -48,6 +55,7 @@ const props = withDefaults(defineProps<DialogRootProps>(), {
|
|
|
48
55
|
open: undefined,
|
|
49
56
|
defaultOpen: false,
|
|
50
57
|
modal: true,
|
|
58
|
+
unmountOnHide: true,
|
|
51
59
|
});
|
|
52
60
|
const emit = defineEmits<DialogRootEmits>();
|
|
53
61
|
|
|
@@ -67,11 +75,12 @@ const open = useVModel(props, 'open', emit, {
|
|
|
67
75
|
|
|
68
76
|
const triggerElement = ref<HTMLElement>();
|
|
69
77
|
const contentElement = ref<HTMLElement>();
|
|
70
|
-
const { modal } = toRefs(props);
|
|
78
|
+
const { modal, unmountOnHide } = toRefs(props);
|
|
71
79
|
|
|
72
80
|
provideDialogRootContext({
|
|
73
81
|
open,
|
|
74
82
|
modal,
|
|
83
|
+
unmountOnHide,
|
|
75
84
|
openModal: () => {
|
|
76
85
|
open.value = true;
|
|
77
86
|
},
|
|
@@ -72,8 +72,19 @@ import {
|
|
|
72
72
|
usePointerDownOutside,
|
|
73
73
|
} from './utils';
|
|
74
74
|
|
|
75
|
-
const props = withDefaults(defineProps<DismissableLayerProps
|
|
75
|
+
const props = withDefaults(defineProps<DismissableLayerProps & {
|
|
76
|
+
/**
|
|
77
|
+
* Whether the layer is currently active. A layer that stays mounted while
|
|
78
|
+
* hidden (e.g. a Dialog with `unmountOnHide: false`) must opt out of the
|
|
79
|
+
* layer stack, otherwise it would be treated as the topmost layer and
|
|
80
|
+
* swallow Escape / outside interactions meant for the visible one.
|
|
81
|
+
* Kept out of the public `DismissableLayerProps` on purpose — it is
|
|
82
|
+
* internal plumbing between primitives.
|
|
83
|
+
*/
|
|
84
|
+
present?: boolean;
|
|
85
|
+
}>(), {
|
|
76
86
|
disableOutsidePointerEvents: false,
|
|
87
|
+
present: true,
|
|
77
88
|
});
|
|
78
89
|
|
|
79
90
|
const emits = defineEmits<DismissableLayerPrivateEmits>();
|
|
@@ -108,7 +119,7 @@ const pointerDownOutside = usePointerDownOutside(async (event) => {
|
|
|
108
119
|
branch?.contains(event.target as HTMLElement),
|
|
109
120
|
);
|
|
110
121
|
|
|
111
|
-
if (!isPointerEventsEnabled.value || isPointerDownOnBranch) {
|
|
122
|
+
if (!props.present || !isPointerEventsEnabled.value || isPointerDownOnBranch) {
|
|
112
123
|
return;
|
|
113
124
|
}
|
|
114
125
|
emits('pointerDownOutside', event);
|
|
@@ -124,7 +135,7 @@ const focusOutside = useFocusOutside((event) => {
|
|
|
124
135
|
branch?.contains(event.target as HTMLElement),
|
|
125
136
|
);
|
|
126
137
|
|
|
127
|
-
if (isFocusInBranch) {
|
|
138
|
+
if (!props.present || isFocusInBranch) {
|
|
128
139
|
return;
|
|
129
140
|
}
|
|
130
141
|
emits('focusOutside', event);
|
|
@@ -135,6 +146,13 @@ const focusOutside = useFocusOutside((event) => {
|
|
|
135
146
|
}, layerElement);
|
|
136
147
|
|
|
137
148
|
onKeyStroke('Escape', (event) => {
|
|
149
|
+
// A layer that stays mounted while hidden (e.g. a Dialog with
|
|
150
|
+
// `unmountOnHide: false`) is out of the layer stack, so its `index` is `-1`.
|
|
151
|
+
// When no layer is visible (`size === 0`), `-1 === size - 1` would otherwise
|
|
152
|
+
// make it look like the highest layer and emit `escapeKeyDown` / `dismiss`.
|
|
153
|
+
if (!props.present) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
138
156
|
const isHighestLayer = index.value === layers.value.size - 1;
|
|
139
157
|
if (!isHighestLayer) {
|
|
140
158
|
return;
|
|
@@ -150,11 +168,11 @@ onKeyStroke('Escape', (event) => {
|
|
|
150
168
|
// Reading `context.layersWithOutsidePointerEventsDisabled.size` inside the
|
|
151
169
|
// callback must NOT make it reactive: otherwise adding/removing any other
|
|
152
170
|
// layer would re-run this effect and its cleanup could prematurely restore the
|
|
153
|
-
// body's `pointer-events` while an ancestor layer is still open.
|
|
171
|
+
// body's `pointer-events` while an ancestor layer is still open (#2674).
|
|
154
172
|
watch(
|
|
155
|
-
[layerElement, () => props.disableOutsidePointerEvents],
|
|
156
|
-
([element, disableOutsidePointerEvents], _, onCleanup) => {
|
|
157
|
-
if (!element) {
|
|
173
|
+
[layerElement, () => props.disableOutsidePointerEvents, () => props.present],
|
|
174
|
+
([element, disableOutsidePointerEvents, present], _, onCleanup) => {
|
|
175
|
+
if (!element || !present) {
|
|
158
176
|
return;
|
|
159
177
|
}
|
|
160
178
|
if (disableOutsidePointerEvents) {
|
|
@@ -170,7 +188,7 @@ watch(
|
|
|
170
188
|
// the unmount-only effect below — keeps the set accurate when
|
|
171
189
|
// `disableOutsidePointerEvents` toggles `true -> false` while still
|
|
172
190
|
// mounted (e.g. a modal Menu closing). Checking `size === 0` *after*
|
|
173
|
-
// deletion makes the restore independent of cleanup ordering.
|
|
191
|
+
// deletion makes the restore independent of cleanup ordering (#2674).
|
|
174
192
|
onCleanup(() => {
|
|
175
193
|
context.layersWithOutsidePointerEventsDisabled.delete(element);
|
|
176
194
|
if (
|
|
@@ -181,7 +199,25 @@ watch(
|
|
|
181
199
|
}
|
|
182
200
|
});
|
|
183
201
|
}
|
|
202
|
+
},
|
|
203
|
+
{ immediate: true },
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
// Membership in the layer stack follows presence, not mount: a hidden layer
|
|
207
|
+
// (e.g. a closed Dialog with `unmountOnHide: false`) must leave the stack so
|
|
208
|
+
// Escape and outside interactions target the layer that is actually visible.
|
|
209
|
+
// Kept separate from the pointer-events watch above so a
|
|
210
|
+
// `disableOutsidePointerEvents` toggle alone never re-orders the stack.
|
|
211
|
+
watch(
|
|
212
|
+
[layerElement, () => props.present],
|
|
213
|
+
([element, present], _, onCleanup) => {
|
|
214
|
+
if (!element || !present) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
184
217
|
layers.value.add(element);
|
|
218
|
+
onCleanup(() => {
|
|
219
|
+
layers.value.delete(element);
|
|
220
|
+
});
|
|
185
221
|
},
|
|
186
222
|
{ immediate: true },
|
|
187
223
|
);
|
|
@@ -30,12 +30,22 @@ export interface FocusScopeProps extends PrimitiveProps {
|
|
|
30
30
|
* @defaultValue false
|
|
31
31
|
*/
|
|
32
32
|
trapped?: boolean;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Whether the scope is currently visible. Lets a consumer keep the scope
|
|
36
|
+
* mounted but hidden (e.g. `display: none`) and still get correct auto-focus:
|
|
37
|
+
* the mount auto-focus is skipped while not present, and re-runs when it
|
|
38
|
+
* becomes present again. Defaults to `true` so consumers that mount the scope
|
|
39
|
+
* only while visible are unaffected.
|
|
40
|
+
* @defaultValue true
|
|
41
|
+
*/
|
|
42
|
+
present?: boolean;
|
|
33
43
|
}
|
|
34
44
|
</script>
|
|
35
45
|
|
|
36
46
|
<script setup lang="ts">
|
|
37
47
|
import { isClient } from '@vueuse/shared';
|
|
38
|
-
import { nextTick, reactive, ref, watchEffect } from 'vue';
|
|
48
|
+
import { nextTick, reactive, ref, watch, watchEffect } from 'vue';
|
|
39
49
|
import { Primitive } from '@/Primitive';
|
|
40
50
|
import { createFocusScopesStack } from './stack';
|
|
41
51
|
import {
|
|
@@ -48,10 +58,20 @@ import {
|
|
|
48
58
|
getTabbableEdges,
|
|
49
59
|
} from './utils';
|
|
50
60
|
|
|
51
|
-
const props = withDefaults(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
61
|
+
const props = withDefaults(
|
|
62
|
+
defineProps<FocusScopeProps>(),
|
|
63
|
+
{
|
|
64
|
+
loop: false,
|
|
65
|
+
trapped: false,
|
|
66
|
+
// `present` MUST default to `true`. It is typed `boolean`, so Vue's boolean
|
|
67
|
+
// prop casting would otherwise coerce an absent prop to `false` (not
|
|
68
|
+
// `undefined`), and the `props.present !== false` gates below would then skip
|
|
69
|
+
// adding the scope to the stack for every consumer that doesn't pass `present`
|
|
70
|
+
// (e.g. Combobox/Select content). That scope would never pause an ancestor
|
|
71
|
+
// trap, so a Combobox input inside a Dialog could not be focused (#2749).
|
|
72
|
+
present: true,
|
|
73
|
+
},
|
|
74
|
+
);
|
|
55
75
|
const emits = defineEmits<FocusScopeEmits>();
|
|
56
76
|
|
|
57
77
|
const { currentRef, currentElement } = useForwardExpose();
|
|
@@ -157,6 +177,25 @@ watchEffect((cleanupFn) => {
|
|
|
157
177
|
});
|
|
158
178
|
});
|
|
159
179
|
|
|
180
|
+
// Dispatch the mount auto-focus event and move focus to the first tabbable
|
|
181
|
+
// candidate (or the container as a fallback). Shared by the physical-mount path
|
|
182
|
+
// and the visibility path below so both behave identically. Consumers (e.g.
|
|
183
|
+
// Dialog's `openAutoFocus`) may `preventDefault()` to opt out of default focus.
|
|
184
|
+
function dispatchMountAutoFocus(container: HTMLElement, previouslyFocusedElement: HTMLElement | null) {
|
|
185
|
+
const mountEvent = new CustomEvent(AUTOFOCUS_ON_MOUNT, EVENT_OPTIONS);
|
|
186
|
+
const handleMountAutoFocus = (ev: Event) => emits('mountAutoFocus', ev);
|
|
187
|
+
container.addEventListener(AUTOFOCUS_ON_MOUNT, handleMountAutoFocus);
|
|
188
|
+
container.dispatchEvent(mountEvent);
|
|
189
|
+
container.removeEventListener(AUTOFOCUS_ON_MOUNT, handleMountAutoFocus);
|
|
190
|
+
|
|
191
|
+
if (!mountEvent.defaultPrevented) {
|
|
192
|
+
focusFirst(getTabbableCandidates(container), { select: true });
|
|
193
|
+
if (getActiveElement() === previouslyFocusedElement) {
|
|
194
|
+
focus(container);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
160
199
|
watchEffect(async (cleanupFn) => {
|
|
161
200
|
const container = currentElement.value;
|
|
162
201
|
|
|
@@ -164,30 +203,29 @@ watchEffect(async (cleanupFn) => {
|
|
|
164
203
|
if (!container) {
|
|
165
204
|
return;
|
|
166
205
|
}
|
|
167
|
-
|
|
206
|
+
// A scope that mounts hidden (`present: false`, e.g. a closed Dialog with
|
|
207
|
+
// `unmountOnHide: false`) must stay out of the scope stack: adding it would
|
|
208
|
+
// pause the currently active scope and break its focus trap. The `present`
|
|
209
|
+
// watcher below adds/removes it as it becomes visible.
|
|
210
|
+
if (props.present !== false) {
|
|
211
|
+
focusScopesStack.add(focusScope);
|
|
212
|
+
}
|
|
168
213
|
const previouslyFocusedElement = getActiveElement() as HTMLElement | null;
|
|
169
214
|
const hasFocusedCandidate = container.contains(previouslyFocusedElement);
|
|
170
215
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if (getActiveElement() === previouslyFocusedElement) {
|
|
182
|
-
focus(container);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
216
|
+
// When force-mounted while closed (e.g. Dialog `unmountOnHide: false`), the
|
|
217
|
+
// consumer keeps the scope mounted but flags it as not present. Skip the
|
|
218
|
+
// mount auto-focus in that case, otherwise it fires `mountAutoFocus` and
|
|
219
|
+
// steals focus into a hidden scope. The `present` watcher below re-runs the
|
|
220
|
+
// auto-focus once the scope becomes present again.
|
|
221
|
+
// NOTE: `props.present` must stay read *after* the `await` above so this
|
|
222
|
+
// effect does not track it — re-running on `present` changes would dispatch
|
|
223
|
+
// the unmount auto-focus cleanup below on every close.
|
|
224
|
+
if (!hasFocusedCandidate && props.present !== false) {
|
|
225
|
+
dispatchMountAutoFocus(container, previouslyFocusedElement);
|
|
185
226
|
}
|
|
186
227
|
|
|
187
228
|
cleanupFn(() => {
|
|
188
|
-
container.removeEventListener(AUTOFOCUS_ON_MOUNT, (ev: Event) =>
|
|
189
|
-
emits('mountAutoFocus', ev));
|
|
190
|
-
|
|
191
229
|
const unmountEvent = new CustomEvent(AUTOFOCUS_ON_UNMOUNT, EVENT_OPTIONS);
|
|
192
230
|
const unmountEventHandler = (ev: Event) => {
|
|
193
231
|
emits('unmountAutoFocus', ev);
|
|
@@ -208,12 +246,47 @@ watchEffect(async (cleanupFn) => {
|
|
|
208
246
|
container.removeEventListener(AUTOFOCUS_ON_UNMOUNT, unmountEventHandler);
|
|
209
247
|
|
|
210
248
|
focusScopesStack.remove(focusScope);
|
|
211
|
-
|
|
212
249
|
container.removeAttribute('data-focus-scope-unmounting');
|
|
213
250
|
}, 0);
|
|
214
251
|
});
|
|
215
252
|
});
|
|
216
253
|
|
|
254
|
+
// Force-mounted scopes (e.g. Dialog `unmountOnHide: false`) stay mounted across
|
|
255
|
+
// open/close and toggle `present` instead of unmounting, so mount/unmount-keyed
|
|
256
|
+
// behavior must be re-keyed on `present`: stack membership (which pauses other
|
|
257
|
+
// scopes' traps) and the mount auto-focus (which only fires on physical mount).
|
|
258
|
+
// Awaiting `nextTick` lets the consumer's visibility change (e.g. `v-show`)
|
|
259
|
+
// apply first, so the focus targets exist. Consumers that don't pass `present`
|
|
260
|
+
// default it to `true` (see `withDefaults`); since it never changes for them,
|
|
261
|
+
// this watcher never fires and the main effect above owns their stack membership.
|
|
262
|
+
watch(() => props.present, async (present, prevPresent) => {
|
|
263
|
+
if (!isClient) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
if (present === false && prevPresent === true) {
|
|
268
|
+
focusScopesStack.remove(focusScope);
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
if (present !== true || prevPresent !== false) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
focusScopesStack.add(focusScope);
|
|
277
|
+
|
|
278
|
+
await nextTick();
|
|
279
|
+
const container = currentElement.value;
|
|
280
|
+
if (!container) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const previouslyFocusedElement = getActiveElement() as HTMLElement | null;
|
|
285
|
+
if (!container.contains(previouslyFocusedElement)) {
|
|
286
|
+
dispatchMountAutoFocus(container, previouslyFocusedElement);
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
|
|
217
290
|
function handleKeyDown(event: KeyboardEvent) {
|
|
218
291
|
if (!props.loop && !props.trapped) {
|
|
219
292
|
return;
|
|
@@ -188,6 +188,12 @@ function highlightItem(value: T) {
|
|
|
188
188
|
|
|
189
189
|
function onKeydownEnter(event: KeyboardEvent) {
|
|
190
190
|
if (highlightedElement.value && highlightedElement.value.isConnected) {
|
|
191
|
+
// Modifier combos (e.g. Ctrl+Enter) are not handled here —
|
|
192
|
+
// let them bubble so parent listeners can react (e.g. submit a form).
|
|
193
|
+
if (event.ctrlKey || event.metaKey || event.altKey) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
|
|
191
197
|
event.preventDefault();
|
|
192
198
|
event.stopPropagation();
|
|
193
199
|
|
|
@@ -170,6 +170,13 @@ const activeSubmenuContext = ref<{ onOpenChange: (open: boolean) => void; trigge
|
|
|
170
170
|
|
|
171
171
|
watch(highlightedElement, (el) => {
|
|
172
172
|
if (activeSubmenuContext.value && (el === undefined || el !== activeSubmenuContext.value.trigger.value)) {
|
|
173
|
+
// Don't close the submenu when the highlight disappears (pointer left
|
|
174
|
+
// all parent items, likely because the submenu opened on top of the
|
|
175
|
+
// trigger in a constrained viewport). Only close when highlight moves
|
|
176
|
+
// to a different parent item.
|
|
177
|
+
if (el === undefined) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
173
180
|
activeSubmenuContext.value.onOpenChange(false);
|
|
174
181
|
activeSubmenuContext.value = undefined;
|
|
175
182
|
}
|
|
@@ -243,7 +250,7 @@ function handleKeyDown(event: KeyboardEvent) {
|
|
|
243
250
|
|
|
244
251
|
if (isKeyDownInside) {
|
|
245
252
|
// menus should not be navigated using tab key so we prevent it
|
|
246
|
-
if (event.key === 'Tab') {
|
|
253
|
+
if (event.key === 'Tab' && rootContext.modal.value) {
|
|
247
254
|
event.preventDefault();
|
|
248
255
|
}
|
|
249
256
|
if (!isModifierKey && isCharacterKey && !isKeyDownInTextField) {
|