akar 2.0.7 → 2.0.9
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/AutocompleteInput.cjs +12 -16
- package/dist/Autocomplete/AutocompleteInput.cjs.map +1 -1
- package/dist/Autocomplete/AutocompleteInput.js +13 -17
- package/dist/Autocomplete/AutocompleteInput.js.map +1 -1
- package/dist/ColorField/ColorFieldInput.cjs +10 -2
- package/dist/ColorField/ColorFieldInput.cjs.map +1 -1
- package/dist/ColorField/ColorFieldInput.js +10 -2
- package/dist/ColorField/ColorFieldInput.js.map +1 -1
- package/dist/Combobox/ComboboxInput.cjs +27 -9
- package/dist/Combobox/ComboboxInput.cjs.map +1 -1
- package/dist/Combobox/ComboboxInput.js +28 -10
- package/dist/Combobox/ComboboxInput.js.map +1 -1
- package/dist/DateField/DateFieldInput.cjs +4 -1
- package/dist/DateField/DateFieldInput.cjs.map +1 -1
- package/dist/DateField/DateFieldInput.js +4 -1
- package/dist/DateField/DateFieldInput.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/DatePicker/DatePickerRoot.cjs +15 -1
- package/dist/DatePicker/DatePickerRoot.cjs.map +1 -1
- package/dist/DatePicker/DatePickerRoot.js +15 -1
- package/dist/DatePicker/DatePickerRoot.js.map +1 -1
- package/dist/DateRangeField/DateRangeFieldInput.cjs +4 -1
- package/dist/DateRangeField/DateRangeFieldInput.cjs.map +1 -1
- package/dist/DateRangeField/DateRangeFieldInput.js +4 -1
- package/dist/DateRangeField/DateRangeFieldInput.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/Dialog/DialogOverlayImpl.cjs +5 -1
- package/dist/Dialog/DialogOverlayImpl.cjs.map +1 -1
- package/dist/Dialog/DialogOverlayImpl.js +5 -1
- package/dist/Dialog/DialogOverlayImpl.js.map +1 -1
- package/dist/DropdownMenu/DropdownMenuFilter.cjs +22 -3
- package/dist/DropdownMenu/DropdownMenuFilter.cjs.map +1 -1
- package/dist/DropdownMenu/DropdownMenuFilter.js +22 -3
- package/dist/DropdownMenu/DropdownMenuFilter.js.map +1 -1
- package/dist/Listbox/ListboxFilter.cjs +32 -11
- package/dist/Listbox/ListboxFilter.cjs.map +1 -1
- package/dist/Listbox/ListboxFilter.js +33 -12
- package/dist/Listbox/ListboxFilter.js.map +1 -1
- package/dist/Listbox/ListboxRoot.cjs +12 -6
- package/dist/Listbox/ListboxRoot.cjs.map +1 -1
- package/dist/Listbox/ListboxRoot.js +12 -6
- package/dist/Listbox/ListboxRoot.js.map +1 -1
- package/dist/NavigationMenu/NavigationMenuRoot.cjs +16 -3
- package/dist/NavigationMenu/NavigationMenuRoot.cjs.map +1 -1
- package/dist/NavigationMenu/NavigationMenuRoot.js +16 -3
- package/dist/NavigationMenu/NavigationMenuRoot.js.map +1 -1
- package/dist/NumberField/NumberFieldInput.cjs +44 -13
- package/dist/NumberField/NumberFieldInput.cjs.map +1 -1
- package/dist/NumberField/NumberFieldInput.js +45 -14
- package/dist/NumberField/NumberFieldInput.js.map +1 -1
- package/dist/PinInput/PinInputInput.cjs +37 -2
- package/dist/PinInput/PinInputInput.cjs.map +1 -1
- package/dist/PinInput/PinInputInput.js +37 -2
- package/dist/PinInput/PinInputInput.js.map +1 -1
- package/dist/ScrollArea/ScrollAreaScrollbarX.cjs +3 -0
- package/dist/ScrollArea/ScrollAreaScrollbarX.cjs.map +1 -1
- package/dist/ScrollArea/ScrollAreaScrollbarX.js +4 -1
- package/dist/ScrollArea/ScrollAreaScrollbarX.js.map +1 -1
- package/dist/ScrollArea/ScrollAreaScrollbarY.cjs +3 -0
- package/dist/ScrollArea/ScrollAreaScrollbarY.cjs.map +1 -1
- package/dist/ScrollArea/ScrollAreaScrollbarY.js +4 -1
- package/dist/ScrollArea/ScrollAreaScrollbarY.js.map +1 -1
- package/dist/TagsInput/TagsInputInput.cjs +12 -13
- package/dist/TagsInput/TagsInputInput.cjs.map +1 -1
- package/dist/TagsInput/TagsInputInput.js +13 -14
- package/dist/TagsInput/TagsInputInput.js.map +1 -1
- package/dist/TagsInput/TagsInputRoot.cjs +1 -0
- package/dist/TagsInput/TagsInputRoot.cjs.map +1 -1
- package/dist/TagsInput/TagsInputRoot.js +1 -0
- package/dist/TagsInput/TagsInputRoot.js.map +1 -1
- package/dist/TimeField/TimeFieldInput.cjs +4 -1
- package/dist/TimeField/TimeFieldInput.cjs.map +1 -1
- package/dist/TimeField/TimeFieldInput.js +4 -1
- package/dist/TimeField/TimeFieldInput.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/TimeRangeFieldInput.cjs +4 -1
- package/dist/TimeRangeField/TimeRangeFieldInput.cjs.map +1 -1
- package/dist/TimeRangeField/TimeRangeFieldInput.js +4 -1
- package/dist/TimeRangeField/TimeRangeFieldInput.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/constant.d.cts.map +1 -1
- package/dist/date/useDateField.cjs +38 -0
- package/dist/date/useDateField.cjs.map +1 -1
- package/dist/date/useDateField.js +38 -0
- package/dist/date/useDateField.js.map +1 -1
- package/dist/index.cjs +1 -0
- package/dist/index.js +1 -0
- package/dist/index2.d.ts.map +1 -1
- package/dist/index3.d.cts +24 -16
- package/dist/index3.d.cts.map +1 -1
- package/dist/index3.d.ts +9 -1
- package/dist/index3.d.ts.map +1 -1
- package/dist/index4.d.cts +634 -634
- package/dist/index4.d.cts.map +1 -1
- package/dist/index4.d.ts +638 -638
- package/dist/index4.d.ts.map +1 -1
- package/dist/internal.cjs +1 -0
- package/dist/internal.d.cts +2 -2
- package/dist/internal.d.cts.map +1 -1
- package/dist/internal.d.ts +2 -2
- package/dist/internal.js +1 -0
- package/dist/shared/useComposing.cjs +30 -0
- package/dist/shared/useComposing.cjs.map +1 -0
- package/dist/shared/useComposing.js +24 -0
- package/dist/shared/useComposing.js.map +1 -0
- 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 +3 -3
- package/src/Autocomplete/AutocompleteInput.vue +14 -18
- package/src/ColorField/ColorFieldInput.vue +16 -1
- package/src/Combobox/ComboboxInput.vue +46 -10
- package/src/DateField/DateFieldInput.vue +6 -0
- package/src/DateField/DateFieldRoot.vue +5 -0
- package/src/DatePicker/DatePickerRoot.vue +18 -2
- package/src/DateRangeField/DateRangeFieldInput.vue +6 -0
- package/src/DateRangeField/DateRangeFieldRoot.vue +5 -0
- package/src/Dialog/DialogOverlayImpl.vue +1 -1
- package/src/DropdownMenu/DropdownMenuFilter.vue +37 -11
- package/src/Listbox/ListboxFilter.vue +51 -14
- package/src/Listbox/ListboxRoot.vue +20 -4
- package/src/NavigationMenu/NavigationMenuRoot.vue +21 -4
- package/src/NumberField/NumberFieldInput.vue +46 -8
- package/src/PinInput/PinInputInput.vue +50 -1
- package/src/ScrollArea/ScrollAreaScrollbarX.vue +8 -1
- package/src/ScrollArea/ScrollAreaScrollbarY.vue +7 -1
- package/src/TagsInput/TagsInputInput.vue +19 -14
- package/src/TagsInput/TagsInputRoot.vue +5 -0
- package/src/TimeField/TimeFieldInput.vue +6 -0
- package/src/TimeField/TimeFieldRoot.vue +5 -0
- package/src/TimeRangeField/TimeRangeFieldInput.vue +6 -0
- package/src/TimeRangeField/TimeRangeFieldRoot.vue +5 -0
- package/src/shared/date/useDateField.ts +81 -1
- package/src/shared/index.ts +1 -0
- package/src/shared/useComposing.ts +18 -0
- package/src/test/utils.ts +0 -2
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { PrimitiveProps } from '..';
|
|
3
|
-
import { useVModel } from '@vueuse/core';
|
|
4
|
-
import { computed, onMounted, onUnmounted, ref, watchSyncEffect } from 'vue';
|
|
5
|
-
import { usePrimitiveElement } from '@/Primitive';
|
|
6
|
-
import { Primitive } from '..';
|
|
7
|
-
import { injectListboxRootContext } from './ListboxRoot.vue';
|
|
8
3
|
|
|
9
4
|
export interface ListboxFilterProps extends PrimitiveProps {
|
|
10
5
|
/** The controlled value of the filter. Can be binded with v-model. */
|
|
@@ -21,6 +16,13 @@ export type ListboxFilterEmits = {
|
|
|
21
16
|
</script>
|
|
22
17
|
|
|
23
18
|
<script setup lang="ts">
|
|
19
|
+
import { useVModel } from '@vueuse/core';
|
|
20
|
+
import { computed, onMounted, onUnmounted, ref, watchSyncEffect } from 'vue';
|
|
21
|
+
import { usePrimitiveElement } from '@/Primitive';
|
|
22
|
+
import { useComposing } from '@/shared';
|
|
23
|
+
import { Primitive } from '..';
|
|
24
|
+
import { injectListboxRootContext } from './ListboxRoot.vue';
|
|
25
|
+
|
|
24
26
|
const props = withDefaults(defineProps<ListboxFilterProps>(), {
|
|
25
27
|
as: 'input',
|
|
26
28
|
});
|
|
@@ -44,7 +46,9 @@ const { primitiveElement, currentElement } = usePrimitiveElement();
|
|
|
44
46
|
const disabled = computed(() => props.disabled || rootContext.disabled.value || false);
|
|
45
47
|
|
|
46
48
|
const activedescendant = ref<string | undefined>();
|
|
47
|
-
watchSyncEffect(() =>
|
|
49
|
+
watchSyncEffect(() => {
|
|
50
|
+
activedescendant.value = rootContext.highlightedElement.value?.id;
|
|
51
|
+
});
|
|
48
52
|
|
|
49
53
|
onMounted(() => {
|
|
50
54
|
rootContext.focusable.value = false;
|
|
@@ -60,6 +64,42 @@ onMounted(() => {
|
|
|
60
64
|
onUnmounted(() => {
|
|
61
65
|
rootContext.focusable.value = true;
|
|
62
66
|
});
|
|
67
|
+
|
|
68
|
+
const { isComposing, handleCompositionStart, handleCompositionEnd } = useComposing((event) => {
|
|
69
|
+
modelValue.value = (event.target as HTMLInputElement).value;
|
|
70
|
+
rootContext.onCompositionEnd();
|
|
71
|
+
rootContext.highlightFirstItem();
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
function onCompositionStart() {
|
|
75
|
+
rootContext.onCompositionStart();
|
|
76
|
+
handleCompositionStart();
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function handleInput(event: InputEvent) {
|
|
80
|
+
if (isComposing.value) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
modelValue.value = (event.target as HTMLInputElement).value;
|
|
84
|
+
rootContext.highlightFirstItem();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function handleKeydownNavigation(event: KeyboardEvent) {
|
|
88
|
+
// Don't navigate mid-composition, arrow keys are used for IME candidate navigation
|
|
89
|
+
if (isComposing.value) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
event.preventDefault();
|
|
93
|
+
rootContext.onKeydownNavigation(event);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function handleKeydownEnter(event: KeyboardEvent) {
|
|
97
|
+
// Don't select mid-composition, Enter commits the IME candidate
|
|
98
|
+
if (isComposing.value) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
rootContext.onKeydownEnter(event);
|
|
102
|
+
}
|
|
63
103
|
</script>
|
|
64
104
|
|
|
65
105
|
<template>
|
|
@@ -73,14 +113,11 @@ onUnmounted(() => {
|
|
|
73
113
|
:aria-disabled="disabled ?? undefined"
|
|
74
114
|
:aria-activedescendant="activedescendant"
|
|
75
115
|
type="text"
|
|
76
|
-
@keydown.down.up.home.end
|
|
77
|
-
@keydown.enter="
|
|
78
|
-
@input="
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}"
|
|
82
|
-
@compositionstart="rootContext.onCompositionStart"
|
|
83
|
-
@compositionend="rootContext.onCompositionEnd"
|
|
116
|
+
@keydown.down.up.home.end="handleKeydownNavigation"
|
|
117
|
+
@keydown.enter="handleKeydownEnter"
|
|
118
|
+
@input="handleInput"
|
|
119
|
+
@compositionstart="onCompositionStart"
|
|
120
|
+
@compositionend="handleCompositionEnd"
|
|
84
121
|
>
|
|
85
122
|
<slot :model-value="modelValue" />
|
|
86
123
|
</Primitive>
|
|
@@ -331,7 +331,7 @@ function handleMultipleReplace(event: KeyboardEvent, targetEl: HTMLElement) {
|
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
333
|
|
|
334
|
-
async function highlightSelected(event?: Event) {
|
|
334
|
+
async function highlightSelected(event?: Event, scroll = true) {
|
|
335
335
|
// highlightSelected is called inside a watch with immediate set to true.
|
|
336
336
|
// This results in code execution during SSR.
|
|
337
337
|
// Ensure this code only runs in a browser environment, since it performs
|
|
@@ -346,19 +346,35 @@ async function highlightSelected(event?: Event) {
|
|
|
346
346
|
} else {
|
|
347
347
|
const collection = getCollectionItem();
|
|
348
348
|
const item = collection.find((i) => i.dataset.state === 'checked');
|
|
349
|
+
|
|
350
|
+
// On the initial (mount) highlight we only set the roving-tabindex target.
|
|
351
|
+
// Focusing/scrolling here would scroll the page to a Listbox the user never
|
|
352
|
+
// interacted with (e.g. one below the fold). Later highlights scroll as before.
|
|
353
|
+
const focus = scroll ? undefined : false;
|
|
354
|
+
|
|
349
355
|
if (item) {
|
|
350
|
-
changeHighlight(item);
|
|
356
|
+
changeHighlight(item, scroll, focus);
|
|
351
357
|
} else if (collection.length) {
|
|
352
|
-
changeHighlight(collection[0]);
|
|
358
|
+
changeHighlight(collection[0], scroll, focus);
|
|
353
359
|
}
|
|
354
360
|
}
|
|
355
361
|
}
|
|
356
362
|
|
|
363
|
+
// `false` until the initial (mount) modelValue highlight has been queued.
|
|
364
|
+
// Flipped synchronously in the watcher so the "is this the mount highlight?"
|
|
365
|
+
// decision never depends on nextTick ordering, which differs between a client
|
|
366
|
+
// mount and SSR hydration. The intent travels with the call as an argument
|
|
367
|
+
// rather than via a shared flag released on a later tick.
|
|
368
|
+
let hasHighlightedOnMount = false;
|
|
369
|
+
|
|
357
370
|
// watch for only programmatic changes
|
|
358
371
|
watch(modelValue, () => {
|
|
359
372
|
if (!isUserAction.value) {
|
|
373
|
+
const scroll = hasHighlightedOnMount;
|
|
374
|
+
hasHighlightedOnMount = true;
|
|
375
|
+
|
|
360
376
|
nextTick(() => {
|
|
361
|
-
highlightSelected();
|
|
377
|
+
highlightSelected(undefined, scroll);
|
|
362
378
|
});
|
|
363
379
|
}
|
|
364
380
|
}, { immediate: true, deep: true });
|
|
@@ -141,12 +141,13 @@ const { delayDuration, skipDelayDuration, dir: propDir, disableClickTrigger, dis
|
|
|
141
141
|
const dir = useDirection(propDir);
|
|
142
142
|
|
|
143
143
|
const isDelaySkipped = refAutoReset(false, skipDelayDuration);
|
|
144
|
+
const skipNextClose = ref(false);
|
|
144
145
|
const computedDelay = computed(() => {
|
|
145
146
|
const isOpen = modelValue.value !== '';
|
|
146
147
|
if (isOpen || isDelaySkipped.value) {
|
|
147
148
|
return 150;
|
|
148
|
-
}
|
|
149
|
-
|
|
149
|
+
} else {
|
|
150
|
+
// 150ms for user to switch trigger or move into content view
|
|
150
151
|
return delayDuration.value;
|
|
151
152
|
}
|
|
152
153
|
});
|
|
@@ -154,8 +155,17 @@ const computedDelay = computed(() => {
|
|
|
154
155
|
const debouncedFn = useDebounceFn((val?: string) => {
|
|
155
156
|
// passing `undefined` meant to reset the debounce timer
|
|
156
157
|
if (isString(val)) {
|
|
158
|
+
if (val === '' && skipNextClose.value) {
|
|
159
|
+
skipNextClose.value = false;
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
|
|
157
163
|
previousValue.value = modelValue.value;
|
|
158
164
|
modelValue.value = val;
|
|
165
|
+
|
|
166
|
+
if (val === '') {
|
|
167
|
+
isDelaySkipped.value = true;
|
|
168
|
+
}
|
|
159
169
|
}
|
|
160
170
|
}, computedDelay);
|
|
161
171
|
|
|
@@ -193,10 +203,16 @@ provideNavigationMenuContext({
|
|
|
193
203
|
viewport.value = val;
|
|
194
204
|
},
|
|
195
205
|
onTriggerEnter: (val) => {
|
|
196
|
-
|
|
206
|
+
if (modelValue.value !== '') {
|
|
207
|
+
skipNextClose.value = true;
|
|
208
|
+
previousValue.value = modelValue.value;
|
|
209
|
+
modelValue.value = val;
|
|
210
|
+
} else {
|
|
211
|
+
debouncedFn(val);
|
|
212
|
+
}
|
|
197
213
|
},
|
|
198
214
|
onTriggerLeave: () => {
|
|
199
|
-
|
|
215
|
+
skipNextClose.value = false;
|
|
200
216
|
debouncedFn('');
|
|
201
217
|
},
|
|
202
218
|
onContentEnter: () => {
|
|
@@ -204,6 +220,7 @@ provideNavigationMenuContext({
|
|
|
204
220
|
},
|
|
205
221
|
onContentLeave: () => {
|
|
206
222
|
if (!props.disablePointerLeaveClose) {
|
|
223
|
+
skipNextClose.value = false;
|
|
207
224
|
debouncedFn('');
|
|
208
225
|
}
|
|
209
226
|
},
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { PrimitiveProps } from '@/Primitive';
|
|
3
3
|
import { onMounted, ref, watch } from 'vue';
|
|
4
|
-
import { getActiveElement } from '@/shared';
|
|
5
4
|
import { injectNumberFieldRootContext } from './NumberFieldRoot.vue';
|
|
6
5
|
|
|
7
6
|
export interface NumberFieldInputProps extends PrimitiveProps {
|
|
@@ -9,7 +8,9 @@ export interface NumberFieldInputProps extends PrimitiveProps {
|
|
|
9
8
|
</script>
|
|
10
9
|
|
|
11
10
|
<script setup lang="ts">
|
|
11
|
+
import { KEY_CODES } from '@vinicunca/perkakas';
|
|
12
12
|
import { Primitive, usePrimitiveElement } from '@/Primitive';
|
|
13
|
+
import { getActiveElement, useComposing } from '@/shared';
|
|
13
14
|
|
|
14
15
|
const props = withDefaults(defineProps<NumberFieldInputProps>(), {
|
|
15
16
|
as: 'input',
|
|
@@ -18,6 +19,47 @@ const props = withDefaults(defineProps<NumberFieldInputProps>(), {
|
|
|
18
19
|
const { primitiveElement, currentElement } = usePrimitiveElement();
|
|
19
20
|
const rootContext = injectNumberFieldRootContext();
|
|
20
21
|
|
|
22
|
+
const { isComposing, handleCompositionStart, handleCompositionEnd } = useComposing();
|
|
23
|
+
|
|
24
|
+
function handleKeydown(event: KeyboardEvent) {
|
|
25
|
+
// Don't step/apply mid-composition, keys are used for IME candidate navigation and commit.
|
|
26
|
+
// `isComposing` stays true until the tick after `compositionend`, so the commit keydown
|
|
27
|
+
// (which can report `event.isComposing === false`) is still skipped.
|
|
28
|
+
if (isComposing.value || event.isComposing) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
switch (event.key) {
|
|
33
|
+
case KEY_CODES.ARROW_UP:
|
|
34
|
+
event.preventDefault();
|
|
35
|
+
rootContext.handleIncrease();
|
|
36
|
+
break;
|
|
37
|
+
case KEY_CODES.ARROW_DOWN:
|
|
38
|
+
event.preventDefault();
|
|
39
|
+
rootContext.handleDecrease();
|
|
40
|
+
break;
|
|
41
|
+
case KEY_CODES.PAGE_UP:
|
|
42
|
+
event.preventDefault();
|
|
43
|
+
rootContext.handleIncrease(10);
|
|
44
|
+
break;
|
|
45
|
+
case KEY_CODES.PAGE_DOWN:
|
|
46
|
+
event.preventDefault();
|
|
47
|
+
rootContext.handleDecrease(10);
|
|
48
|
+
break;
|
|
49
|
+
case KEY_CODES.HOME:
|
|
50
|
+
event.preventDefault();
|
|
51
|
+
rootContext.handleMinMaxValue('min');
|
|
52
|
+
break;
|
|
53
|
+
case KEY_CODES.END:
|
|
54
|
+
event.preventDefault();
|
|
55
|
+
rootContext.handleMinMaxValue('max');
|
|
56
|
+
break;
|
|
57
|
+
case KEY_CODES.ENTER:
|
|
58
|
+
rootContext.applyInputValue((event.target as HTMLInputElement)?.value);
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
21
63
|
function handleWheelEvent(event: WheelEvent) {
|
|
22
64
|
if (rootContext.disableWheelChange.value) {
|
|
23
65
|
return;
|
|
@@ -81,12 +123,7 @@ function handleChange() {
|
|
|
81
123
|
:aria-valuenow="rootContext.modelValue.value"
|
|
82
124
|
:aria-valuemin="rootContext.min.value"
|
|
83
125
|
:aria-valuemax="rootContext.max.value"
|
|
84
|
-
@keydown
|
|
85
|
-
@keydown.down.prevent="rootContext.handleDecrease()"
|
|
86
|
-
@keydown.page-up.prevent="rootContext.handleIncrease(10)"
|
|
87
|
-
@keydown.page-down.prevent="rootContext.handleDecrease(10)"
|
|
88
|
-
@keydown.home.prevent="rootContext.handleMinMaxValue('min')"
|
|
89
|
-
@keydown.end.prevent="rootContext.handleMinMaxValue('max')"
|
|
126
|
+
@keydown="handleKeydown"
|
|
90
127
|
@wheel="handleWheelEvent"
|
|
91
128
|
@beforeinput="(event: InputEvent) => {
|
|
92
129
|
const target = event.target as HTMLInputElement
|
|
@@ -104,8 +141,9 @@ function handleChange() {
|
|
|
104
141
|
inputValue = target.value
|
|
105
142
|
}"
|
|
106
143
|
@change="handleChange"
|
|
107
|
-
@keydown.enter="rootContext.applyInputValue($event.target?.value)"
|
|
108
144
|
@blur="rootContext.applyInputValue($event.target?.value)"
|
|
145
|
+
@compositionstart="handleCompositionStart"
|
|
146
|
+
@compositionend="handleCompositionEnd"
|
|
109
147
|
>
|
|
110
148
|
<slot />
|
|
111
149
|
</Primitive>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import type { PinInputContextValue } from './PinInputRoot.vue';
|
|
3
3
|
import type { PrimitiveProps } from '@/Primitive';
|
|
4
4
|
import { Primitive, usePrimitiveElement } from '@/Primitive';
|
|
5
|
-
import { getActiveElement, useArrowNavigation } from '@/shared';
|
|
5
|
+
import { getActiveElement, useArrowNavigation, useComposing } from '@/shared';
|
|
6
6
|
import { injectPinInputRootContext } from './PinInputRoot.vue';
|
|
7
7
|
|
|
8
8
|
export interface PinInputInputProps extends PrimitiveProps {
|
|
@@ -32,7 +32,49 @@ const NUMBER_REG = /^\d*$/;
|
|
|
32
32
|
const NON_NUMBER_REG = /\D/g;
|
|
33
33
|
|
|
34
34
|
const { primitiveElement, currentElement } = usePrimitiveElement();
|
|
35
|
+
|
|
36
|
+
const { isComposing, handleCompositionStart, handleCompositionEnd } = useComposing((event) => {
|
|
37
|
+
const target = event.target as HTMLInputElement;
|
|
38
|
+
const value = event.data || target.value;
|
|
39
|
+
|
|
40
|
+
if (context.isNumericMode.value) {
|
|
41
|
+
const filtered = value.replace(NON_NUMBER_REG, '');
|
|
42
|
+
if (!filtered) {
|
|
43
|
+
target.value = '';
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (filtered.length > 1) {
|
|
47
|
+
handleMultipleCharacter(filtered);
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
target.value = filtered;
|
|
51
|
+
updateModelValueAt(props.index, filtered);
|
|
52
|
+
const nextEl = inputElements.value[props.index + 1];
|
|
53
|
+
if (nextEl) {
|
|
54
|
+
nextEl.focus();
|
|
55
|
+
}
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (value.length > 1) {
|
|
60
|
+
handleMultipleCharacter(value);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
target.value = value;
|
|
65
|
+
updateModelValueAt(props.index, value);
|
|
66
|
+
|
|
67
|
+
const nextEl = inputElements.value[props.index + 1];
|
|
68
|
+
if (nextEl) {
|
|
69
|
+
nextEl.focus();
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
35
73
|
function handleInput(event: InputEvent) {
|
|
74
|
+
if (isComposing.value || event.isComposing) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
36
78
|
const target = event.target as HTMLInputElement;
|
|
37
79
|
|
|
38
80
|
if ((event.data?.length ?? 0) > 1) {
|
|
@@ -69,6 +111,10 @@ function updatePlaceholder() {
|
|
|
69
111
|
}
|
|
70
112
|
|
|
71
113
|
function handleKeydown(event: KeyboardEvent) {
|
|
114
|
+
if (isComposing.value || event.isComposing) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
72
118
|
useArrowNavigation(event, getActiveElement() as HTMLElement, undefined, {
|
|
73
119
|
itemsArray: inputElements.value,
|
|
74
120
|
focus: true,
|
|
@@ -177,6 +223,7 @@ function updateModelValueAt(index: number, value: string) {
|
|
|
177
223
|
const num = +value;
|
|
178
224
|
|
|
179
225
|
if (value === '' || isNaN(num)) {
|
|
226
|
+
// eslint-disable-next-line ts/no-dynamic-delete
|
|
180
227
|
delete tempModelValue[index];
|
|
181
228
|
} else {
|
|
182
229
|
tempModelValue[index] = num;
|
|
@@ -221,6 +268,8 @@ onUnmounted(() => {
|
|
|
221
268
|
@focus="handleFocus"
|
|
222
269
|
@blur="handleBlur"
|
|
223
270
|
@paste="handlePaste"
|
|
271
|
+
@compositionstart="handleCompositionStart"
|
|
272
|
+
@compositionend="handleCompositionEnd"
|
|
224
273
|
>
|
|
225
274
|
<slot />
|
|
226
275
|
</Primitive>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { computed, onMounted } from 'vue';
|
|
2
|
+
import { computed, onMounted, onUnmounted } from 'vue';
|
|
3
3
|
import { useForwardExpose } from '@/shared';
|
|
4
4
|
import { injectScrollAreaRootContext } from './ScrollAreaRoot.vue';
|
|
5
5
|
import ScrollAreaScrollbarImpl from './ScrollAreaScrollbarImpl.vue';
|
|
@@ -16,6 +16,13 @@ onMounted(() => {
|
|
|
16
16
|
rootContext.onScrollbarXChange(scrollbarElement.value);
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
|
+
|
|
20
|
+
// Clear the registration on unmount so consumers (e.g. ScrollAreaCorner) don't
|
|
21
|
+
// hold a stale reference once the scrollbar is removed (e.g. between hover cycles).
|
|
22
|
+
onUnmounted(() => {
|
|
23
|
+
rootContext.onScrollbarXChange(null);
|
|
24
|
+
});
|
|
25
|
+
|
|
19
26
|
const sizes = computed(() => scrollbarVisibleContext.sizes.value);
|
|
20
27
|
</script>
|
|
21
28
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { computed, onMounted } from 'vue';
|
|
2
|
+
import { computed, onMounted, onUnmounted } from 'vue';
|
|
3
3
|
import { useForwardExpose } from '@/shared';
|
|
4
4
|
import { injectScrollAreaRootContext } from './ScrollAreaRoot.vue';
|
|
5
5
|
import ScrollAreaScrollbarImpl from './ScrollAreaScrollbarImpl.vue';
|
|
@@ -17,6 +17,12 @@ onMounted(() => {
|
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
+
// Clear the registration on unmount so consumers (e.g. ScrollAreaCorner) don't
|
|
21
|
+
// hold a stale reference once the scrollbar is removed (e.g. between hover cycles).
|
|
22
|
+
onUnmounted(() => {
|
|
23
|
+
rootContext.onScrollbarYChange(null);
|
|
24
|
+
});
|
|
25
|
+
|
|
20
26
|
const sizes = computed(() => scrollbarVisibleContext.sizes.value);
|
|
21
27
|
</script>
|
|
22
28
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { PrimitiveProps } from '@/Primitive';
|
|
3
|
-
import { useForwardExpose } from '@/shared';
|
|
4
3
|
|
|
5
4
|
export interface TagsInputInputProps extends PrimitiveProps {
|
|
6
5
|
/** The placeholder character to use for empty tags input. */
|
|
@@ -13,8 +12,9 @@ export interface TagsInputInputProps extends PrimitiveProps {
|
|
|
13
12
|
</script>
|
|
14
13
|
|
|
15
14
|
<script setup lang="ts">
|
|
16
|
-
import { nextTick, onMounted
|
|
15
|
+
import { nextTick, onMounted } from 'vue';
|
|
17
16
|
import { Primitive } from '@/Primitive';
|
|
17
|
+
import { useComposing, useForwardExpose } from '@/shared';
|
|
18
18
|
import { injectTagsInputRootContext } from './TagsInputRoot.vue';
|
|
19
19
|
|
|
20
20
|
const props = withDefaults(defineProps<TagsInputInputProps>(), {
|
|
@@ -60,15 +60,7 @@ function handleTab(event: Event) {
|
|
|
60
60
|
handleCustomKeydown(event);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
const isComposing =
|
|
64
|
-
function onCompositionStart() {
|
|
65
|
-
isComposing.value = true;
|
|
66
|
-
}
|
|
67
|
-
function onCompositionEnd() {
|
|
68
|
-
nextTick(() => {
|
|
69
|
-
isComposing.value = false;
|
|
70
|
-
});
|
|
71
|
-
}
|
|
63
|
+
const { isComposing, handleCompositionStart, handleCompositionEnd } = useComposing();
|
|
72
64
|
async function handleCustomKeydown(event: Event) {
|
|
73
65
|
if (isComposing.value) {
|
|
74
66
|
return;
|
|
@@ -94,6 +86,10 @@ async function handleCustomKeydown(event: Event) {
|
|
|
94
86
|
}
|
|
95
87
|
|
|
96
88
|
function handleInput(event: InputEvent) {
|
|
89
|
+
if (isComposing.value) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
97
93
|
context.isInvalidInput.value = false;
|
|
98
94
|
if (event.data === null) {
|
|
99
95
|
return;
|
|
@@ -117,6 +113,15 @@ function handleInput(event: InputEvent) {
|
|
|
117
113
|
}
|
|
118
114
|
}
|
|
119
115
|
|
|
116
|
+
function handleInputKeydown(event: KeyboardEvent) {
|
|
117
|
+
// `isComposing` stays true until the tick after `compositionend`, so arrow/backspace
|
|
118
|
+
// tag navigation is skipped even when the commit keydown reports `event.isComposing === false`.
|
|
119
|
+
if (isComposing.value) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
context.onInputKeydown(event);
|
|
123
|
+
}
|
|
124
|
+
|
|
120
125
|
function handlePaste(event: ClipboardEvent) {
|
|
121
126
|
if (context.addOnPaste.value) {
|
|
122
127
|
event.preventDefault();
|
|
@@ -173,9 +178,9 @@ onMounted(() => {
|
|
|
173
178
|
@keydown.enter="handleCustomKeydown"
|
|
174
179
|
@keydown.tab="handleTab"
|
|
175
180
|
@blur="handleBlur"
|
|
176
|
-
@keydown="
|
|
177
|
-
@compositionstart="
|
|
178
|
-
@compositionend="
|
|
181
|
+
@keydown="handleInputKeydown"
|
|
182
|
+
@compositionstart="handleCompositionStart"
|
|
183
|
+
@compositionend="handleCompositionEnd"
|
|
179
184
|
@paste="handlePaste"
|
|
180
185
|
>
|
|
181
186
|
<slot />
|
|
@@ -156,6 +156,11 @@ provideTagsInputRootContext({
|
|
|
156
156
|
},
|
|
157
157
|
onRemoveValue: handleRemoveTag,
|
|
158
158
|
onInputKeydown: (event) => {
|
|
159
|
+
// Don't navigate/select tags mid-composition, keys are used for IME candidate navigation
|
|
160
|
+
if (event.isComposing) {
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
|
|
159
164
|
const target = event.target as HTMLInputElement;
|
|
160
165
|
const collection = getItems().map((i) => i.ref).filter((i) => i.dataset.disabled !== '');
|
|
161
166
|
if (!collection.length) {
|
|
@@ -25,6 +25,9 @@ const {
|
|
|
25
25
|
handleSegmentKeydown,
|
|
26
26
|
handleSegmentFocusOut,
|
|
27
27
|
attributes,
|
|
28
|
+
handleSegmentBeforeInput,
|
|
29
|
+
handleSegmentCompositionStart,
|
|
30
|
+
handleSegmentCompositionEnd,
|
|
28
31
|
} = useDateField({
|
|
29
32
|
hasLeftFocus,
|
|
30
33
|
lastKeyZero,
|
|
@@ -61,6 +64,9 @@ const isInvalid = computed(() => rootContext.isInvalid.value);
|
|
|
61
64
|
v-on="part !== 'literal' ? {
|
|
62
65
|
mousedown: handleSegmentClick,
|
|
63
66
|
keydown: handleSegmentKeydown,
|
|
67
|
+
beforeinput: handleSegmentBeforeInput,
|
|
68
|
+
compositionstart: handleSegmentCompositionStart,
|
|
69
|
+
compositionend: handleSegmentCompositionEnd,
|
|
64
70
|
focusout: () => {
|
|
65
71
|
hasLeftFocus = true
|
|
66
72
|
handleSegmentFocusOut()
|
|
@@ -308,6 +308,11 @@ const prevFocusableSegment = computed(() => {
|
|
|
308
308
|
});
|
|
309
309
|
|
|
310
310
|
function handleKeydown(e: KeyboardEvent) {
|
|
311
|
+
// Don't navigate between segments mid-composition, arrow keys are used for IME candidate navigation
|
|
312
|
+
if (e.isComposing) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
|
|
311
316
|
if (!isSegmentNavigationKey(e.key)) {
|
|
312
317
|
return;
|
|
313
318
|
}
|
|
@@ -27,6 +27,9 @@ const {
|
|
|
27
27
|
handleSegmentClick,
|
|
28
28
|
handleSegmentKeydown,
|
|
29
29
|
attributes,
|
|
30
|
+
handleSegmentBeforeInput,
|
|
31
|
+
handleSegmentCompositionStart,
|
|
32
|
+
handleSegmentCompositionEnd,
|
|
30
33
|
} = useDateField({
|
|
31
34
|
hasLeftFocus,
|
|
32
35
|
lastKeyZero,
|
|
@@ -63,6 +66,9 @@ const isInvalid = computed(() => rootContext.isInvalid.value);
|
|
|
63
66
|
v-on="part !== 'literal' ? {
|
|
64
67
|
mousedown: handleSegmentClick,
|
|
65
68
|
keydown: handleSegmentKeydown,
|
|
69
|
+
beforeinput: handleSegmentBeforeInput,
|
|
70
|
+
compositionstart: handleSegmentCompositionStart,
|
|
71
|
+
compositionend: handleSegmentCompositionEnd,
|
|
66
72
|
focusout: () => { hasLeftFocus = true },
|
|
67
73
|
focusin: (e: FocusEvent) => {
|
|
68
74
|
rootContext.setFocusedElement(e.target as HTMLElement)
|
|
@@ -417,6 +417,11 @@ const prevFocusableSegment = computed(() => {
|
|
|
417
417
|
});
|
|
418
418
|
|
|
419
419
|
function handleKeydown(e: KeyboardEvent) {
|
|
420
|
+
// Don't navigate between segments mid-composition, arrow keys are used for IME candidate navigation
|
|
421
|
+
if (e.isComposing) {
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
|
|
420
425
|
if (!isSegmentNavigationKey(e.key)) {
|
|
421
426
|
return;
|
|
422
427
|
}
|
|
@@ -8,9 +8,11 @@ import {
|
|
|
8
8
|
import { isIncludedIn, KEY_CODES } from '@vinicunca/perkakas';
|
|
9
9
|
import { computed } from 'vue';
|
|
10
10
|
import { getDaysInMonth, toDate } from '@/date';
|
|
11
|
-
import { snapValueToStep } from '@/shared';
|
|
11
|
+
import { getActiveElement, snapValueToStep } from '@/shared';
|
|
12
12
|
import { isAcceptableSegmentKey, isNumberString, isSegmentNavigationKey } from './segment';
|
|
13
13
|
|
|
14
|
+
const DIGIT_REG = /^\d$/;
|
|
15
|
+
|
|
14
16
|
type MinuteSecondIncrementProps = {
|
|
15
17
|
e: KeyboardEvent;
|
|
16
18
|
part: keyof TimeFields;
|
|
@@ -903,6 +905,14 @@ export function useDateField(props: UseDateFieldProps) {
|
|
|
903
905
|
}
|
|
904
906
|
|
|
905
907
|
function handleSegmentKeydown(e: KeyboardEvent) {
|
|
908
|
+
// A genuine composition keydown sets `isComposing` or reports `key === 'Process'`.
|
|
909
|
+
// Don't use `keyCode === 229` alone: a CJK IME (e.g. Pinyin) keeps that flag set
|
|
910
|
+
// while passing a directly-typed key through, so a real digit (`key === '1'`)
|
|
911
|
+
// would be dropped and leak into the contenteditable as raw text.
|
|
912
|
+
if (e.isComposing || e.key === 'Process') {
|
|
913
|
+
return;
|
|
914
|
+
}
|
|
915
|
+
|
|
906
916
|
const disabled = props.disabled.value;
|
|
907
917
|
const readonly = props.readonly.value;
|
|
908
918
|
if (disabled || readonly) {
|
|
@@ -968,9 +978,79 @@ export function useDateField(props: UseDateFieldProps) {
|
|
|
968
978
|
}
|
|
969
979
|
}
|
|
970
980
|
|
|
981
|
+
// Snapshot of the segment's child nodes (and their text) before the IME mutates
|
|
982
|
+
// the contenteditable. Vue renders the value into one text node but may keep
|
|
983
|
+
// empty sibling text nodes around it, so we must preserve EVERY node it owns and
|
|
984
|
+
// restore them verbatim on `compositionend`. Recreating nodes (textContent) would
|
|
985
|
+
// detach Vue's binding and freeze the segment; recreating the element isn't an
|
|
986
|
+
// option either, since the root captures segment elements once via
|
|
987
|
+
// `getSegmentElements` and a fresh node would break navigation.
|
|
988
|
+
let preCompositionNodes: Array<{ node: ChildNode; value: string | null }> | null = null;
|
|
989
|
+
|
|
990
|
+
function handleSegmentBeforeInput(e: InputEvent) {
|
|
991
|
+
// The segment's text is driven programmatically (keydown -> segmentValues ->
|
|
992
|
+
// Vue render), so the contenteditable must never be edited directly. Safari
|
|
993
|
+
// dispatches `beforeinput`/`input` BEFORE `keydown` while an IME is active,
|
|
994
|
+
// so a passed-through key (e.g. a digit typed while Pinyin is selected) would
|
|
995
|
+
// leak into the DOM as raw text before `handleSegmentKeydown` can prevent it.
|
|
996
|
+
// Composition input keeps `isComposing` true, so let it through and reconcile
|
|
997
|
+
// on `compositionend`.
|
|
998
|
+
if (!e.isComposing) {
|
|
999
|
+
e.preventDefault();
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
function handleSegmentCompositionStart(e: CompositionEvent) {
|
|
1004
|
+
const el = e.target as HTMLElement;
|
|
1005
|
+
preCompositionNodes = Array.from(el.childNodes, (node) => ({ node, value: node.nodeValue }));
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
function handleSegmentCompositionEnd(e: CompositionEvent) {
|
|
1009
|
+
const el = e.target as HTMLElement;
|
|
1010
|
+
const original = preCompositionNodes;
|
|
1011
|
+
preCompositionNodes = null;
|
|
1012
|
+
|
|
1013
|
+
// Restore Vue's original nodes (with their text) and drop anything the IME
|
|
1014
|
+
// inserted, keeping Vue's bindings intact so later renders still patch the DOM.
|
|
1015
|
+
// When no composition was tracked (e.g. synthetic events in tests) leave it be.
|
|
1016
|
+
if (original) {
|
|
1017
|
+
for (const { node, value } of original) {
|
|
1018
|
+
node.nodeValue = value;
|
|
1019
|
+
}
|
|
1020
|
+
el.replaceChildren(...original.map((o) => o.node));
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
const data = e.data;
|
|
1024
|
+
if (!data) {
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
for (const char of data) {
|
|
1029
|
+
if (!DIGIT_REG.test(char)) {
|
|
1030
|
+
continue;
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
// Dispatch to the focused segment so subsequent digits follow focus
|
|
1034
|
+
// after `focusNext()` advances to the next segment (e.g. "34" → 3 in day, 4 in month).
|
|
1035
|
+
const target = getActiveElement();
|
|
1036
|
+
if (!(target instanceof HTMLElement)) {
|
|
1037
|
+
break;
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
target.dispatchEvent(new KeyboardEvent('keydown', {
|
|
1041
|
+
key: char,
|
|
1042
|
+
bubbles: true,
|
|
1043
|
+
cancelable: true,
|
|
1044
|
+
}));
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
|
|
971
1048
|
return {
|
|
972
1049
|
handleSegmentClick,
|
|
973
1050
|
handleSegmentKeydown,
|
|
1051
|
+
handleSegmentBeforeInput,
|
|
1052
|
+
handleSegmentCompositionStart,
|
|
1053
|
+
handleSegmentCompositionEnd,
|
|
974
1054
|
handleSegmentFocusOut,
|
|
975
1055
|
attributes,
|
|
976
1056
|
};
|