@kalyx/react 1.0.0-rc.3 → 1.0.0-rc.4

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/index.d.cts CHANGED
@@ -515,6 +515,9 @@ interface TimePickerAmPmToggleProps extends Omit<HTMLAttributes<HTMLDivElement>,
515
515
  /**
516
516
  * TimePicker.AmPmToggle — AM/PM toggle shown only in 12-hour mode.
517
517
  * Returns null in 24-hour mode.
518
+ *
519
+ * Implements the WAI-ARIA radiogroup pattern: only the checked radio is in the
520
+ * tab order; ArrowLeft/Right/Up/Down + Home/End move selection between radios.
518
521
  */
519
522
  declare function TimePickerAmPmToggle({ classNames, ...props }: TimePickerAmPmToggleProps): react_jsx_runtime.JSX.Element | null;
520
523
 
package/dist/index.d.ts CHANGED
@@ -515,6 +515,9 @@ interface TimePickerAmPmToggleProps extends Omit<HTMLAttributes<HTMLDivElement>,
515
515
  /**
516
516
  * TimePicker.AmPmToggle — AM/PM toggle shown only in 12-hour mode.
517
517
  * Returns null in 24-hour mode.
518
+ *
519
+ * Implements the WAI-ARIA radiogroup pattern: only the checked radio is in the
520
+ * tab order; ArrowLeft/Right/Up/Down + Home/End move selection between radios.
518
521
  */
519
522
  declare function TimePickerAmPmToggle({ classNames, ...props }: TimePickerAmPmToggleProps): react_jsx_runtime.JSX.Element | null;
520
523
 
