akar 1.18.0 → 1.20.0

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.
Files changed (89) hide show
  1. package/dist/autocomplete/autocomplete-input.js +122 -0
  2. package/dist/autocomplete/autocomplete-input.js.map +1 -0
  3. package/dist/autocomplete/autocomplete-root.js +253 -0
  4. package/dist/autocomplete/autocomplete-root.js.map +1 -0
  5. package/dist/checkbox/checkbox-group-root.js +1 -1
  6. package/dist/checkbox/checkbox-root.js +1 -1
  7. package/dist/combobox/combobox-content-impl.js +9 -2
  8. package/dist/combobox/combobox-content-impl.js.map +1 -1
  9. package/dist/combobox/combobox-content.js +4 -0
  10. package/dist/combobox/combobox-content.js.map +1 -1
  11. package/dist/combobox/combobox-root.js +1 -1
  12. package/dist/composables/use-window-splitter-panel-group-behavior.js +13 -9
  13. package/dist/composables/use-window-splitter-panel-group-behavior.js.map +1 -1
  14. package/dist/constant/components.js +18 -0
  15. package/dist/constant/components.js.map +1 -1
  16. package/dist/constant.d.ts +1 -0
  17. package/dist/constant.d.ts.map +1 -1
  18. package/dist/date/use-date-field.js +1 -1
  19. package/dist/date/use-date-field.js.map +1 -1
  20. package/dist/date-field/date-field-root.js +1 -1
  21. package/dist/date-range-field/date-range-field-root.js +1 -1
  22. package/dist/dialog/dialog-content-impl.js +1 -1
  23. package/dist/hover-card/hover-card-content-impl.js +1 -1
  24. package/dist/index.d.ts +1752 -1622
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +50 -47
  27. package/dist/listbox/listbox-root.js +1 -1
  28. package/dist/listbox/listbox-virtualizer.js +1 -1
  29. package/dist/menu/menu-content-impl.js +1 -1
  30. package/dist/menu/menu-item-impl.js +1 -1
  31. package/dist/namespaced/index.cjs +19 -0
  32. package/dist/namespaced/index.d.cts +20 -2
  33. package/dist/namespaced/index.d.mts +20 -2
  34. package/dist/namespaced/index.mjs +20 -2
  35. package/dist/popover/popover-content-impl.js +1 -1
  36. package/dist/radio-group/radio-group-root.js +1 -1
  37. package/dist/range-calendar/range-calendar-cell-trigger.js +3 -1
  38. package/dist/range-calendar/range-calendar-cell-trigger.js.map +1 -1
  39. package/dist/range-calendar/range-calendar-grid.js +2 -1
  40. package/dist/range-calendar/range-calendar-grid.js.map +1 -1
  41. package/dist/range-calendar/range-calendar-root.js +17 -9
  42. package/dist/range-calendar/range-calendar-root.js.map +1 -1
  43. package/dist/range-calendar/use-range-calendar.js +16 -6
  44. package/dist/range-calendar/use-range-calendar.js.map +1 -1
  45. package/dist/select/select-content-impl.js +1 -1
  46. package/dist/select/select-root.js +1 -1
  47. package/dist/select/select-trigger.js +1 -1
  48. package/dist/shared/use-id.js +7 -4
  49. package/dist/shared/use-id.js.map +1 -1
  50. package/dist/splitter/splitter-group.js +143 -30
  51. package/dist/splitter/splitter-group.js.map +1 -1
  52. package/dist/splitter/splitter-panel.js +7 -2
  53. package/dist/splitter/splitter-panel.js.map +1 -1
  54. package/dist/time-field/time-field-root.js +1 -1
  55. package/dist/toast/toast-announce.js +4 -1
  56. package/dist/toast/toast-announce.js.map +1 -1
  57. package/dist/toggle-group/toggle-group-root.js +1 -1
  58. package/dist/tooltip/tooltip-content-impl.js +26 -19
  59. package/dist/tooltip/tooltip-content-impl.js.map +1 -1
  60. package/dist/tooltip/tooltip-content.js +1 -2
  61. package/dist/tooltip/tooltip-content.js.map +1 -1
  62. package/dist/tooltip/tooltip-provider.js +7 -2
  63. package/dist/tooltip/tooltip-provider.js.map +1 -1
  64. package/dist/utils/storage.js +7 -1
  65. package/dist/utils/storage.js.map +1 -1
  66. package/dist/utils/units.js +82 -0
  67. package/dist/utils/units.js.map +1 -0
  68. package/package.json +1 -1
  69. package/src/autocomplete/autocomplete-input.vue +124 -0
  70. package/src/autocomplete/autocomplete-root.vue +292 -0
  71. package/src/autocomplete/index.ts +74 -0
  72. package/src/combobox/combobox-content-impl.vue +13 -1
  73. package/src/index.ts +1 -0
  74. package/src/range-calendar/range-calendar-cell-trigger.vue +4 -2
  75. package/src/range-calendar/range-calendar-grid.vue +1 -0
  76. package/src/range-calendar/range-calendar-root.vue +27 -22
  77. package/src/range-calendar/use-range-calendar.ts +10 -12
  78. package/src/shared/date/use-date-field.ts +7 -3
  79. package/src/shared/use-id.ts +6 -8
  80. package/src/splitter/splitter-group.vue +249 -54
  81. package/src/splitter/splitter-panel.vue +12 -7
  82. package/src/splitter/utils/composables/use-window-splitter-panel-group-behavior.ts +18 -7
  83. package/src/splitter/utils/storage.ts +14 -0
  84. package/src/splitter/utils/units.ts +166 -0
  85. package/src/splitter/utils/validation.ts +3 -2
  86. package/src/toast/toast-announce.vue +4 -1
  87. package/src/tooltip/tooltip-content-impl.vue +18 -10
  88. package/src/tooltip/tooltip-content.vue +1 -3
  89. package/src/tooltip/tooltip-provider.vue +20 -3
