pixelize-design-library 3.3.2 → 3.3.3

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/CHANGELOG.md CHANGED
@@ -9,6 +9,21 @@ Found a bug or a gap? Report it as a GitHub issue and track it to closure — se
9
9
  [COMPONENT-GOTCHAS.md](COMPONENT-GOTCHAS.md#found-a-gap-or-a-bug-report-it-then-track-it). A fix's
10
10
  line below names its issue number.
11
11
 
12
+ ## [3.3.3] — 2026-11-13
13
+
14
+ ### Fixed
15
+
16
+ - **`DatePicker` dropped the first digit typed right after focusing an empty field** (`24` became `04`): the
17
+ deferred first-segment select reset the typing buffer. It now skips once a key has been typed.
18
+ - **`DatePicker` select-all + Delete/Backspace cleared only the last segment**, and cut or a programmatic fill
19
+ of `""` was ignored. Both now clear the whole field.
20
+ - **`DatePicker` calendar month and year pickers were browser-native `<select>`s.** They are now the library
21
+ `Select` (`native={false}`), so they match every other field. Tests that drove them with `selectOption` should
22
+ click the `Month` / `Year` combobox and then the option by name.
23
+ - **Opening a dropdown inside another popup closed the outer one.** The one-overlay-at-a-time rule now lets an
24
+ overlay opened from inside another (the month list inside the calendar) keep its parent open, and a picker's
25
+ outside-click check treats a popup its field owns (`aria-controls` / `aria-owns`) as inside.
26
+
12
27
  ## [3.3.2] — 2026-11-13
13
28
 
14
29
  ### Fixed
@@ -9,11 +9,13 @@ const react_1 = require("@chakra-ui/react");
9
9
  const date_fns_1 = require("date-fns");
10
10
  const lucide_react_1 = require("lucide-react");
11
11
  const Button_1 = __importDefault(require("../Button/Button"));
12
+ const Select_1 = __importDefault(require("../Select/Select"));
12
13
  const useCustomTheme_1 = require("../../Theme/useCustomTheme");
13
14
  const filledSurface_1 = require("../../Theme/tokens/builders/filledSurface");
14
- const focusRing_styles_1 = require("../../Theme/chakra/focusRing.styles");
15
15
  const dayStates_1 = require("./dayStates");
16
16
  const motion_1 = require("../../Theme/tokens/primitives/motion");
17
+ const MONTH_OPTIONS = Array.from({ length: 12 }, (_, i) => ({ id: i, label: (0, date_fns_1.format)(new Date(2000, i, 1), "MMMM") }));
18
+ const yearOptions = (thisYear) => Array.from({ length: 100 }, (_, i) => ({ id: thisYear - 50 + i, label: String(thisYear - 50 + i) }));
17
19
  const BACKGROUND_COLOR_TRANSITION = (0, motion_1.transitionFor)(["background", "color"]);
18
20
  /** Internal month grid shared by Single/RangeDatePicker; not published from index.ts, so only reachable via a deep import. */
19
21
  const CalendarPanel = ({ currentMonth, setCurrentMonth, today, isRange, tempDate, tempRangeStart, tempRangeEnd, isSameDay, isBefore, isAfter, minDate, maxDate, disablePastDates, disableFutureDates, disableToday, onDaySelect, hoveredDate, onDayHover, renderWeekdays, dayStates, renderDayContent, }) => {
@@ -29,28 +31,6 @@ const CalendarPanel = ({ currentMonth, setCurrentMonth, today, isRange, tempDate
29
31
  const rangeEnd = tempRangeEnd !== null && tempRangeEnd !== void 0 ? tempRangeEnd : tentativeEnd;
30
32
  const isTentative = !tempRangeEnd && !!tentativeEnd;
31
33
  const hasRange = !!(rangeStart && rangeEnd && !isSameDay(rangeStart, rangeEnd));
32
- const selectStyles = {
33
- border: "1px solid",
34
- // boxborder[500] is the control-outline rung the sibling pickers already use; boxborder[200]
35
- // is decorative and measured 1.85:1 on the dark canvas — the select read as borderless.
36
- borderColor: theme.colors.boxborder[500],
37
- borderRadius: "md",
38
- px: 2,
39
- py: 1,
40
- fontSize: "xs",
41
- fontWeight: 600,
42
- color: theme.colors.text[700],
43
- cursor: "pointer",
44
- bg: theme.colors.background[50],
45
- outline: "none",
46
- _hover: { borderColor: theme.colors.primary[300] },
47
- _focus: { borderColor: theme.colors.primary[500], ...(0, focusRing_styles_1.fieldFocusVisible)(theme.colors) },
48
- style: {
49
- WebkitAppearance: "menulist",
50
- MozAppearance: "menulist",
51
- appearance: "menulist",
52
- },
53
- };
54
34
  const renderDays = () => {
55
35
  var _a;
56
36
  const monthStart = (0, date_fns_1.startOfMonth)(currentMonth);
@@ -139,16 +119,15 @@ const CalendarPanel = ({ currentMonth, setCurrentMonth, today, isRange, tempDate
139
119
  }
140
120
  return rows;
141
121
  };
142
- return ((0, jsx_runtime_1.jsxs)(react_1.Box, { children: [(0, jsx_runtime_1.jsxs)(react_1.Box, { display: "flex", alignItems: "center", justifyContent: "space-between", mb: 2, gap: 1, children: [(0, jsx_runtime_1.jsx)(Button_1.default, { variant: "ghost", size: "xs", sx: { flexShrink: 0 }, onClick: () => setCurrentMonth((prev) => new Date(prev.getFullYear(), prev.getMonth() - 1, 1)), "aria-label": "Previous month", children: (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronLeftIcon, { size: 16 }) }), (0, jsx_runtime_1.jsxs)(react_1.Box, { display: "flex", alignItems: "center", gap: 1.5, minW: 0, children: [(0, jsx_runtime_1.jsx)(react_1.Box, { as: "select", "aria-label": "Month", value: currentMonth.getMonth(), onChange: (e) => {
143
- const newMonth = parseInt(e.target.value, 10);
144
- setCurrentMonth((prev) => new Date(prev.getFullYear(), newMonth, 1));
145
- }, ...selectStyles, children: Array.from({ length: 12 }).map((_, i) => ((0, jsx_runtime_1.jsx)("option", { value: i, children: (0, date_fns_1.format)(new Date(2000, i, 1), "MMMM") }, i))) }), (0, jsx_runtime_1.jsx)(react_1.Box, { as: "select", "aria-label": "Year", value: currentMonth.getFullYear(), onChange: (e) => {
146
- const newYear = parseInt(e.target.value, 10);
147
- setCurrentMonth((prev) => new Date(newYear, prev.getMonth(), 1));
148
- }, ...selectStyles, children: Array.from({ length: 100 }).map((_, i) => {
149
- const year = new Date().getFullYear() - 50 + i;
150
- return ((0, jsx_runtime_1.jsx)("option", { value: year, children: year }, year));
151
- }) })] }), (0, jsx_runtime_1.jsxs)(react_1.Box, { display: "flex", alignItems: "center", gap: 1, flexShrink: 0, children: [!isRange && !isViewingCurrentMonth && ((0, jsx_runtime_1.jsx)(Button_1.default, { variant: "ghost", size: "xs", onClick: () => {
122
+ return ((0, jsx_runtime_1.jsxs)(react_1.Box, { children: [(0, jsx_runtime_1.jsxs)(react_1.Box, { display: "flex", alignItems: "center", justifyContent: "space-between", mb: 2, gap: 1, children: [(0, jsx_runtime_1.jsx)(Button_1.default, { variant: "ghost", size: "xs", sx: { flexShrink: 0 }, onClick: () => setCurrentMonth((prev) => new Date(prev.getFullYear(), prev.getMonth() - 1, 1)), "aria-label": "Previous month", children: (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronLeftIcon, { size: 16 }) }), (0, jsx_runtime_1.jsxs)(react_1.Box, { display: "flex", alignItems: "center", gap: 1.5, minW: 0, children: [(0, jsx_runtime_1.jsx)(Select_1.default, { native: false, size: "xs", width: "7.5rem", "aria-label": "Month", options: MONTH_OPTIONS, value: currentMonth.getMonth(), onChange: (option) => {
123
+ if (option === undefined)
124
+ return;
125
+ setCurrentMonth((prev) => new Date(prev.getFullYear(), Number(option.id), 1));
126
+ } }), (0, jsx_runtime_1.jsx)(Select_1.default, { native: false, size: "xs", width: "5.5rem", "aria-label": "Year", options: yearOptions(new Date().getFullYear()), value: currentMonth.getFullYear(), onChange: (option) => {
127
+ if (option === undefined)
128
+ return;
129
+ setCurrentMonth((prev) => new Date(Number(option.id), prev.getMonth(), 1));
130
+ } })] }), (0, jsx_runtime_1.jsxs)(react_1.Box, { display: "flex", alignItems: "center", gap: 1, flexShrink: 0, children: [!isRange && !isViewingCurrentMonth && ((0, jsx_runtime_1.jsx)(Button_1.default, { variant: "ghost", size: "xs", onClick: () => {
152
131
  setCurrentMonth(() => new Date(today.getFullYear(), today.getMonth(), 1));
153
132
  if (!disableToday) {
154
133
  onDaySelect(new Date(today));
@@ -73,13 +73,13 @@ exports.RangeDatePicker = (0, react_1.forwardRef)(function RangeDatePicker(props
73
73
  const calendarIconPx = (0, textInputIconSize_1.getTextInputIconSizePx)(sizeKey);
74
74
  const calendarIconWrapperSx = (0, textInputIconSize_1.getTextInputIconWrapperSx)(sizeKey);
75
75
  const { isOpen, onOpen, onClose } = (0, react_2.useDisclosure)();
76
- const requestExclusiveOpen = (0, useExclusiveOverlay_1.useExclusiveOverlay)(isOpen, onClose);
76
+ const popoverRef = (0, react_1.useRef)(null);
77
+ const requestExclusiveOpen = (0, useExclusiveOverlay_1.useExclusiveOverlay)(isOpen, onClose, popoverRef);
77
78
  const pickerPortal = (0, PickerPortal_1.usePickerPortal)(isOpen);
78
79
  const calendarLabel = label !== null && label !== void 0 ? label : "Choose date range";
79
80
  const inputRef = (0, react_1.useRef)(null);
80
81
  const mergedInputRef = (0, react_2.useMergeRefs)(inputRef, ref);
81
82
  const triggerRef = (0, react_1.useRef)(null);
82
- const popoverRef = (0, react_1.useRef)(null);
83
83
  const today = new Date();
84
84
  const placeholder = (0, react_1.useMemo)(() => placeholderText || `${dateFormat} - ${dateFormat}`, [placeholderText, dateFormat]);
85
85
  const selectedRange = (_b = (_a = props.value) !== null && _a !== void 0 ? _a : props.selectedDate) !== null && _b !== void 0 ? _b : null;
@@ -232,12 +232,12 @@ function SingleDatePickerInner(props, ref) {
232
232
  const calendarIconPx = (0, textInputIconSize_1.getTextInputIconSizePx)(sizeKey);
233
233
  const calendarIconWrapperSx = (0, textInputIconSize_1.getTextInputIconWrapperSx)(sizeKey);
234
234
  const { isOpen, onOpen, onClose } = (0, react_2.useDisclosure)();
235
- const requestExclusiveOpen = (0, useExclusiveOverlay_1.useExclusiveOverlay)(isOpen, onClose);
235
+ const popoverRef = (0, react_1.useRef)(null);
236
+ const requestExclusiveOpen = (0, useExclusiveOverlay_1.useExclusiveOverlay)(isOpen, onClose, popoverRef);
236
237
  const pickerPortal = (0, PickerPortal_1.usePickerPortal)(isOpen);
237
238
  const calendarLabel = label !== null && label !== void 0 ? label : "Choose date";
238
239
  const inputRef = (0, react_1.useRef)(null);
239
240
  const mergedInputRef = (0, react_2.useMergeRefs)(inputRef, ref);
240
- const popoverRef = (0, react_1.useRef)(null);
241
241
  const triggerRef = (0, react_1.useRef)(null);
242
242
  const resolvedPickerType = pickerType !== null && pickerType !== void 0 ? pickerType : (0, pickerField_1.inferPickerTypeFromFormat)(dateFormat);
243
243
  const resolvedDateFormat = getFormatForPickerType(pickerType, dateFormat);
@@ -285,6 +285,7 @@ function SingleDatePickerInner(props, ref) {
285
285
  const pendingSegmentNavigationRef = (0, react_1.useRef)(null);
286
286
  const restoreSelectionRef = (0, react_1.useRef)(null);
287
287
  const segmentInputBufferRef = (0, react_1.useRef)("");
288
+ const keystrokeSeqRef = (0, react_1.useRef)(0);
288
289
  const maskInsertedRef = (0, react_1.useRef)(false);
289
290
  const today = new Date();
290
291
  const tomorrow = (0, date_fns_1.addDays)(today, 1);
@@ -417,6 +418,8 @@ function SingleDatePickerInner(props, ref) {
417
418
  };
418
419
  const handleInputChange = (e) => {
419
420
  if (enableMask && isMaskActive) {
421
+ if (e.target.value === "")
422
+ clearAllSegments();
420
423
  return;
421
424
  }
422
425
  let value = e.target.value;
@@ -583,6 +586,29 @@ function SingleDatePickerInner(props, ref) {
583
586
  const clamped = Math.max(0, Math.min(tokenSegments.length - 1, nextIndex));
584
587
  selectSegment(clamped);
585
588
  }, [enableMask, selectSegment, tokenSegments.length]);
589
+ const deferSelectSegment = (index) => {
590
+ const seq = keystrokeSeqRef.current;
591
+ requestAnimationFrame(() => {
592
+ if (keystrokeSeqRef.current === seq)
593
+ selectSegment(index);
594
+ });
595
+ };
596
+ const clearAllSegments = () => {
597
+ keystrokeSeqRef.current += 1;
598
+ segmentInputBufferRef.current = "";
599
+ maskInsertedRef.current = true;
600
+ setInputValue(maskPlaceholder);
601
+ setTempDate(null);
602
+ setIsTyping(true);
603
+ const inputEl = inputRef.current;
604
+ if (inputEl && tokenSegments.length > 0) {
605
+ inputEl.value = maskPlaceholder;
606
+ lastSegmentIndexRef.current = 0;
607
+ setCurrentSegmentIndex(0);
608
+ restoreSelectionRef.current = { start: tokenSegments[0].start, end: tokenSegments[0].end };
609
+ inputEl.setSelectionRange(tokenSegments[0].start, tokenSegments[0].end);
610
+ }
611
+ };
586
612
  const getTokenIndexForCaret = (caret, tokens) => {
587
613
  if (tokens.length === 0)
588
614
  return 0;
@@ -688,7 +714,7 @@ function SingleDatePickerInner(props, ref) {
688
714
  maskInsertedRef.current = false;
689
715
  }
690
716
  segmentInputBufferRef.current = "";
691
- requestAnimationFrame(() => selectSegment(0));
717
+ deferSelectSegment(0);
692
718
  };
693
719
  const handleInputClick = (e) => {
694
720
  var _a;
@@ -706,7 +732,7 @@ function SingleDatePickerInner(props, ref) {
706
732
  ? 0
707
733
  : tokenSegments.findIndex((segment) => caret >= segment.start && caret <= segment.end);
708
734
  if (index >= 0) {
709
- requestAnimationFrame(() => selectSegment(index));
735
+ deferSelectSegment(index);
710
736
  }
711
737
  };
712
738
  const handleKeyDown = (e) => {
@@ -799,6 +825,11 @@ function SingleDatePickerInner(props, ref) {
799
825
  }
800
826
  if (key === "Backspace" || key === "Delete") {
801
827
  e.preventDefault();
828
+ if (inputEl && selStart === 0 && selEnd > 0 && selEnd >= inputEl.value.length) {
829
+ clearAllSegments();
830
+ return;
831
+ }
832
+ keystrokeSeqRef.current += 1;
802
833
  const baseValue = ensureMaskValue();
803
834
  const newValue = baseValue.slice(0, segment.start) + segment.placeholder + baseValue.slice(segment.end);
804
835
  setInputValue(newValue);
@@ -806,7 +837,7 @@ function SingleDatePickerInner(props, ref) {
806
837
  maskInsertedRef.current = false;
807
838
  segmentInputBufferRef.current = "";
808
839
  updateTempDateFromMask(newValue);
809
- requestAnimationFrame(() => selectSegment(activeIdx));
840
+ deferSelectSegment(activeIdx);
810
841
  return;
811
842
  }
812
843
  if (e.ctrlKey || e.metaKey) {
@@ -818,6 +849,7 @@ function SingleDatePickerInner(props, ref) {
818
849
  const isDigit = /^[0-9]$/.test(key);
819
850
  if (isDigit || separatorKeys.includes(key)) {
820
851
  e.preventDefault();
852
+ keystrokeSeqRef.current += 1;
821
853
  const baseValue = ensureMaskValue();
822
854
  const buffered = segmentInputBufferRef.current !== "";
823
855
  const typingIdx = buffered ? lastSegmentIndexRef.current : isMaskEmpty(baseValue) ? 0 : activeIdx;
@@ -183,7 +183,7 @@ const SelectPopup = (0, react_1.forwardRef)(function SelectPopup(props, ref) {
183
183
  const handleOpen = () => {
184
184
  if (!isInteractive)
185
185
  return;
186
- requestExclusiveOpen();
186
+ requestExclusiveOpen(triggerRef.current);
187
187
  onFocus === null || onFocus === void 0 ? void 0 : onFocus();
188
188
  onOpen();
189
189
  const firstSelected = props.isMulti
@@ -1,4 +1,7 @@
1
- export declare const exclusiveOpen: (id: string, close: () => void) => void;
1
+ export declare const exclusiveOpen: (id: string, close: () => void, options?: {
2
+ anchor?: Node | null;
3
+ contains?: (node: Node) => boolean;
4
+ }) => void;
2
5
  export declare const exclusiveClose: (id: string) => void;
3
6
  /** Test-only reset — not exported from the package root. */
4
7
  export declare const resetExclusiveOverlay: () => void;
@@ -1,22 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.resetExclusiveOverlay = exports.exclusiveClose = exports.exclusiveOpen = void 0;
4
- let active = null;
5
- const exclusiveOpen = (id, close) => {
6
- if (active && active.id !== id) {
7
- active.close();
4
+ let stack = [];
5
+ const exclusiveOpen = (id, close, options = {}) => {
6
+ var _a;
7
+ stack = stack.filter((entry) => entry.id !== id);
8
+ const { anchor } = options;
9
+ while (stack.length > 0) {
10
+ const top = stack[stack.length - 1];
11
+ if (anchor && ((_a = top.contains) === null || _a === void 0 ? void 0 : _a.call(top, anchor)))
12
+ break;
13
+ stack.pop();
14
+ top.close();
8
15
  }
9
- active = { id, close };
16
+ stack.push({ id, close, contains: options.contains });
10
17
  };
11
18
  exports.exclusiveOpen = exclusiveOpen;
12
19
  const exclusiveClose = (id) => {
13
- if ((active === null || active === void 0 ? void 0 : active.id) === id) {
14
- active = null;
15
- }
20
+ stack = stack.filter((entry) => entry.id !== id);
16
21
  };
17
22
  exports.exclusiveClose = exclusiveClose;
18
23
  /** Test-only reset — not exported from the package root. */
19
24
  const resetExclusiveOverlay = () => {
20
- active = null;
25
+ stack = [];
21
26
  };
22
27
  exports.resetExclusiveOverlay = resetExclusiveOverlay;
@@ -1 +1,2 @@
1
- export declare const useExclusiveOverlay: (isOpen: boolean, onClose: () => void) => () => void;
1
+ import { type RefObject } from "react";
2
+ export declare const useExclusiveOverlay: (isOpen: boolean, onClose: () => void, contentRef?: RefObject<Element | null>) => (anchor?: Node | null) => void;
@@ -4,13 +4,16 @@ exports.useExclusiveOverlay = void 0;
4
4
  const react_1 = require("react");
5
5
  const exclusiveOverlay_1 = require("./exclusiveOverlay");
6
6
  // NOTE: registers with the global dismiss coordinator — call requestOpen() before opening.
7
- const useExclusiveOverlay = (isOpen, onClose) => {
7
+ const useExclusiveOverlay = (isOpen, onClose, contentRef) => {
8
8
  const id = (0, react_1.useId)();
9
9
  const onCloseRef = (0, react_1.useRef)(onClose);
10
10
  onCloseRef.current = onClose;
11
- const requestOpen = (0, react_1.useCallback)(() => {
12
- (0, exclusiveOverlay_1.exclusiveOpen)(id, () => onCloseRef.current());
13
- }, [id]);
11
+ const requestOpen = (0, react_1.useCallback)((anchor) => {
12
+ (0, exclusiveOverlay_1.exclusiveOpen)(id, () => onCloseRef.current(), {
13
+ anchor,
14
+ contains: contentRef ? (node) => { var _a; return Boolean((_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.contains(node)); } : undefined,
15
+ });
16
+ }, [id, contentRef]);
14
17
  (0, react_1.useEffect)(() => {
15
18
  if (!isOpen) {
16
19
  (0, exclusiveOverlay_1.exclusiveClose)(id);
@@ -2,6 +2,19 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.useOutsideMouseDown = void 0;
4
4
  const react_1 = require("react");
5
+ const ownedIds = (root) => Array.from(root.querySelectorAll("[aria-controls], [aria-owns]")).flatMap((el) => { var _a, _b; return `${(_a = el.getAttribute("aria-controls")) !== null && _a !== void 0 ? _a : ""} ${(_b = el.getAttribute("aria-owns")) !== null && _b !== void 0 ? _b : ""}`.split(/\s+/).filter(Boolean); });
6
+ const ownsTarget = (root, target) => {
7
+ if (!root)
8
+ return false;
9
+ const ids = ownedIds(root);
10
+ if (ids.length === 0)
11
+ return false;
12
+ for (let node = target instanceof Element ? target : target.parentElement; node; node = node.parentElement) {
13
+ if (node.id && ids.includes(node.id))
14
+ return true;
15
+ }
16
+ return false;
17
+ };
5
18
  /** Calls `onOutside` for a document `mousedown` outside every ref; a null ref contains nothing. Unlike Chakra's `useOutsideClick` it never waits for `mouseup`. */
6
19
  const useOutsideMouseDown = (refs, onOutside, { enabled = true, capture = false, includeClick = false } = {}) => {
7
20
  const latest = (0, react_1.useRef)({ refs, onOutside });
@@ -13,7 +26,9 @@ const useOutsideMouseDown = (refs, onOutside, { enabled = true, capture = false,
13
26
  return;
14
27
  const handle = (event) => {
15
28
  const target = event.target;
16
- if (latest.current.refs.some((ref) => { var _a; return (_a = ref.current) === null || _a === void 0 ? void 0 : _a.contains(target); }))
29
+ if (!target.isConnected)
30
+ return;
31
+ if (latest.current.refs.some((ref) => { var _a; return ((_a = ref.current) === null || _a === void 0 ? void 0 : _a.contains(target)) || ownsTarget(ref.current, target); }))
17
32
  return;
18
33
  latest.current.onOutside(event);
19
34
  };
@@ -3,11 +3,13 @@ import { Box } from "@chakra-ui/react";
3
3
  import { format, startOfMonth, endOfMonth, startOfWeek, endOfWeek, addDays } from "date-fns";
4
4
  import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
5
5
  import Button from "../Button/Button.js";
6
+ import Select from "../Select/Select.js";
6
7
  import { useCustomTheme } from "../../Theme/useCustomTheme.js";
7
8
  import { resolveFilledSurface } from "../../Theme/tokens/builders/filledSurface.js";
8
- import { fieldFocusVisible } from "../../Theme/chakra/focusRing.styles.js";
9
9
  import { DAY_CLASS, dayAccessibleName, dayStateClassName, resolveDayStateVisual, } from "./dayStates.js";
10
10
  import { transitionFor } from "../../Theme/tokens/primitives/motion.js";
11
+ const MONTH_OPTIONS = Array.from({ length: 12 }, (_, i) => ({ id: i, label: format(new Date(2000, i, 1), "MMMM") }));
12
+ const yearOptions = (thisYear) => Array.from({ length: 100 }, (_, i) => ({ id: thisYear - 50 + i, label: String(thisYear - 50 + i) }));
11
13
  const BACKGROUND_COLOR_TRANSITION = transitionFor(["background", "color"]);
12
14
  /** Internal month grid shared by Single/RangeDatePicker; not published from index.ts, so only reachable via a deep import. */
13
15
  export const CalendarPanel = ({ currentMonth, setCurrentMonth, today, isRange, tempDate, tempRangeStart, tempRangeEnd, isSameDay, isBefore, isAfter, minDate, maxDate, disablePastDates, disableFutureDates, disableToday, onDaySelect, hoveredDate, onDayHover, renderWeekdays, dayStates, renderDayContent, }) => {
@@ -23,28 +25,6 @@ export const CalendarPanel = ({ currentMonth, setCurrentMonth, today, isRange, t
23
25
  const rangeEnd = tempRangeEnd !== null && tempRangeEnd !== void 0 ? tempRangeEnd : tentativeEnd;
24
26
  const isTentative = !tempRangeEnd && !!tentativeEnd;
25
27
  const hasRange = !!(rangeStart && rangeEnd && !isSameDay(rangeStart, rangeEnd));
26
- const selectStyles = {
27
- border: "1px solid",
28
- // boxborder[500] is the control-outline rung the sibling pickers already use; boxborder[200]
29
- // is decorative and measured 1.85:1 on the dark canvas — the select read as borderless.
30
- borderColor: theme.colors.boxborder[500],
31
- borderRadius: "md",
32
- px: 2,
33
- py: 1,
34
- fontSize: "xs",
35
- fontWeight: 600,
36
- color: theme.colors.text[700],
37
- cursor: "pointer",
38
- bg: theme.colors.background[50],
39
- outline: "none",
40
- _hover: { borderColor: theme.colors.primary[300] },
41
- _focus: { borderColor: theme.colors.primary[500], ...fieldFocusVisible(theme.colors) },
42
- style: {
43
- WebkitAppearance: "menulist",
44
- MozAppearance: "menulist",
45
- appearance: "menulist",
46
- },
47
- };
48
28
  const renderDays = () => {
49
29
  var _a;
50
30
  const monthStart = startOfMonth(currentMonth);
@@ -133,16 +113,15 @@ export const CalendarPanel = ({ currentMonth, setCurrentMonth, today, isRange, t
133
113
  }
134
114
  return rows;
135
115
  };
136
- return (_jsxs(Box, { children: [_jsxs(Box, { display: "flex", alignItems: "center", justifyContent: "space-between", mb: 2, gap: 1, children: [_jsx(Button, { variant: "ghost", size: "xs", sx: { flexShrink: 0 }, onClick: () => setCurrentMonth((prev) => new Date(prev.getFullYear(), prev.getMonth() - 1, 1)), "aria-label": "Previous month", children: _jsx(ChevronLeftIcon, { size: 16 }) }), _jsxs(Box, { display: "flex", alignItems: "center", gap: 1.5, minW: 0, children: [_jsx(Box, { as: "select", "aria-label": "Month", value: currentMonth.getMonth(), onChange: (e) => {
137
- const newMonth = parseInt(e.target.value, 10);
138
- setCurrentMonth((prev) => new Date(prev.getFullYear(), newMonth, 1));
139
- }, ...selectStyles, children: Array.from({ length: 12 }).map((_, i) => (_jsx("option", { value: i, children: format(new Date(2000, i, 1), "MMMM") }, i))) }), _jsx(Box, { as: "select", "aria-label": "Year", value: currentMonth.getFullYear(), onChange: (e) => {
140
- const newYear = parseInt(e.target.value, 10);
141
- setCurrentMonth((prev) => new Date(newYear, prev.getMonth(), 1));
142
- }, ...selectStyles, children: Array.from({ length: 100 }).map((_, i) => {
143
- const year = new Date().getFullYear() - 50 + i;
144
- return (_jsx("option", { value: year, children: year }, year));
145
- }) })] }), _jsxs(Box, { display: "flex", alignItems: "center", gap: 1, flexShrink: 0, children: [!isRange && !isViewingCurrentMonth && (_jsx(Button, { variant: "ghost", size: "xs", onClick: () => {
116
+ return (_jsxs(Box, { children: [_jsxs(Box, { display: "flex", alignItems: "center", justifyContent: "space-between", mb: 2, gap: 1, children: [_jsx(Button, { variant: "ghost", size: "xs", sx: { flexShrink: 0 }, onClick: () => setCurrentMonth((prev) => new Date(prev.getFullYear(), prev.getMonth() - 1, 1)), "aria-label": "Previous month", children: _jsx(ChevronLeftIcon, { size: 16 }) }), _jsxs(Box, { display: "flex", alignItems: "center", gap: 1.5, minW: 0, children: [_jsx(Select, { native: false, size: "xs", width: "7.5rem", "aria-label": "Month", options: MONTH_OPTIONS, value: currentMonth.getMonth(), onChange: (option) => {
117
+ if (option === undefined)
118
+ return;
119
+ setCurrentMonth((prev) => new Date(prev.getFullYear(), Number(option.id), 1));
120
+ } }), _jsx(Select, { native: false, size: "xs", width: "5.5rem", "aria-label": "Year", options: yearOptions(new Date().getFullYear()), value: currentMonth.getFullYear(), onChange: (option) => {
121
+ if (option === undefined)
122
+ return;
123
+ setCurrentMonth((prev) => new Date(Number(option.id), prev.getMonth(), 1));
124
+ } })] }), _jsxs(Box, { display: "flex", alignItems: "center", gap: 1, flexShrink: 0, children: [!isRange && !isViewingCurrentMonth && (_jsx(Button, { variant: "ghost", size: "xs", onClick: () => {
146
125
  setCurrentMonth(() => new Date(today.getFullYear(), today.getMonth(), 1));
147
126
  if (!disableToday) {
148
127
  onDaySelect(new Date(today));
@@ -34,13 +34,13 @@ export const RangeDatePicker = forwardRef(function RangeDatePicker(props, ref) {
34
34
  const calendarIconPx = getTextInputIconSizePx(sizeKey);
35
35
  const calendarIconWrapperSx = getTextInputIconWrapperSx(sizeKey);
36
36
  const { isOpen, onOpen, onClose } = useDisclosure();
37
- const requestExclusiveOpen = useExclusiveOverlay(isOpen, onClose);
37
+ const popoverRef = useRef(null);
38
+ const requestExclusiveOpen = useExclusiveOverlay(isOpen, onClose, popoverRef);
38
39
  const pickerPortal = usePickerPortal(isOpen);
39
40
  const calendarLabel = label !== null && label !== void 0 ? label : "Choose date range";
40
41
  const inputRef = useRef(null);
41
42
  const mergedInputRef = useMergeRefs(inputRef, ref);
42
43
  const triggerRef = useRef(null);
43
- const popoverRef = useRef(null);
44
44
  const today = new Date();
45
45
  const placeholder = useMemo(() => placeholderText || `${dateFormat} - ${dateFormat}`, [placeholderText, dateFormat]);
46
46
  const selectedRange = (_b = (_a = props.value) !== null && _a !== void 0 ? _a : props.selectedDate) !== null && _b !== void 0 ? _b : null;
@@ -193,12 +193,12 @@ function SingleDatePickerInner(props, ref) {
193
193
  const calendarIconPx = getTextInputIconSizePx(sizeKey);
194
194
  const calendarIconWrapperSx = getTextInputIconWrapperSx(sizeKey);
195
195
  const { isOpen, onOpen, onClose } = useDisclosure();
196
- const requestExclusiveOpen = useExclusiveOverlay(isOpen, onClose);
196
+ const popoverRef = useRef(null);
197
+ const requestExclusiveOpen = useExclusiveOverlay(isOpen, onClose, popoverRef);
197
198
  const pickerPortal = usePickerPortal(isOpen);
198
199
  const calendarLabel = label !== null && label !== void 0 ? label : "Choose date";
199
200
  const inputRef = useRef(null);
200
201
  const mergedInputRef = useMergeRefs(inputRef, ref);
201
- const popoverRef = useRef(null);
202
202
  const triggerRef = useRef(null);
203
203
  const resolvedPickerType = pickerType !== null && pickerType !== void 0 ? pickerType : inferPickerTypeFromFormat(dateFormat);
204
204
  const resolvedDateFormat = getFormatForPickerType(pickerType, dateFormat);
@@ -246,6 +246,7 @@ function SingleDatePickerInner(props, ref) {
246
246
  const pendingSegmentNavigationRef = useRef(null);
247
247
  const restoreSelectionRef = useRef(null);
248
248
  const segmentInputBufferRef = useRef("");
249
+ const keystrokeSeqRef = useRef(0);
249
250
  const maskInsertedRef = useRef(false);
250
251
  const today = new Date();
251
252
  const tomorrow = addDays(today, 1);
@@ -378,6 +379,8 @@ function SingleDatePickerInner(props, ref) {
378
379
  };
379
380
  const handleInputChange = (e) => {
380
381
  if (enableMask && isMaskActive) {
382
+ if (e.target.value === "")
383
+ clearAllSegments();
381
384
  return;
382
385
  }
383
386
  let value = e.target.value;
@@ -544,6 +547,29 @@ function SingleDatePickerInner(props, ref) {
544
547
  const clamped = Math.max(0, Math.min(tokenSegments.length - 1, nextIndex));
545
548
  selectSegment(clamped);
546
549
  }, [enableMask, selectSegment, tokenSegments.length]);
550
+ const deferSelectSegment = (index) => {
551
+ const seq = keystrokeSeqRef.current;
552
+ requestAnimationFrame(() => {
553
+ if (keystrokeSeqRef.current === seq)
554
+ selectSegment(index);
555
+ });
556
+ };
557
+ const clearAllSegments = () => {
558
+ keystrokeSeqRef.current += 1;
559
+ segmentInputBufferRef.current = "";
560
+ maskInsertedRef.current = true;
561
+ setInputValue(maskPlaceholder);
562
+ setTempDate(null);
563
+ setIsTyping(true);
564
+ const inputEl = inputRef.current;
565
+ if (inputEl && tokenSegments.length > 0) {
566
+ inputEl.value = maskPlaceholder;
567
+ lastSegmentIndexRef.current = 0;
568
+ setCurrentSegmentIndex(0);
569
+ restoreSelectionRef.current = { start: tokenSegments[0].start, end: tokenSegments[0].end };
570
+ inputEl.setSelectionRange(tokenSegments[0].start, tokenSegments[0].end);
571
+ }
572
+ };
547
573
  const getTokenIndexForCaret = (caret, tokens) => {
548
574
  if (tokens.length === 0)
549
575
  return 0;
@@ -649,7 +675,7 @@ function SingleDatePickerInner(props, ref) {
649
675
  maskInsertedRef.current = false;
650
676
  }
651
677
  segmentInputBufferRef.current = "";
652
- requestAnimationFrame(() => selectSegment(0));
678
+ deferSelectSegment(0);
653
679
  };
654
680
  const handleInputClick = (e) => {
655
681
  var _a;
@@ -667,7 +693,7 @@ function SingleDatePickerInner(props, ref) {
667
693
  ? 0
668
694
  : tokenSegments.findIndex((segment) => caret >= segment.start && caret <= segment.end);
669
695
  if (index >= 0) {
670
- requestAnimationFrame(() => selectSegment(index));
696
+ deferSelectSegment(index);
671
697
  }
672
698
  };
673
699
  const handleKeyDown = (e) => {
@@ -760,6 +786,11 @@ function SingleDatePickerInner(props, ref) {
760
786
  }
761
787
  if (key === "Backspace" || key === "Delete") {
762
788
  e.preventDefault();
789
+ if (inputEl && selStart === 0 && selEnd > 0 && selEnd >= inputEl.value.length) {
790
+ clearAllSegments();
791
+ return;
792
+ }
793
+ keystrokeSeqRef.current += 1;
763
794
  const baseValue = ensureMaskValue();
764
795
  const newValue = baseValue.slice(0, segment.start) + segment.placeholder + baseValue.slice(segment.end);
765
796
  setInputValue(newValue);
@@ -767,7 +798,7 @@ function SingleDatePickerInner(props, ref) {
767
798
  maskInsertedRef.current = false;
768
799
  segmentInputBufferRef.current = "";
769
800
  updateTempDateFromMask(newValue);
770
- requestAnimationFrame(() => selectSegment(activeIdx));
801
+ deferSelectSegment(activeIdx);
771
802
  return;
772
803
  }
773
804
  if (e.ctrlKey || e.metaKey) {
@@ -779,6 +810,7 @@ function SingleDatePickerInner(props, ref) {
779
810
  const isDigit = /^[0-9]$/.test(key);
780
811
  if (isDigit || separatorKeys.includes(key)) {
781
812
  e.preventDefault();
813
+ keystrokeSeqRef.current += 1;
782
814
  const baseValue = ensureMaskValue();
783
815
  const buffered = segmentInputBufferRef.current !== "";
784
816
  const typingIdx = buffered ? lastSegmentIndexRef.current : isMaskEmpty(baseValue) ? 0 : activeIdx;
@@ -145,7 +145,7 @@ const SelectPopup = forwardRef(function SelectPopup(props, ref) {
145
145
  const handleOpen = () => {
146
146
  if (!isInteractive)
147
147
  return;
148
- requestExclusiveOpen();
148
+ requestExclusiveOpen(triggerRef.current);
149
149
  onFocus === null || onFocus === void 0 ? void 0 : onFocus();
150
150
  onOpen();
151
151
  const firstSelected = props.isMulti
@@ -1,16 +1,21 @@
1
- let active = null;
2
- export const exclusiveOpen = (id, close) => {
3
- if (active && active.id !== id) {
4
- active.close();
1
+ let stack = [];
2
+ export const exclusiveOpen = (id, close, options = {}) => {
3
+ var _a;
4
+ stack = stack.filter((entry) => entry.id !== id);
5
+ const { anchor } = options;
6
+ while (stack.length > 0) {
7
+ const top = stack[stack.length - 1];
8
+ if (anchor && ((_a = top.contains) === null || _a === void 0 ? void 0 : _a.call(top, anchor)))
9
+ break;
10
+ stack.pop();
11
+ top.close();
5
12
  }
6
- active = { id, close };
13
+ stack.push({ id, close, contains: options.contains });
7
14
  };
8
15
  export const exclusiveClose = (id) => {
9
- if ((active === null || active === void 0 ? void 0 : active.id) === id) {
10
- active = null;
11
- }
16
+ stack = stack.filter((entry) => entry.id !== id);
12
17
  };
13
18
  /** Test-only reset — not exported from the package root. */
14
19
  export const resetExclusiveOverlay = () => {
15
- active = null;
20
+ stack = [];
16
21
  };
@@ -1,13 +1,16 @@
1
1
  import { useCallback, useEffect, useId, useRef } from "react";
2
2
  import { exclusiveClose, exclusiveOpen } from "./exclusiveOverlay.js";
3
3
  // NOTE: registers with the global dismiss coordinator — call requestOpen() before opening.
4
- export const useExclusiveOverlay = (isOpen, onClose) => {
4
+ export const useExclusiveOverlay = (isOpen, onClose, contentRef) => {
5
5
  const id = useId();
6
6
  const onCloseRef = useRef(onClose);
7
7
  onCloseRef.current = onClose;
8
- const requestOpen = useCallback(() => {
9
- exclusiveOpen(id, () => onCloseRef.current());
10
- }, [id]);
8
+ const requestOpen = useCallback((anchor) => {
9
+ exclusiveOpen(id, () => onCloseRef.current(), {
10
+ anchor,
11
+ contains: contentRef ? (node) => { var _a; return Boolean((_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.contains(node)); } : undefined,
12
+ });
13
+ }, [id, contentRef]);
11
14
  useEffect(() => {
12
15
  if (!isOpen) {
13
16
  exclusiveClose(id);
@@ -1,4 +1,17 @@
1
1
  import { useEffect, useRef } from "react";
2
+ const ownedIds = (root) => Array.from(root.querySelectorAll("[aria-controls], [aria-owns]")).flatMap((el) => { var _a, _b; return `${(_a = el.getAttribute("aria-controls")) !== null && _a !== void 0 ? _a : ""} ${(_b = el.getAttribute("aria-owns")) !== null && _b !== void 0 ? _b : ""}`.split(/\s+/).filter(Boolean); });
3
+ const ownsTarget = (root, target) => {
4
+ if (!root)
5
+ return false;
6
+ const ids = ownedIds(root);
7
+ if (ids.length === 0)
8
+ return false;
9
+ for (let node = target instanceof Element ? target : target.parentElement; node; node = node.parentElement) {
10
+ if (node.id && ids.includes(node.id))
11
+ return true;
12
+ }
13
+ return false;
14
+ };
2
15
  /** Calls `onOutside` for a document `mousedown` outside every ref; a null ref contains nothing. Unlike Chakra's `useOutsideClick` it never waits for `mouseup`. */
3
16
  export const useOutsideMouseDown = (refs, onOutside, { enabled = true, capture = false, includeClick = false } = {}) => {
4
17
  const latest = useRef({ refs, onOutside });
@@ -10,7 +23,9 @@ export const useOutsideMouseDown = (refs, onOutside, { enabled = true, capture =
10
23
  return;
11
24
  const handle = (event) => {
12
25
  const target = event.target;
13
- if (latest.current.refs.some((ref) => { var _a; return (_a = ref.current) === null || _a === void 0 ? void 0 : _a.contains(target); }))
26
+ if (!target.isConnected)
27
+ return;
28
+ if (latest.current.refs.some((ref) => { var _a; return ((_a = ref.current) === null || _a === void 0 ? void 0 : _a.contains(target)) || ownsTarget(ref.current, target); }))
14
29
  return;
15
30
  latest.current.onOutside(event);
16
31
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixelize-design-library",
3
- "version": "3.3.2",
3
+ "version": "3.3.3",
4
4
  "description": "React component library for Pixelize apps: themeable Chakra-based components, design tokens and light/dark brand theming.",
5
5
  "keywords": [
6
6
  "react",