bits-ui 1.0.0-next.59 → 1.0.0-next.60

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.
@@ -379,7 +379,7 @@ export class DateFieldRootState {
379
379
  const next = castCb(pVal);
380
380
  this.states.hour.updating = next;
381
381
  if (next !== null && prev.dayPeriod !== null) {
382
- const dayPeriod = this.formatter.dayPeriod(toDate(dateRef.set({ hour: Number.parseInt(next) })));
382
+ const dayPeriod = this.formatter.dayPeriod(toDate(dateRef.set({ hour: Number.parseInt(next) })), this.hourCycle.current);
383
383
  if (dayPeriod === "AM" || dayPeriod === "PM") {
384
384
  prev.dayPeriod = dayPeriod;
385
385
  }
@@ -1278,6 +1278,10 @@ class DateFieldHourSegmentState {
1278
1278
  this.#announcer.announce("12");
1279
1279
  return "12";
1280
1280
  }
1281
+ if (next === 0 && this.#root.hourCycle.current === 24) {
1282
+ this.#announcer.announce("00");
1283
+ return "00";
1284
+ }
1281
1285
  this.#announcer.announce(next);
1282
1286
  return `${next}`;
1283
1287
  });
@@ -1300,6 +1304,10 @@ class DateFieldHourSegmentState {
1300
1304
  this.#announcer.announce("12");
1301
1305
  return "12";
1302
1306
  }
1307
+ if (next === 0 && this.#root.hourCycle.current === 24) {
1308
+ this.#announcer.announce("00");
1309
+ return "00";
1310
+ }
1303
1311
  this.#announcer.announce(next);
1304
1312
  return `${next}`;
1305
1313
  });
@@ -1307,10 +1315,12 @@ class DateFieldHourSegmentState {
1307
1315
  }