@@ -0,0 +1,292 @@
1
+ <script lang="ts">
2
+ import type { Ref } from 'vue';
3
+ import type { APrimitiveProps } from '../primitive';
4
+ import type { Direction, GenericComponentInstance } from '../shared/types';
5
+ import { createContext, useDirection, useFilter } from '../shared';
6
+
7
+ export interface AAutocompleteRootProps extends APrimitiveProps {
8
+ /** The controlled value of the Autocomplete (the input text). Can be bound with `v-model`. */
9
+ modelValue?: string;
10
+ /** The value of the autocomplete when initially rendered. Use when you do not need to control the state. */
11
+ defaultValue?: string;
12
+ /** The controlled open state of the Autocomplete. Can be bound with `v-model:open`. */
13
+ open?: boolean;
14
+ /** The open state of the autocomplete when it is initially rendered. Use when you do not need to control its open state. */
15
+ defaultOpen?: boolean;
16
+ /** When `true`, prevents the user from interacting with autocomplete */
17
+ disabled?: boolean;
18
+ /** The reading direction of the autocomplete when applicable. */
19
+ dir?: Direction;
20
+ /** The name of the field. Submitted with its owning form as part of a name/value pair. */
21
+ name?: string;
22
+ /** When `true`, indicates that the user must set the value before the owning form can be submitted. */
23
+ required?: boolean;
24
+ /**
25
+ * Whether to reset the searchTerm when the Autocomplete input blurred
26
+ * @defaultValue `false`
27
+ */
28
+ resetSearchTermOnBlur?: boolean;
29
+ /**
30
+ * Whether to open the autocomplete when the input is focused
31
+ * @defaultValue `false`
32
+ */
33
+ openOnFocus?: boolean;
34
+ /**
35
+ * Whether to open the autocomplete when the input is clicked
36
+ * @defaultValue `false`
37
+ */
38
+ openOnClick?: boolean;
39
+ /**
40
+ * When `true`, disable the default filters
41
+ */
42
+ ignoreFilter?: boolean;
43
+ /** When `true`, hover over item will trigger highlight */
44
+ highlightOnHover?: boolean;
45
+ }
46
+
47
+ export type AAutocompleteRootEmits = {
48
+ /** Event handler called when the value changes. */
49
+ 'update:modelValue': [value: string];
50
+ /** Event handler when highlighted element changes. */
51
+ 'highlight': [payload: { ref: HTMLElement; value: string } | undefined];
52
+ /** Event handler called when the open state of the autocomplete changes. */
53
+ 'update:open': [value: boolean];
54
+ };
55
+
56
+ export type AAutocompleteRootContext = {
57
+ modelValue: Ref<string>;
58
+ };
59
+
60
+ export const [
61
+ injectAAutocompleteRootContext,
62
+ provideAAutocompleteRootContext,
63
+ ] = createContext<AAutocompleteRootContext>('AutocompleteRoot');
64
+ </script>
65
+
66
+ <script setup lang="ts">
67
+ import { createEventHook, useVModel } from '@vueuse/core';
68
+ import { computed, getCurrentInstance, nextTick, onMounted, ref, toRefs } from 'vue';
69
+ import { provideComboboxRootContext } from '../combobox/combobox-root.vue';
70
+ import { AListboxRoot } from '../listbox';
71
+ import { APopperRoot } from '../popper';
72
+ import { usePrimitiveElement } from '../primitive';
73
+
74
+ const props = withDefaults(
75
+ defineProps<AAutocompleteRootProps>(),
76
+ {
77
+ open: undefined,
78
+ resetSearchTermOnBlur: false,
79
+ openOnFocus: false,
80
+ openOnClick: false,
81
+ highlightOnHover: true,
82
+ },
83
+ );
84
+ const emits = defineEmits<AAutocompleteRootEmits>();
85
+
86
+ defineSlots<{
87
+ default?: (props: {
88
+ /** Current open state */
89
+ open: typeof open.value;
90
+ /** Current active value */
91
+ modelValue: typeof modelValue.value;
92
+ }) => any;
93
+ }>();
94
+
95
+ const {
96
+ primitiveElement,
97
+ currentElement: parentElement,
98
+ } = usePrimitiveElement<GenericComponentInstance<typeof AListboxRoot>>();
99
+ const {
100
+ disabled,
101
+ ignoreFilter,
102
+ openOnFocus,
103
+ openOnClick,
104
+ dir: propDir,
105
+ highlightOnHover,
106
+ } = toRefs(props);
107
+
108
+ const dir = useDirection(propDir);
109
+
110
+ const modelValue = useVModel(props, 'modelValue', emits, {
111
+ defaultValue: props.defaultValue ?? '',
112
+ passive: (props.modelValue === undefined) as false,
113
+ }) as Ref<string>;
114
+
115
+ const open = useVModel(props, 'open', emits, {
116
+ defaultValue: props.defaultOpen,
117
+ passive: (props.open === undefined) as false,
118
+ }) as Ref<boolean>;
119
+
120
+ // Writable computed that converts any value to string for the ComboboxRootContext.
121
+ // This handles the case when ComboboxItem sets modelValue to a non-string value,
122
+ // or when ComboboxCancel resets modelValue to null.
123
+ const contextModelValue = computed({
124
+ get: () => modelValue.value,
125
+ set: (val: any) => {
126
+ if (val === null || val === undefined) {
127
+ modelValue.value = '';
128
+ } else {
129
+ modelValue.value = String(val);
130
+ }
131
+ },
132
+ });
133
+
134
+ async function onOpenChange(val: boolean) {
135
+ open.value = val;
136
+
137
+ if (val) {
138
+ // When opening, set filter to current text so items are filtered by what's in the input
139
+ filterSearch.value = modelValue.value || '';
140
+
141
+ await nextTick();
142
+ primitiveElement.value?.highlightSelected();
143
+ isUserInputted.value = true;
144
+ inputElement.value?.focus();
145
+ } else {
146
+ isUserInputted.value = false;
147
+ filterSearch.value = '';
148
+ setTimeout(() => {
149
+ // eslint-disable-next-line sonar/no-gratuitous-expressions
150
+ if (!val && props.resetSearchTermOnBlur) {
151
+ resetSearchTerm.trigger();
152
+ }
153
+ }, 1);
154
+ }
155
+ }
156
+
157
+ const resetSearchTerm = createEventHook();
158
+ const isUserInputted = ref(false);
159
+ const isVirtual = ref(false);
160
+ const inputElement = ref<HTMLInputElement>();
161
+ const triggerElement = ref<HTMLElement>();
162
+
163
+ const highlightedElement = computed(() => primitiveElement.value?.highlightedElement ?? undefined);
164
+
165
+ const allItems = ref<Map<string, string>>(new Map());
166
+ const allGroups = ref<Map<string, Set<string>>>(new Map());
167
+
168
+ const { contains } = useFilter({ sensitivity: 'base' });
169
+
170
+ const filterSearch = ref('');
171
+
172
+ const filterState = computed<{
173
+ count: number;
174
+ items: Map<string, number>;
175
+ groups: Set<string>;
176
+ }>((oldValue) => {
177
+ if (!filterSearch.value || props.ignoreFilter || isVirtual.value) {
178
+ return {
179
+ count: allItems.value.size,
180
+ items: oldValue?.items ?? new Map(),
181
+ groups: oldValue?.groups ?? new Set(allGroups.value.keys()),
182
+ };
183
+ }
184
+
185
+ let itemCount = 0;
186
+ const filteredItems = new Map<string, number>();
187
+ const filteredGroups = new Set<string>();
188
+
189
+ for (const [id, value] of allItems.value) {
190
+ const score = contains({ string: value, substring: filterSearch.value });
191
+ filteredItems.set(id, score ? 1 : 0);
192
+ if (score) {
193
+ itemCount++;
194
+ }
195
+ }
196
+
197
+ for (const [groupId, group] of allGroups.value) {
198
+ for (const itemId of group) {
199
+ if (filteredItems.get(itemId)! > 0) {
200
+ filteredGroups.add(groupId);
201
+ break;
202
+ }
203
+ }
204
+ }
205
+
206
+ return {
207
+ count: itemCount,
208
+ items: filteredItems,
209
+ groups: filteredGroups,
210
+ };
211
+ });
212
+
213
+ const inst = getCurrentInstance();
214
+ onMounted(() => {
215
+ if (inst?.exposed) {
216
+ inst.exposed.highlightItem = primitiveElement.value?.highlightItem;
217
+ inst.exposed.highlightFirstItem = primitiveElement.value?.highlightFirstItem;
218
+ inst.exposed.highlightSelected = primitiveElement.value?.highlightSelected;
219
+ }
220
+ });
221
+
222
+ defineExpose({
223
+ filtered: filterState,
224
+ highlightedElement,
225
+ highlightItem: primitiveElement.value?.highlightItem,
226
+ highlightFirstItem: primitiveElement.value?.highlightFirstItem,
227
+ highlightSelected: primitiveElement.value?.highlightSelected,
228
+ });
229
+
230
+ // Provide the Combobox context so all Combobox sub-components work inside Autocomplete
231
+ provideComboboxRootContext({
232
+ modelValue: contextModelValue as any,
233
+ multiple: ref(false),
234
+ disabled,
235
+ open,
236
+ onOpenChange,
237
+ contentId: '',
238
+ isUserInputted,
239
+ isVirtual,
240
+ inputElement,
241
+ highlightedElement,
242
+ onInputElementChange: (val) => {
243
+ inputElement.value = val;
244
+ },
245
+ triggerElement,
246
+ onTriggerElementChange: (val) => {
247
+ triggerElement.value = val;
248
+ },
249
+ parentElement,
250
+ resetSearchTermOnSelect: ref(false),
251
+ onResetSearchTerm: resetSearchTerm.on,
252
+ allItems,
253
+ allGroups,
254
+ filterSearch,
255
+ filterState,
256
+ ignoreFilter,
257
+ openOnFocus,
258
+ openOnClick,
259
+ resetModelValueOnClear: ref(true),
260
+ });
261
+
262
+ // Provide autocomplete-specific context
263
+ provideAAutocompleteRootContext({
264
+ modelValue,
265
+ });
266
+ </script>
267
+
268
+ <template>
269
+ <APopperRoot>
270
+ <AListboxRoot
271
+ ref="primitiveElement"
272
+ v-bind="$attrs"
273
+ v-model="(contextModelValue as any)"
274
+ :style="{
275
+ pointerEvents: open ? 'auto' : undefined,
276
+ }"
277
+ :as="as"
278
+ :as-child="asChild"
279
+ :dir="dir"
280
+ :name="name"
281
+ :required="required"
282
+ :disabled="disabled"
283
+ :highlight-on-hover="highlightOnHover"
284
+ @highlight="emits('highlight', $event as any)"
285
+ >
286
+ <slot
287
+ :open="open"
288
+ :model-value="modelValue"
289
+ />
290
+ </AListboxRoot>
291
+ </APopperRoot>
292
+ </template>
@@ -0,0 +1,74 @@
1
+ // Re-export Combobox sub-components as Autocomplete equivalents.
2
+ // These components inject ComboboxRootContext which AutocompleteRoot provides.
3
+ export {
4
+ AComboboxAnchor as AAutocompleteAnchor,
5
+ type AComboboxAnchorProps as AAutocompleteAnchorProps,
6
+ } from '../combobox';
7
+ export {
8
+ AComboboxArrow as AAutocompleteArrow,
9
+ type AComboboxArrowProps as AAutocompleteArrowProps,
10
+ } from '../combobox';
11
+
12
+ export {
13
+ AComboboxCancel as AAutocompleteCancel,
14
+ type AComboboxCancelProps as AAutocompleteCancelProps,
15
+ } from '../combobox';
16
+ export {
17
+ AComboboxContent as AAutocompleteContent,
18
+ type AComboboxContentEmits as AAutocompleteContentEmits,
19
+ type AComboboxContentProps as AAutocompleteContentProps,
20
+ } from '../combobox';
21
+ export {
22
+ AComboboxEmpty as AAutocompleteEmpty,
23
+ type AComboboxEmptyProps as AAutocompleteEmptyProps,
24
+ } from '../combobox';
25
+ export {
26
+ AComboboxGroup as AAutocompleteGroup,
27
+ type AComboboxGroupProps as AAutocompleteGroupProps,
28
+ } from '../combobox';
29
+ export {
30
+ AComboboxItem as AAutocompleteItem,
31
+ type AComboboxItemEmits as AAutocompleteItemEmits,
32
+ type AComboboxItemProps as AAutocompleteItemProps,
33
+ } from '../combobox';
34
+ export {
35
+ AComboboxItemIndicator as AAutocompleteItemIndicator,
36
+ type AComboboxItemIndicatorProps as AAutocompleteItemIndicatorProps,
37
+ } from '../combobox';
38
+ export {
39
+ AComboboxLabel as AAutocompleteLabel,
40
+ type AComboboxLabelProps as AAutocompleteLabelProps,
41
+ } from '../combobox';
42
+ export {
43
+ AComboboxPortal as AAutocompletePortal,
44
+ type AComboboxPortalProps as AAutocompletePortalProps,
45
+ } from '../combobox';
46
+ export {
47
+ AComboboxSeparator as AAutocompleteSeparator,
48
+ type AComboboxSeparatorProps as AAutocompleteSeparatorProps,
49
+ } from '../combobox';
50
+ export {
51
+ AComboboxTrigger as AAutocompleteTrigger,
52
+ type AComboboxTriggerProps as AAutocompleteTriggerProps,
53
+ } from '../combobox';
54
+ export {
55
+ AComboboxViewport as AAutocompleteViewport,
56
+ type AComboboxViewportProps as AAutocompleteViewportProps,
57
+ } from '../combobox';
58
+ export {
59
+ AComboboxVirtualizer as AAutocompleteVirtualizer,
60
+ type AComboboxVirtualizerProps as AAutocompleteVirtualizerProps,
61
+ } from '../combobox';
62
+
63
+ export {
64
+ default as AAutocompleteInput,
65
+ type AAutocompleteInputEmits,
66
+ type AAutocompleteInputProps,
67
+ } from './autocomplete-input.vue';
68
+
69
+ export {
70
+ default as AAutocompleteRoot,
71
+ type AAutocompleteRootEmits,
72
+ type AAutocompleteRootProps,
73
+ injectAAutocompleteRootContext,
74
+ } from './autocomplete-root.vue';
@@ -24,6 +24,11 @@ export interface ComboboxContentImplProps extends APopperContentProps, Dismissab
24
24
  position?: 'inline' | 'popper';