package/dist/index.js CHANGED
@@ -692,11 +692,15 @@ function DatePickerMonthGrid({
692
692
  ...props
693
693
  }) {
694
694
  const ctx = useDatePickerContext("DatePicker.MonthGrid");
695
- const { adapter, viewMonth, locale } = ctx;
695
+ const { adapter, viewMonth, locale, displayTimezone } = ctx;
696
696
  const currentYear = adapter.getYear(viewMonth);
697
697
  const currentMonth = adapter.getMonth(viewMonth);
698
- const todayMonth = adapter.getMonth(adapter.today());
699
- const todayYear = adapter.getYear(adapter.today());
698
+ const [today, setToday] = useState(null);
699
+ useEffect(() => {
700
+ setToday(adapter.today(displayTimezone));
701
+ }, [adapter, displayTimezone]);
702
+ const todayMonth = today !== null ? adapter.getMonth(today) : -1;
703
+ const todayYear = today !== null ? adapter.getYear(today) : -1;
700
704
  const navigateYear = useCallback(
701
705
  (direction) => {
702
706
  const newDate = adapter.addYears(viewMonth, direction);
@@ -778,9 +782,13 @@ function DatePickerMonthGrid({
778
782
  }
779
783
  function DatePickerYearGrid({ classNames, onSelect, ...props }) {
780
784
  const ctx = useDatePickerContext("DatePicker.YearGrid");
781
- const { adapter, viewMonth } = ctx;
785
+ const { adapter, viewMonth, displayTimezone } = ctx;
782
786
  const currentYear = adapter.getYear(viewMonth);
783
- const todayYear = adapter.getYear(adapter.today());
787
+ const [today, setToday] = useState(null);
788
+ useEffect(() => {
789
+ setToday(adapter.today(displayTimezone));
790
+ }, [adapter, displayTimezone]);
791
+ const todayYear = today !== null ? adapter.getYear(today) : -1;
784
792
  const decadeStart = currentYear - currentYear % 12;
785
793
  const navigateDecade = useCallback(
786
794
  (direction) => {
@@ -934,8 +942,7 @@ function DatePickerPreset({
934
942
  "button",
935
943
  {
936
944
  type: "button",
937
- role: "option",
938
- "aria-selected": isActive,
945
+ "aria-pressed": isActive,
939
946
  "data-active": isActive || void 0,
940
947
  disabled: ctx.isDisabled,
941
948
  onClick: handleClick,
@@ -1427,7 +1434,6 @@ function RangePickerCalendar({
1427
1434
  ref: gridRef,
1428
1435
  role: "grid",
1429
1436
  "aria-label": title,
1430
- "aria-multiselectable": "true",
1431
1437
  "aria-rowcount": weeks.length + 1,
1432
1438
  "aria-colcount": 7,
1433
1439
  className: classNames?.grid,
@@ -1591,8 +1597,7 @@ function RangePickerPreset({
1591
1597
  "button",
1592
1598
  {
1593
1599
  type: "button",
1594
- role: "option",
1595
- "aria-selected": isActive,
1600
+ "aria-pressed": isActive,
1596
1601
  "data-active": isActive || void 0,
1597
1602
  disabled: ctx.isDisabled,
1598
1603
  onClick: handleClick,
@@ -1896,29 +1901,70 @@ function TimePickerMinuteList({ classNames, ...props }) {
1896
1901
  }
1897
1902
  function TimePickerAmPmToggle({ classNames, ...props }) {
1898
1903
  const ctx = useTimePickerContext("TimePicker.AmPmToggle");
1899
- if (ctx.format !== "12h") return null;
1900
- const { period, hours12 } = to12Hour(ctx.currentTime.hours);
1904
+ const amRef = useRef(null);
1905
+ const pmRef = useRef(null);
1901
1906
  const setPeriod = useCallback(
1902
1907
  (newPeriod) => {
1903
1908
  if (ctx.isDisabled || ctx.isReadOnly) return;
1909
+ const { hours12 } = to12Hour(ctx.currentTime.hours);
1904
1910
  const newHours24 = to24Hour(hours12, newPeriod);
1905
1911
  ctx.setTime({ hours: newHours24 });
1906
1912
  },
1907
- [hours12, ctx]
1913
+ [ctx]
1908
1914
  );
1915
+ if (ctx.format !== "12h") return null;
1916
+ const { period } = to12Hour(ctx.currentTime.hours);
1917
+ const focusOther = (target) => {
1918
+ (target === "AM" ? amRef : pmRef).current?.focus();
1919
+ };
1920
+ const handleKeyDown = (e, target) => {
1921
+ switch (e.key) {
1922
+ case "ArrowRight":
1923
+ case "ArrowDown":
1924
+ case "ArrowLeft":
1925
+ case "ArrowUp": {
1926
+ e.preventDefault();
1927
+ const next = target === "AM" ? "PM" : "AM";
1928
+ setPeriod(next);
1929
+ focusOther(next);
1930
+ break;
1931
+ }
1932
+ case "Home": {
1933
+ e.preventDefault();
1934
+ setPeriod("AM");
1935
+ focusOther("AM");
1936
+ break;
1937
+ }
1938
+ case "End": {
1939
+ e.preventDefault();
1940
+ setPeriod("PM");
1941
+ focusOther("PM");
1942
+ break;
1943
+ }
1944
+ case " ":
1945
+ case "Enter": {
1946
+ e.preventDefault();
1947
+ setPeriod(target);
1948
+ break;
1949
+ }
1950
+ }
1951
+ };
1909
1952
  const renderButton = (target) => {
1910
1953
  const isSelected = period === target;
1911
1954
  const optionClass = [classNames?.option, isSelected && classNames?.optionSelected].filter(Boolean).join(" ") || void 0;
1912
1955
  return /* @__PURE__ */ jsx(
1913
1956
  "button",
1914
1957
  {
1958
+ ref: target === "AM" ? amRef : pmRef,
1915
1959
  type: "button",
1916
1960
  role: "radio",
1917
1961
  "aria-checked": isSelected,
1962
+ tabIndex: isSelected ? 0 : -1,
1918
1963
  "data-selected": isSelected || void 0,
1919
1964
  disabled: ctx.isDisabled,
1920
1965
  className: optionClass,
1921
1966
  onClick: () => setPeriod(target),
1967
+ onKeyDown: (e) => handleKeyDown(e, target),
1922
1968
  children: target
1923
1969
  }
1924
1970
  );
@@ -2211,9 +2257,12 @@ function MonthPickerGrid({ classNames, ...props }) {
2211
2257
  return [null, null];
2212
2258
  }
2213
2259
  }, [value, adapter, displayTimezone]);
2214
- const today = adapter.today(displayTimezone);
2215
- const todayYear = adapter.getYear(today);
2216
- const todayMonth = adapter.getMonth(today);
2260
+ const [today, setToday] = useState(null);
2261
+ useEffect(() => {
2262
+ setToday(adapter.today(displayTimezone));
2263
+ }, [adapter, displayTimezone]);
2264
+ const todayYear = today !== null ? adapter.getYear(today) : -1;
2265
+ const todayMonth = today !== null ? adapter.getMonth(today) : -1;
2217
2266
  const navigateYear = useCallback(
2218
2267
  (direction) => {
2219
2268
  ctx.setViewMonth(adapter.addYears(viewMonth, direction));
@@ -2315,7 +2364,11 @@ function YearPickerGrid({ classNames, ...props }) {
2315
2364
  return null;
2316
2365
  }
2317
2366
  }, [value, adapter, displayTimezone]);
2318
- const todayYear = adapter.getYear(adapter.today(displayTimezone));
2367
+ const [today, setToday] = useState(null);
2368
+ useEffect(() => {
2369
+ setToday(adapter.today(displayTimezone));
2370
+ }, [adapter, displayTimezone]);
2371
+ const todayYear = today !== null ? adapter.getYear(today) : -1;
2319
2372
  const navigateDecade = useCallback(
2320
2373
  (direction) => {
2321
2374
  ctx.setViewMonth(adapter.addYears(viewMonth, direction * 12));