1308
1316
  if (isNumberString(e.key)) {
1309
1317
  const num = Number.parseInt(e.key);
1310
- const max = "dayPeriod" in this.#root.segmentValues &&
1311
- this.#root.segmentValues.dayPeriod !== null
1312
- ? 12
1313
- : 23;
1318
+ const max = this.#root.hourCycle.current === 24
1319
+ ? 23
1320
+ : "dayPeriod" in this.#root.segmentValues &&
1321
+ this.#root.segmentValues.dayPeriod !== null
1322
+ ? 12
1323
+ : 23;
1314
1324
  const maxStart = Math.floor(max / 10);
1315
1325
  let moveToNext = false;
1316
1326
  const numIsZero = num === 0;
@@ -1385,6 +1395,15 @@ class DateFieldHourSegmentState {
1385
1395
  this.#root.states.hour.lastKeyZero = false;
1386
1396
  return `0${num}`;
1387
1397
  }
1398
+ /**
1399
+ * If the new number is 0 and the hour cycle is set to 24, then we move
1400
+ * to the next segment, returning the new number with a leading 0.
1401
+ */
1402
+ if (num === 0 && this.#root.hourCycle.current === 24) {
1403
+ moveToNext = true;
1404
+ this.#root.states.hour.lastKeyZero = false;
1405
+ return `0${num}`;
1406
+ }
1388
1407
  /**
1389
1408
  * If the new number is 0, then we simply return the previous value, since
1390
1409
  * they didn't actually type a new number.
@@ -1,3 +1,4 @@
1
+ import type { FocusEventHandler, KeyboardEventHandler, MouseEventHandler } from "svelte/elements";
1
2
  import type { ReadableBoxedValues, WritableBoxedValues } from "../../internal/box.svelte.js";
2
3
  import type { WithRefProps } from "../../internal/types.js";
3
4
  import type { Orientation } from "../../shared/index.js";
@@ -56,10 +57,9 @@ declare class RadioGroupItemState {
56
57
  readonly type: "button";
57
58
  readonly role: "radio";
58
59
  readonly tabindex: number;
59
- readonly onpointerdown: (e: PointerEvent) => void;
60
- readonly onpointerup: (e: PointerEvent) => void;
61
- readonly onkeydown: (e: KeyboardEvent) => void;
62
- readonly onfocus: () => void;
60
+ readonly onkeydown: KeyboardEventHandler<HTMLButtonElement>;
61
+ readonly onfocus: FocusEventHandler<HTMLButtonElement>;
62
+ readonly onclick: MouseEventHandler<HTMLButtonElement>;
63
63
  };
64
64
  }
65
65
  declare class RadioGroupInputState {
@@ -74,21 +74,11 @@ class RadioGroupItemState {
74
74
  this.#tabIndex = this.#root.rovingFocusGroup.getTabIndex(this.#ref.current);
75
75
  });
76
76
  }
77
- #onpointerdown = (e) => {
77
+ #onclick = (e) => {
78
78
  if (this.#disabled.current)
79
79
  return;
80
- if (e.pointerType === "touch")
81
- return e.preventDefault();
82
80
  this.#root.setValue(this.#value.current);
83
81
  };
84
- #onpointerup = (e) => {
85
- if (this.#disabled.current)
86
- return;
87
- if (e.pointerType === "touch") {
88
- e.preventDefault();
89
- this.#root.setValue(this.#value.current);
90
- }
91
- };
92
82
  #onfocus = () => {
93
83
  if (!this.#root.hasValue)
94
84
  return;
@@ -119,10 +109,9 @@ class RadioGroupItemState {
119
109
  role: "radio",
120
110
  tabindex: this.#tabIndex,
121
111
  //
122
- onpointerdown: this.#onpointerdown,
123
- onpointerup: this.#onpointerup,
124
112
  onkeydown: this.#onkeydown,
125
113
  onfocus: this.#onfocus,
114
+ onclick: this.#onclick,
126
115
  }));
127
116
  }
128
117
  //
@@ -54,7 +54,7 @@ function createContentObj(props) {
54
54
  }
55
55
  else if (!isNull(value) && !isNull(intValue)) {
56
56
  const formatted = formatter.part(dateRef.set({ [part]: value }), part, {
57
- hourCycle: props.hourCycle === 24 ? "h24" : undefined,
57
+ hourCycle: props.hourCycle === 24 ? "h23" : undefined,
58
58
  });
59
59
  /**
60
60
  * If we're operating in a 12 hour clock and the part is an hour, we handle
@@ -179,7 +179,7 @@ function getOptsByGranularity(granularity, hourCycle) {
179
179
  minute: "2-digit",
180
180
  second: "2-digit",
181
181
  timeZoneName: "short",
182
- hourCycle: hourCycle === 24 ? "h24" : undefined,
182
+ hourCycle: hourCycle === 24 ? "h23" : undefined,
183
183
  hour12: hourCycle === 24 ? false : undefined,
184
184
  };
185
185
  if (granularity === "day") {
@@ -1,4 +1,5 @@
1
1
  import { type DateValue } from "@internationalized/date";
2
+ import type { HourCycle } from "../../shared/date/types.js";
2
3
  export type Formatter = ReturnType<typeof createFormatter>;
3
4
  /**
4
5
  * Creates a wrapper around the `DateFormatter`, which is
@@ -17,7 +18,7 @@ export declare function createFormatter(initialLocale: string): {
17
18
  toParts: (date: DateValue, options?: Intl.DateTimeFormatOptions) => Intl.DateTimeFormatPart[];
18
19
  custom: (date: Date, options: Intl.DateTimeFormatOptions) => string;
19
20
  part: (dateObj: DateValue, type: Intl.DateTimeFormatPartTypes, options?: Intl.DateTimeFormatOptions) => string;
20
- dayPeriod: (date: Date) => "AM" | "PM";
21
+ dayPeriod: (date: Date, hourCycle?: HourCycle | undefined) => "AM" | "PM";
21
22
  selectedDate: (date: DateValue, includeTime?: boolean) => string;
22
23
  dayOfWeek: (date: Date, length?: Intl.DateTimeFormatOptions["weekday"]) => string;
23
24
  };
@@ -63,10 +63,11 @@ export function createFormatter(initialLocale) {
63
63
  function dayOfWeek(date, length = "narrow") {
64
64
  return new DateFormatter(locale, { weekday: length }).format(date);
65
65
  }
66
- function dayPeriod(date) {
66
+ function dayPeriod(date, hourCycle = undefined) {
67
67
  const parts = new DateFormatter(locale, {
68
68
  hour: "numeric",
69
69
  minute: "numeric",
70
+ hourCycle: hourCycle === 24 ? "h23" : undefined,
70
71
  }).formatToParts(date);
71
72
  const value = parts.find((p) => p.type === "dayPeriod")?.value;
72
73
  if (value === "PM") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bits-ui",
3
- "version": "1.0.0-next.59",
3
+ "version": "1.0.0-next.60",
4
4
  "license": "MIT",
5
5
  "repository": "github:huntabyte/bits-ui",
6
6
  "funding": "https://github.com/sponsors/huntabyte",