25
25
  /** The document.body will be lock, and scrolling will be disabled. */
26
26
  bodyLock?: boolean;
27
+ /**
28
+ * When `true`, hides the content when there are no items matching the filter.
29
+ * @defaultValue false
30
+ */
31
+ hideWhenEmpty?: boolean;
27
32
  }
28
33
 
29
34
  export const [
@@ -51,6 +56,11 @@ const emits = defineEmits<ComboboxContentImplEmits>();
51
56
  const { position } = toRefs(props);
52
57
  const rootContext = injectAComboboxRootContext();
53
58
 
59
+ const isEmpty = computed(() => rootContext.ignoreFilter.value
60
+ ? rootContext.allItems.value.size === 0
61
+ : rootContext.filterState.value.count === 0,
62
+ );
63
+
54
64
  const { forwardRef, currentElement } = useForwardExpose();
55
65
  useBodyScrollLock(props.bodyLock);
56
66
  useFocusGuards();
@@ -130,9 +140,11 @@ onUnmounted(() => {
130
140
  :id="rootContext.contentId"
131
141
  :ref="forwardRef"
132
142
  :data-state="rootContext.open.value ? 'open' : 'closed'"
143
+ :data-empty="isEmpty ? '' : undefined"
133
144
  :style="{
134
145
  // flex layout so we can place the scroll buttons properly
135
- display: 'flex',
146
+ // When hideWhenEmpty is true, hide the content when no items match
147
+ display: (props.hideWhenEmpty && isEmpty) ? 'none' : 'flex',
136
148
  flexDirection: 'column',
137
149
  // reset the outline by default as the content MAY get focused
138
150
  outline: 'none',
package/src/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable perfectionist/sort-exports */
2
2
  export * from './accordion';
3
+ export * from './autocomplete';
3
4
  export * from './avatar';
4
5
  export * from './alert-dialog';
5
6
  export * from './calendar';
@@ -118,22 +118,24 @@ function changeDate(event: KeyboardEvent | MouseEvent, date: DateValue) {
118
118
  return;
119
119
  }
120
120
 
121
- rootContext.lastPressedDateValue.value = date.copy();
122
-
123
121
  if (rootContext.startValue.value && rootContext.highlightedRange.value === null) {
124
122
  if (isSameDay(date, rootContext.startValue.value) && !rootContext.preventDeselect.value && !rootContext.endValue.value) {
125
123
  rootContext.startValue.value = undefined;
126
124
  rootContext.onPlaceholderChange(date);
125
+ rootContext.lastPressedDateValue.value = date.copy();
127
126
  return;
128
127
  } else if (!rootContext.endValue.value) {
129
128
  event.preventDefault();
130
129
  if (rootContext.lastPressedDateValue.value && isSameDay(rootContext.lastPressedDateValue.value, date)) {
131
130
  rootContext.startValue.value = date.copy();
132
131
  }
132
+ rootContext.lastPressedDateValue.value = date.copy();
133
133
  return;
134
134
  }
135
135
  }
136
136
 
137
+ rootContext.lastPressedDateValue.value = date.copy();
138
+
137
139
  if (
138
140
  rootContext.startValue.value
139
141
  && rootContext.endValue.value
@@ -26,6 +26,7 @@ const readonly = computed(() => rootContext.readonly.value ? true : undefined);
26
26
  :aria-disabled="disabled"
27
27
  :data-readonly="readonly && ''"
28
28
  :data-disabled="disabled && ''"
29
+ @mouseleave="rootContext.focusedValue.value = undefined"
29
30
  >
30
31
  <slot />
31
32
  </APrimitive>
@@ -229,9 +229,12 @@ const isEditing = ref(false);
229
229
  const modelValue = useVModel(props, 'modelValue', emits, {
230
230
  defaultValue: props.defaultValue ?? { start: undefined, end: undefined },
231
231
  passive: (props.modelValue === undefined) as false,
232
- }) as Ref<DateRange>;
232
+ }) as Ref<DateRange | null>;
233
233
 
234
- const validModelValue = ref(modelValue.value) as Ref<DateRange>;
234
+ const normalizeRange = (value?: DateRange | null): DateRange => value ?? { start: undefined, end: undefined };
235
+ const normalizedModelValue = computed(() => normalizeRange(modelValue.value));
236
+
237
+ const validModelValue = ref(normalizeRange(modelValue.value)) as Ref<DateRange>;
235
238
 
236
239
  watch(validModelValue, (value) => {
237
240
  emits('update:validModelValue', value);
@@ -239,12 +242,16 @@ watch(validModelValue, (value) => {
239
242
 
240
243
  const defaultDate = getDefaultDate({
241
244
  defaultPlaceholder: props.placeholder,
242
- defaultValue: modelValue.value.start,
245
+ defaultValue: normalizeRange(modelValue.value).start,
243
246
  locale: props.locale,
244
247
  });
245
248
 
246
- const startValue = ref(modelValue.value.start) as Ref<DateValue | undefined>;
247
- const endValue = ref(modelValue.value.end) as Ref<DateValue | undefined>;
249
+ const startValue = ref(normalizeRange(modelValue.value).start) as Ref<
250
+ DateValue | undefined
251
+ >;
252
+ const endValue = ref(normalizeRange(modelValue.value).end) as Ref<
253
+ DateValue | undefined
254
+ >;
248
255
 
249
256
  const placeholder = useVModel(props, 'placeholder', emits, {
250
257
  defaultValue: props.defaultPlaceholder ?? defaultDate.copy(),
@@ -310,23 +317,21 @@ const {
310
317
 
311
318
  watch(
312
319
  modelValue,
313
- (modelValue_, prevValue_) => {
314
- if (
315
- (!prevValue_?.start && modelValue_?.start)
316
- || !modelValue_
317
- || !modelValue_.start
318
- || (startValue.value && !isEqualDay(modelValue_.start, startValue.value))
319
- ) {
320
- startValue.value = modelValue_?.start?.copy?.();
320
+ (modelValue_) => {
321
+ const next = normalizeRange(modelValue_);
322
+
323
+ const isStartSynced = (!next.start && !startValue.value)
324
+ || (!!next.start && !!startValue.value && isEqualDay(next.start, startValue.value));
325
+
326
+ if (!isStartSynced) {
327
+ startValue.value = next.start?.copy?.();
321
328
  }
322
329
 
323
- if (
324
- (!prevValue_?.end && modelValue_.end)
325
- || !modelValue_
326
- || !modelValue_.end
327
- || (endValue.value && !isEqualDay(modelValue_.end, endValue.value))
328
- ) {
329
- endValue.value = modelValue_?.end?.copy?.();
330
+ const isEndSynced = (!next.end && !endValue.value)
331
+ || (!!next.end && !!endValue.value && isEqualDay(next.end, endValue.value));
332
+
333
+ if (!isEndSynced) {
334
+ endValue.value = next.end?.copy?.();
330
335
  }
331
336
  },
332
337
  );
@@ -395,7 +400,7 @@ provideRangeCalendarRootContext({
395
400
  startValue,
396
401
  endValue,
397
402
  formatter,
398
- modelValue,
403
+ modelValue: normalizedModelValue,
399
404
  placeholder,
400
405
  disabled,
401
406
  initialFocus,
@@ -484,7 +489,7 @@ onMounted(() => {
484
489
  :week-starts-on="weekStartsOn"
485
490
  :locale="locale"
486
491
  :fixed-weeks="fixedWeeks"
487
- :model-value="modelValue"
492
+ :model-value="normalizedModelValue"
488
493
  />
489
494
  </APrimitive>
490
495
  </template>
@@ -40,7 +40,7 @@ export function useRangeCalendarState(props: UseRangeCalendarProps) {
40
40
  const isInvalid = computed(
41
41
  () => {
42
42
  if (isStartInvalid.value || isEndInvalid.value) {
43
- return false;
43
+ return true;
44
44
  }
45
45
 
46
46
  return Boolean(
@@ -83,7 +83,6 @@ export function useRangeCalendarState(props: UseRangeCalendarProps) {
83
83
  return false;
84
84
  };
85
85
 
86
- // Check if a date exceeds maximum days limit from the start dateAdd commentMore actions
87
86
  const rangeIsDateDisabled = (date: DateValue) => {
88
87
  if (props.isDateDisabled(date)) {
89
88
  return true;
@@ -148,20 +147,19 @@ export function useRangeCalendarState(props: UseRangeCalendarProps) {
148
147
  };
149
148
  }
150
149
 
151
- // If maximum days is set and the range exceeds it, limit the highlightAdd commentMore actions
152
- // We only apply this when we're in the middle of a selection (no end date yet)
153
150
  if (
154
151
  props.maximumDays?.value
155
152
  && !props.end.value
156
153
  ) {
157
- // Determine the direction of selection and limit to maximum days
158
- const cappedEnd = isStartBeforeFocused
159
- ? start.add({ days: props.maximumDays.value - 1 })
160
- : start.subtract({ days: props.maximumDays.value });
161
-
162
- return {
163
- start,
164
- end: cappedEnd,
154
+ const maximumDays = props.maximumDays.value;
155
+ const anchor = props.start.value;
156
+
157
+ if (isStartBeforeFocused) {
158
+ const maxEnd = anchor.add({ days: maximumDays - 1 });
159
+ return { start: anchor, end: maxEnd };
160
+ } else {
161
+ const minStart = anchor.subtract({ days: maximumDays - 1 });
162
+ return { start: minStart, end: anchor };
165
163
  };
166
164
  }
167
165
 
@@ -777,7 +777,9 @@ export function useDateField(props: UseDateFieldProps) {
777
777
 
778
778
  if (isNumberString(event.key)) {
779
779
  const num = Number.parseInt(event.key);
780
- const is12Hour = uses12HourFormat(props.formatter.getLocale());
780
+ const is12Hour = props.hourCycle !== undefined
781
+ ? props.hourCycle === 12
782
+ : uses12HourFormat(props.formatter.getLocale());
781
783
  const max = is12Hour ? 12 : 24;
782
784
 
783
785
  let displayPrev = prevValue;
@@ -990,7 +992,8 @@ export function useDateField(props: UseDateFieldProps) {
990
992
  && 'minute' in props.segmentValues.value
991
993
  && props.segmentValues.value.minute !== null
992
994
  && props.step.value.minute
993
- && props.step.value.minute > 1) {
995
+ && props.step.value.minute > 1
996
+ ) {
994
997
  props.segmentValues.value.minute = snapValueToStep({
995
998
  value: props.segmentValues.value.minute,
996
999
  min: 0,
@@ -1002,7 +1005,8 @@ export function useDateField(props: UseDateFieldProps) {
1002
1005
  && 'second' in props.segmentValues.value
1003
1006
  && props.segmentValues.value.second !== null
1004
1007
  && props.step.value.second
1005
- && props.step.value.second > 1) {
1008
+ && props.step.value.second > 1
1009
+ ) {
1006
1010
  props.segmentValues.value.second = snapValueToStep({
1007
1011
  value: props.segmentValues.value.second,
1008
1012
  min: 0,
@@ -18,15 +18,13 @@ export function useId(deterministicId?: null | string | undefined, prefix = 'aka
18
18
  return deterministicId;
19
19
  }
20
20
 
21
+ let id: string;
21
22
  if (Object.hasOwn(vue, 'useId')) {
22
- return `${prefix}-${vue.useId?.()}`;
23
+ id = vue.useId?.();
24
+ } else {
25
+ const configProviderContext = injectAConfigProviderContext({ useId: undefined });
26
+ id = configProviderContext.useId?.() ?? `${++count}`;
23
27
  }
24
28
 
25
- const configProviderContext = injectAConfigProviderContext({ useId: undefined });
26
-
27
- if (configProviderContext.useId) {
28
- return `${prefix}-${configProviderContext.useId()}`;
29
- }
30
-
31
- return `${prefix}-${++count}`;
29
+ return prefix ? `${prefix}-${id}` : id;
32
30
  }