akar 1.16.0 → 1.19.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 (64) hide show
  1. package/dist/calendar/calendar-root.js +6 -5
  2. package/dist/calendar/calendar-root.js.map +1 -1
  3. package/dist/combobox/combobox-content-impl.js +2 -1
  4. package/dist/combobox/combobox-content-impl.js.map +1 -1
  5. package/dist/date/calendar.date.js +25 -11
  6. package/dist/date/calendar.date.js.map +1 -1
  7. package/dist/date/comparators.date.js +10 -2
  8. package/dist/date/comparators.date.js.map +1 -1
  9. package/dist/date/use-date-field.js +59 -20
  10. package/dist/date/use-date-field.js.map +1 -1
  11. package/dist/date-picker/date-picker-root.js +10 -8
  12. package/dist/date-picker/date-picker-root.js.map +1 -1
  13. package/dist/date-range-picker/date-range-picker-root.js +11 -9
  14. package/dist/date-range-picker/date-range-picker-root.js.map +1 -1
  15. package/dist/date.d.ts +2 -2
  16. package/dist/date.js +2 -2
  17. package/dist/focus-scope/focus-scope.js +2 -2
  18. package/dist/focus-scope/focus-scope.js.map +1 -1
  19. package/dist/focus-scope/stack.js +1 -4
  20. package/dist/focus-scope/stack.js.map +1 -1
  21. package/dist/index.d.ts +819 -820
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index2.d.ts +9 -2
  24. package/dist/index2.d.ts.map +1 -1
  25. package/dist/range-calendar/range-calendar-cell-trigger.js +3 -1
  26. package/dist/range-calendar/range-calendar-cell-trigger.js.map +1 -1
  27. package/dist/range-calendar/range-calendar-grid.js +2 -1
  28. package/dist/range-calendar/range-calendar-grid.js.map +1 -1
  29. package/dist/range-calendar/range-calendar-root.js +23 -14
  30. package/dist/range-calendar/range-calendar-root.js.map +1 -1
  31. package/dist/range-calendar/use-range-calendar.js +16 -6
  32. package/dist/range-calendar/use-range-calendar.js.map +1 -1
  33. package/dist/shared/use-grace-area.js +1 -1
  34. package/dist/shared/use-grace-area.js.map +1 -1
  35. package/dist/time-field/time-field-input.js +3 -1
  36. package/dist/time-field/time-field-input.js.map +1 -1
  37. package/dist/time-field/time-field-root.js +26 -2
  38. package/dist/time-field/time-field-root.js.map +1 -1
  39. package/package.json +7 -6
  40. package/src/calendar/calendar-root.vue +12 -11
  41. package/src/calendar/use-calendar.ts +2 -2
  42. package/src/combobox/combobox-content-impl.vue +1 -0
  43. package/src/combobox/combobox-root.vue +1 -1
  44. package/src/date/calendar.date.ts +42 -18
  45. package/src/date/comparators.date.ts +11 -3
  46. package/src/date-picker/date-picker-anchor.vue +2 -2
  47. package/src/date-picker/date-picker-arrow.vue +2 -2
  48. package/src/date-picker/date-picker-close.vue +2 -2
  49. package/src/date-picker/date-picker-root.vue +11 -11
  50. package/src/date-picker/index.ts +71 -27
  51. package/src/date-range-picker/date-range-picker-root.vue +14 -15
  52. package/src/focus-scope/focus-scope.vue +2 -2
  53. package/src/index.ts +1 -0
  54. package/src/listbox/listbox-filter.vue +1 -1
  55. package/src/listbox/listbox-root.vue +1 -1
  56. package/src/range-calendar/range-calendar-cell-trigger.vue +4 -2
  57. package/src/range-calendar/range-calendar-grid.vue +1 -0
  58. package/src/range-calendar/range-calendar-root.vue +41 -36
  59. package/src/range-calendar/use-range-calendar.ts +10 -12
  60. package/src/shared/date/use-date-field.ts +108 -21
  61. package/src/shared/use-grace-area.ts +1 -1
  62. package/src/time-field/time-field-input.vue +7 -2
  63. package/src/time-field/time-field-root.vue +42 -3
  64. package/src/tree/tree-root.vue +2 -2
@@ -1,18 +1,12 @@
1
1
  <script lang="ts">
2
2
  import type { DateValue } from '@internationalized/date';
3
3
  import type { Ref } from 'vue';
4
- import type { DateGrid, DateMatcher, WeekDayFormat } from '../date';
4
+ import type { DateGrid, DateMatcher, WeekDayFormat, WeekStartsOn } from '../date';
5
5
  import type { APrimitiveProps } from '../primitive';
6
6
  import type { UseDateFormatter } from '../shared';
7
7
  import type { DateRange } from '../shared/date';
8
8
  import type { Direction } from '../shared/types';
9
- import { isEqualDay } from '@internationalized/date';
10
- import { KEY_CODES } from '@vinicunca/perkakas';
11
- import { useCalendar } from '../calendar/use-calendar';
12
- import { isDateBefore } from '../date';
13
- import { createContext, useDirection, useLocale } from '../shared';
14
- import { getDefaultDate, handleCalendarInitialFocus } from '../shared/date';
15
- import { useRangeCalendarState } from './use-range-calendar';
9
+ import { createContext } from '../shared';
16
10
 
17
11
  type RangeCalendarRootContext = {
18
12
  modelValue: Ref<DateRange>;
@@ -24,7 +18,7 @@ type RangeCalendarRootContext = {
24
18
  preventDeselect: Ref<boolean>;
25
19
  grid: Ref<Array<DateGrid<DateValue>>>;
26
20
  weekDays: Ref<Array<string>>;
27
- weekStartsOn: Ref<0 | 1 | 2 | 3 | 4 | 5 | 6>;
21
+ weekStartsOn: Ref<WeekStartsOn>;
28
22
  weekdayFormat: Ref<WeekDayFormat>;
29
23
  fixedWeeks: Ref<boolean>;
30
24
  numberOfMonths: Ref<number>;
@@ -84,7 +78,7 @@ export interface ARangeCalendarRootProps extends APrimitiveProps {
84
78
  /** The maximum number of days that can be selected in a range */
85
79
  maximumDays?: number;
86
80
  /** The day of the week to start the calendar on */
87
- weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
81
+ weekStartsOn?: WeekStartsOn;
88
82
  /** The format to use for the weekday strings provided via the weekdays slot prop */
89
83
  weekdayFormat?: WeekDayFormat;
90
84
  /** The accessible label for the calendar */
@@ -141,9 +135,16 @@ export const [
141
135
  </script>
142
136
 
143
137
  <script setup lang="ts">
138
+ import { isEqualDay } from '@internationalized/date';
139
+ import { KEY_CODES } from '@vinicunca/perkakas';
144
140
  import { useEventListener, useVModel } from '@vueuse/core';
145
- import { onMounted, ref, toRefs, watch } from 'vue';
141
+ import { computed, onMounted, ref, toRefs, watch } from 'vue';
142
+ import { useCalendar } from '../calendar/use-calendar';
143
+ import { getWeekStartsOn, isDateBefore } from '../date';
146
144
  import { APrimitive, usePrimitiveElement } from '../primitive';
145
+ import { useDirection, useLocale } from '../shared';
146
+ import { getDefaultDate, handleCalendarInitialFocus } from '../shared/date';
147
+ import { useRangeCalendarState } from './use-range-calendar';
147
148
 
148
149
  const props = withDefaults(
149
150
  defineProps<ARangeCalendarRootProps>(),
@@ -152,7 +153,6 @@ const props = withDefaults(
152
153
  as: 'div',
153
154
  pagedNavigation: false,
154
155
  preventDeselect: false,
155
- weekStartsOn: 0,
156
156
  weekdayFormat: 'narrow',
157
157
  fixedWeeks: false,
158
158
  numberOfMonths: 1,
@@ -179,7 +179,7 @@ defineSlots<{
179
179
  /** The days of the week */
180
180
  weekDays: Array<string>;
181
181
  /** The start of the week */
182
- weekStartsOn: 0 | 1 | 2 | 3 | 4 | 5 | 6;
182
+ weekStartsOn: WeekStartsOn;
183
183
  /** The calendar locale */
184
184
  locale: string;
185
185
  /** Whether or not to always display 6 weeks in the calendar */
@@ -194,7 +194,6 @@ const {
194
194
  readonly,
195
195
  initialFocus,
196
196
  pagedNavigation,
197
- weekStartsOn,
198
197
  weekdayFormat,
199
198
  fixedWeeks,
200
199
  numberOfMonths,
@@ -221,6 +220,7 @@ const {
221
220
  } = usePrimitiveElement();
222
221
  const dir = useDirection(propDir);
223
222
  const locale = useLocale(propLocale);
223
+ const weekStartsOn = computed(() => props.weekStartsOn ?? getWeekStartsOn(locale.value));
224
224
 
225
225
  const lastPressedDateValue = ref() as Ref<DateValue | undefined>;
226
226
  const focusedValue = ref() as Ref<DateValue | undefined>;
@@ -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
+
234
+ const normalizeRange = (value?: DateRange | null): DateRange => value ?? { start: undefined, end: undefined };
235
+ const normalizedModelValue = computed(() => normalizeRange(modelValue.value));
233
236
 
234
- const validModelValue = ref(modelValue.value) as Ref<DateRange>;
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
 
@@ -1,10 +1,14 @@
1
- import type { CalendarDateTime, CycleTimeOptions, DateFields, DateValue, TimeFields } from '@internationalized/date';
1
+ import type { CalendarDateTime, DateFields, DateValue, TimeFields } from '@internationalized/date';
2
2
  import type { Ref } from 'vue';
3
3
  import type { UseDateFormatter } from '../../shared';
4
4
  import type { AnyExceptLiteral, DateStep, HourCycle, SegmentPart, SegmentValueObj } from './types';
5
+ import {
6
+ DateFormatter,
7
+ } from '@internationalized/date';
5
8
  import { isIncludedIn, KEY_CODES } from '@vinicunca/perkakas';
6
9
  import { computed } from 'vue';
7
10
  import { getDaysInMonth, toDate } from '../../date';
11
+ import { snapValueToStep } from '../../shared';
8
12
  import { isAcceptableSegmentKey, isNumberString, isSegmentNavigationKey } from './segment';
9
13
 
10
14
  interface MinuteSecondIncrementProps {
@@ -19,7 +23,6 @@ interface DateTimeValueIncrementation {
19
23
  part: keyof Omit<DateFields, 'era'> | keyof TimeFields;
20
24
  dateRef: DateValue;
21
25
  prevValue: null | number;
22
- hourCycle?: HourCycle;
23
26
  }
24
27
 
25
28
  interface SegmentAttrProps {
@@ -299,6 +302,7 @@ export interface UseDateFieldProps {
299
302
  placeholder: Ref<DateValue>;
300
303
  hourCycle: HourCycle;
301
304
  step: Ref<DateStep>;
305
+ stepSnapping?: Ref<boolean>;
302
306
  formatter: UseDateFormatter;
303
307
  segmentValues: Ref<SegmentValueObj>;
304
308
  disabled: Ref<boolean>;
@@ -339,7 +343,7 @@ export function useDateField(props: UseDateFieldProps) {
339
343
  return Number.parseInt(str.slice(0, -1));
340
344
  }
341
345
 
342
- function dateTimeValueIncrementation({ event, part, dateRef, prevValue, hourCycle }: DateTimeValueIncrementation): number {
346
+ function dateTimeValueIncrementation({ event, part, dateRef, prevValue }: DateTimeValueIncrementation): number {
343
347
  const step = props.step.value[part] ?? 1;
344
348
  const sign = event.key === KEY_CODES.ARROW_UP ? step : -step;
345
349
 
@@ -348,7 +352,9 @@ export function useDateField(props: UseDateFieldProps) {
348
352
  }
349
353
 
350
354
  if (part === 'hour' && 'hour' in dateRef) {
351
- const cycleArgs: [keyof DateFields | keyof TimeFields, number, CycleTimeOptions?] = [part, sign, { hourCycle }];
355
+ // Don't pass hourCycle to cycle - internal representation is always 24-hour
356
+ // The hourCycle prop only affects display, not internal cycling
357
+ const cycleArgs: [keyof DateFields | keyof TimeFields, number] = [part, sign];
352
358
  return dateRef.set({ [part as keyof DateValue]: prevValue }).cycle(...cycleArgs)[part];
353
359
  }
354
360
 
@@ -528,8 +534,7 @@ export function useDateField(props: UseDateFieldProps) {
528
534
  return { value: total, moveToNext };
529
535
  }
530
536
 
531
- function updateHour(num: number, prev: null | number) {
532
- const max = 24;
537
+ function updateHour(max: number, num: number, prev: null | number) {
533
538
  let moveToNext = false;
534
539
  const maxStart = Math.floor(max / 10);
535
540
 
@@ -744,6 +749,11 @@ export function useDateField(props: UseDateFieldProps) {
744
749
  }
745
750
  }
746
751
 
752
+ function uses12HourFormat(locale: string): boolean {
753
+ const hourCycle = new DateFormatter(locale, { hour: 'numeric' }).resolvedOptions().hourCycle;
754
+ return hourCycle === 'h11' || hourCycle === 'h12';
755
+ }
756
+
747
757
  function handleHourSegmentKeydown(event: KeyboardEvent) {
748
758
  const dateRef = props.placeholder.value;
749
759
  if (!isAcceptableSegmentKey(event.key) || isSegmentNavigationKey(event.key) || !('hour' in dateRef) || !('hour' in props.segmentValues.value)) {
@@ -752,17 +762,14 @@ export function useDateField(props: UseDateFieldProps) {
752
762
 
753
763
  const prevValue = props.segmentValues.value.hour;
754
764
 
755
- const hourCycle = props.hourCycle;
756
-
757
765
  if (event.key === KEY_CODES.ARROW_UP || event.key === KEY_CODES.ARROW_DOWN) {
758
- props.segmentValues.value.hour = dateTimeValueIncrementation({ event, part: 'hour', dateRef: props.placeholder.value, prevValue, hourCycle });
766
+ const newHour = dateTimeValueIncrementation({ event, part: 'hour', dateRef: props.placeholder.value, prevValue });
767
+ props.segmentValues.value.hour = newHour;
759
768
 
760
- if ('dayPeriod' in props.segmentValues.value) {
761
- if (props.segmentValues.value.hour < 12) {
762
- props.segmentValues.value.dayPeriod = 'AM';
763
- } else if (props.segmentValues.value.hour) {
764
- props.segmentValues.value.dayPeriod = 'PM';
765
- }
769
+ if ('dayPeriod' in props.segmentValues.value && newHour !== null) {
770
+ // Determine AM/PM based on internal 24-hour value
771
+ // Hour 0-11 = AM, Hour 12-23 = PM
772
+ props.segmentValues.value.dayPeriod = newHour >= 12 ? 'PM' : 'AM';
766
773
  }
767
774
 
768
775
  return;
@@ -770,15 +777,34 @@ export function useDateField(props: UseDateFieldProps) {
770
777
 
771
778
  if (isNumberString(event.key)) {
772
779
  const num = Number.parseInt(event.key);
773
- const { value, moveToNext } = updateHour(num, prevValue);
780
+ const is12Hour = props.hourCycle !== undefined
781
+ ? props.hourCycle === 12
782
+ : uses12HourFormat(props.formatter.getLocale());
783
+ const max = is12Hour ? 12 : 24;
784
+
785
+ let displayPrev = prevValue;
786
+ if (is12Hour && prevValue !== null) {
787
+ if (prevValue === 0) {
788
+ displayPrev = 12;
789
+ } else if (prevValue > 12) {
790
+ displayPrev = prevValue - 12;
791
+ }
792
+ }
774
793
 
775
- if ('dayPeriod' in props.segmentValues.value && value && value > 12) {
776
- props.segmentValues.value.dayPeriod = 'PM';
777
- } else if ('dayPeriod' in props.segmentValues.value && value) {
778
- props.segmentValues.value.dayPeriod = 'AM';
794
+ const { value, moveToNext } = updateHour(max, num, displayPrev);
795
+
796
+ // Convert display hour back to internal 24-hour format
797
+ let internalValue = value;
798
+ if (is12Hour && value !== null) {
799
+ const period = props.segmentValues.value.dayPeriod || 'AM';
800
+ if (value === 12) {
801
+ internalValue = period === 'AM' ? 0 : 12;
802
+ } else {
803
+ internalValue = period === 'PM' ? value + 12 : value;
804
+ }
779
805
  }
780
806
 
781
- props.segmentValues.value.hour = value;
807
+ props.segmentValues.value.hour = internalValue;
782
808
 
783
809
  if (moveToNext) {
784
810
  props.focusNext();
@@ -935,9 +961,70 @@ export function useDateField(props: UseDateFieldProps) {
935
961
  }
936
962
  }
937
963
 
964
+ function handleSegmentFocusOut() {
965
+ if (!props.stepSnapping?.value) {
966
+ return;
967
+ }
968
+
969
+ if (
970
+ props.part === 'hour'
971
+ && 'hour' in props.segmentValues.value
972
+ && props.segmentValues.value.hour !== null
973
+ && props.step.value.hour
974
+ && props.step.value.hour > 1
975
+ ) {
976
+ props.segmentValues.value.hour = snapValueToStep({
977
+ value: props.segmentValues.value.hour,
978
+ min: 0,
979
+ max: 23,
980
+ step: props.step.value.hour,
981
+ });
982
+
983
+ if ('dayPeriod' in props.segmentValues.value) {
984
+ if (props.segmentValues.value.hour < 12) {
985
+ props.segmentValues.value.dayPeriod = 'AM';
986
+ } else if (props.segmentValues.value.hour) {
987
+ props.segmentValues.value.dayPeriod = 'PM';
988
+ }
989
+ }
990
+ } else if (
991
+ props.part === 'minute'
992
+ && 'minute' in props.segmentValues.value
993
+ && props.segmentValues.value.minute !== null
994
+ && props.step.value.minute
995
+ && props.step.value.minute > 1
996
+ ) {
997
+ props.segmentValues.value.minute = snapValueToStep({
998
+ value: props.segmentValues.value.minute,
999
+ min: 0,
1000
+ max: 59,
1001
+ step: props.step.value.minute,
1002
+ });
1003
+ } else if (
1004
+ props.part === 'second'
1005
+ && 'second' in props.segmentValues.value
1006
+ && props.segmentValues.value.second !== null
1007
+ && props.step.value.second
1008
+ && props.step.value.second > 1
1009
+ ) {
1010
+ props.segmentValues.value.second = snapValueToStep({
1011
+ value: props.segmentValues.value.second,
1012
+ min: 0,
1013
+ max: 59,
1014
+ step: props.step.value.second,
1015
+ });
1016
+ }
1017
+
1018
+ if (Object.values(props.segmentValues.value).every((item) => item !== null)) {
1019
+ const dateRef = props.placeholder.value.set({ ...props.segmentValues.value as Record<AnyExceptLiteral, number> });
1020
+ props.modelValue.value = dateRef.copy();
1021
+ }
1022
+ }
1023
+
938
1024
  return {
939
1025
  handleSegmentClick,
940
1026
  handleSegmentKeydown,
1027
+ handleSegmentFocusOut,
941
1028
  attributes,
942
1029
  };
943
1030
  }
@@ -38,7 +38,7 @@ export function useGraceArea(
38
38
  point: exitPoint,
39
39
  rect: currentTarget.getBoundingClientRect(),
40
40
  });
41
- const paddedExitPoints = getPaddedExitPoints(exitPoint, exitSide);
41
+ const paddedExitPoints = getPaddedExitPoints(exitPoint, exitSide, 1);
42
42
  const hoverTargetPoints = getPointsFromRect(hoverTarget.getBoundingClientRect());
43
43
  const graceArea = getHull([...paddedExitPoints, ...hoverTargetPoints]);
44
44
  pointerGraceArea.value = graceArea;
@@ -23,6 +23,7 @@ const lastKeyZero = ref(false);
23
23
  const {
24
24
  handleSegmentClick,
25
25
  handleSegmentKeydown,
26
+ handleSegmentFocusOut,
26
27
  attributes,
27
28
  } = useDateField({
28
29
  hasLeftFocus,
@@ -30,6 +31,7 @@ const {
30
31
  placeholder: rootContext.placeholder,
31
32
  hourCycle: rootContext.hourCycle,
32
33
  step: rootContext.step,
34
+ stepSnapping: rootContext.stepSnapping,
33
35
  segmentValues: rootContext.segmentValues,
34
36
  formatter: rootContext.formatter,
35
37
  part: props.part,
@@ -59,9 +61,12 @@ const isInvalid = computed(() => rootContext.isInvalid.value);
59
61
  v-on="part !== 'literal' ? {
60
62
  mousedown: handleSegmentClick,
61
63
  keydown: handleSegmentKeydown,
62
- focusout: () => { hasLeftFocus = true },
64
+ focusout: () => {
65
+ hasLeftFocus = true;
66
+ handleSegmentFocusOut();
67
+ },
63
68
  focusin: (event: FocusEvent) => {
64
- rootContext.setFocusedElement(event.target as HTMLElement)
69
+ rootContext.setFocusedElement(event.target as HTMLElement);
65
70
  },
66
71
  } : {}"
67
72
  >
@@ -1,6 +1,5 @@
1
1
  <script lang="ts">
2
2
  import type { DateValue } from '@internationalized/date';
3
-
4
3
  import type { Ref } from 'vue';
5
4
  import type { APrimitiveProps } from '../primitive';
6
5
  import type { UseDateFormatter } from '../shared';
@@ -35,6 +34,7 @@ type TimeFieldRootContext = {
35
34
  formatter: UseDateFormatter;
36
35
  hourCycle: HourCycle;
37
36
  step: Ref<DateStep>;
37
+ stepSnapping: Ref<boolean>;
38
38
  segmentValues: Ref<SegmentValueObj>;
39
39
  segmentContents: Ref<Array<{ part: SegmentPart; value: string }>>;
40
40
  elements: Ref<Set<HTMLElement>>;
@@ -55,6 +55,8 @@ export interface ATimeFieldRootProps extends APrimitiveProps, FormFieldProps {
55
55
  hourCycle?: HourCycle;
56
56
  /** The stepping interval for the time fields. Defaults to `1`. */
57
57
  step?: DateStep;
58
+ /** Whether to enforce snapping the value to the nearest step increment after input. Defaults to `false`. */
59
+ stepSnapping?: boolean;
58
60
  /** The granularity to use for formatting times. Defaults to minute if a Time is provided, otherwise defaults to minute. The field will render segments for each part of the date up to and including the specified granularity */
59
61
  granularity?: 'hour' | 'minute' | 'second';
60
62
  /** Whether or not to hide the time zone segment of the field */
@@ -110,7 +112,9 @@ const props = withDefaults(defineProps<ATimeFieldRootProps>(), {
110
112
  readonly: false,
111
113
  placeholder: undefined,
112
114
  isDateUnavailable: undefined,
115
+ stepSnapping: false,
113
116
  });
117
+
114
118
  const emits = defineEmits<ATimeFieldRootEmits>();
115
119
  defineSlots<{
116
120
  default?: (props: {
@@ -123,7 +127,17 @@ defineSlots<{
123
127
  }) => any;
124
128
  }>();
125
129
 
126
- const { disabled, readonly, granularity, defaultValue, minValue, maxValue, dir: propDir, locale: propLocale } = toRefs(props);
130
+ const {
131
+ disabled,
132
+ readonly,
133
+ granularity,
134
+ defaultValue,
135
+ minValue,
136
+ maxValue,
137
+ stepSnapping,
138
+ dir: propDir,
139
+ locale: propLocale,
140
+ } = toRefs(props);
127
141
  const locale = useLocale(propLocale);
128
142
  const dir = useDirection(propDir);
129
143
 
@@ -227,7 +241,31 @@ const allSegmentContent = computed(() => createContent({
227
241
  isTimeValue: true,
228
242
  }));
229
243
 
230
- const segmentContents = computed(() => allSegmentContent.value.arr);
244
+ const segmentContents = computed(() => {
245
+ const contents = allSegmentContent.value.arr;
246
+
247
+ // Convert hour values for 12-hour display
248
+ if (props.hourCycle === 12) {
249
+ return contents.map((segment) => {
250
+ if (segment.part === 'hour' && 'hour' in segmentValues.value) {
251
+ const hour = segmentValues.value.hour;
252
+ if (hour !== null) {
253
+ let displayHour = hour;
254
+ if (hour === 0) {
255
+ displayHour = 12;
256
+ } else if (hour > 12) {
257
+ displayHour = hour - 12;
258
+ }
259
+
260
+ return { ...segment, value: displayHour.toString() };
261
+ }
262
+ }
263
+ return segment;
264
+ });
265
+ }
266
+
267
+ return contents;
268
+ });
231
269
 
232
270
  const editableSegmentContents = computed(() => segmentContents.value.filter(({ part }) => part !== 'literal'));
233
271
 
@@ -320,6 +358,7 @@ provideTimeFieldRootContext({
320
358
  hourCycle: props.hourCycle,
321
359
  readonly,
322
360
  step,
361
+ stepSnapping,
323
362
  segmentValues,
324
363
  isInvalid,
325
364
  segmentContents: editableSegmentContents,
@@ -3,13 +3,13 @@ import type { Direction } from '../shared/types';
3
3
  import { createContext, getActiveElement, useDirection, useSelectionBehavior, useTypeahead } from '../shared';
4
4
 
5
5
  export interface ATreeRootProps<T = Record<string, any>, U extends Record<string, any> = Record<string, any>, M extends boolean = false> extends APrimitiveProps {
6
- /** The controlled value of the tree. Can be binded with with `v-model`. */
6
+ /** The controlled value of the tree. Can be binded with `v-model`. */
7
7
  modelValue?: M extends true ? Array<U> : U;
8
8
  /** The value of the tree when initially rendered. Use when you do not need to control the state of the tree */
9
9
  defaultValue?: M extends true ? Array<U> : U;
10
10
  /** List of items */
11
11
  items?: Array<T>;
12
- /** The controlled value of the expanded item. Can be binded with with `v-model`. */
12
+ /** The controlled value of the expanded item. Can be binded with `v-model`. */
13
13
  expanded?: Array<string>;
14
14
  /** The value of the expanded tree when initially rendered. Use when you do not need to control the state of the expanded tree */
15
15
  defaultExpanded?: Array<string>;