pixelize-design-library 3.3.0 → 3.3.2

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,39 @@ 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.2] — 2026-11-13
13
+
14
+ ### Fixed
15
+
16
+ - **`Select` (`native={false}`) options were invisible to `getByRole('option')` inside a `Drawer` or `Modal`.** The
17
+ dialog `aria-hidden`s every sibling portal when it opens, the popup's included, so the whole listbox left the
18
+ accessibility tree. The popup now drops that `aria-hidden` while open (only if the trigger itself is not hidden), and
19
+ each row is named by its label alone (`aria-labelledby`), with the `description` as `aria-describedby` — a row with a
20
+ description used to be named `LabelDescription`. Rows from `renderOption` keep their content as the name.
21
+
22
+ - **`DatePicker` masked typing lost or mangled digits.** In an empty field, digits now fill from the first segment
23
+ wherever the click left the caret (typing `24122026` after a click gave `dd/MM/2026`), and a typed separator moves
24
+ on, padding a one-digit segment (`2/1/2026` → `02/01/2026`). Keys arriving faster than a frame stay in the segment
25
+ being typed (retyping a full date could drop into the year and blank the field on commit). `MM` is a month, no longer
26
+ minutes: `0` then `5` gives `05` instead of `01` plus a stray year digit. A day digit above 3 or a month digit above 1
27
+ completes its segment as `0d`; two-digit months clamp to 1–12 and days to 1–31.
28
+ - **`DatePicker` `pickerType="time"` showed one time and saved another.** Fast typing wrote the field a frame late, so
29
+ later keys landed at stale caret positions (`1415` could show `05:10`, or `05:` with the old value kept). The saved
30
+ time now comes from the typed hour and minute rather than re-parsing with `dateFormat`, so a time field given a date
31
+ format (`dd/MM/yyyy`, `hh:mm` without `a`) saves what it shows, and a controlled value shows its time, not its date
32
+ digits.
33
+ - **`DatePicker` datetime masks could not type minutes `00`–`09` or hour `00`.** A first `0` in the minutes jumped to `01`
34
+ and both clamped to 1–60 / 1–24; minutes now take 0–59, 24-hour hours 0–23, 12-hour hours 1–12.
35
+
36
+ ## [3.3.1] — 2026-11-11
37
+
38
+ ### Docs
39
+
40
+ - **One look in every app.** `DESIGN-GUIDE.md` §5a is a swap table from each browser-native or raw-Chakra
41
+ control (`<select>`, `<input>`, `Badge`, `Tooltip`, `Menu`, `useToast`, `window.confirm`, a bordered `Box`)
42
+ to the library component and the props that look right. New code always passes `Select native={false}`;
43
+ the `native` default is unchanged, so no call site moves.
44
+
12
45
  ## [Unreleased]
13
46
 
14
47
  ### Added
@@ -119,6 +119,11 @@ There is now **one** picker. `Select` does both modes off the `native` prop:
119
119
  fully-React popup — searchable, `isMulti` with chips, grouped options, `isClearable`,
120
120
  `onCreate`, `renderOption`, `onLoadMore`, optional windowing via `virtualizeAfter`.
121
121
 
122
+ **New code passes `native={false}`.** The `true` default only exists so existing call sites don't
123
+ change; a native `<select>` next to themed fields is the "two apps" look DESIGN-GUIDE §5a removes.
124
+ Converting an existing call site changes its DOM (`combobox`/`listbox`, no `<option>`), so update
125
+ its tests in the same diff.
126
+
122
127
  `isMulti` always forces the popup — there is no native multi-select — and dev-warns if you
123
128
  also passed `native`.
124
129
 
package/DESIGN-GUIDE.md CHANGED
@@ -141,6 +141,38 @@ icon-only button gets an `aria-label` and a `ToolTip`. Inline or panel busy indi
141
141
  input in `FormControl` + `FormLabel`. In a settings row (title + description left, control right)
142
142
  the row title is the label: `<Text as="label" htmlFor={id}>` pointing at the field's `id`.
143
143
 
144
+ ## 5a. One look everywhere — the swap table
145
+
146
+ A screen that mixes library controls with browser or raw-Chakra ones looks like two apps. Every
147
+ row below has one answer; pass exactly these props and nothing that restates a default.
148
+
149
+ | Instead of | Use | Props that look right |
150
+ | --- | --- | --- |
151
+ | `<select>`, `Select` with no `native` | `Select` | `native={false}` — always; the default `native` renders the browser's own list |
152
+ | `<input>`, Chakra `Input` | `TextInput` | `label`, `helperText`, `errorMessage`; default `outline` |
153
+ | `<input type="number">` | `NumberInput` | — |
154
+ | `<input type="date">` / `"time"` | `DatePicker` / `TimePicker` | — |
155
+ | `<textarea>` | `InputTextArea` | `label` |
156
+ | `<input type="checkbox">` | `Checkbox` | — |
157
+ | `<input type="radio">` | `RadioButtonGroup` + `RadioButton`, or `ChoiceCardGroup` for big choices | — |
158
+ | An on/off checkbox or `Switch` | `ToggleSwitch` | in a settings list, inside `SettingRow` |
159
+ | `<button>`, Chakra `Button` | `Button` / `IconButton` | §5 role table; icon-only gets `aria-label` + `ToolTip` |
160
+ | Chakra `Badge`, a coloured `Box` pill | `StatusTag` for a status, `Tag` otherwise | `Tag variant="subtle" size="sm" tone=…` |
161
+ | `title=""`, Chakra `Tooltip` | `ToolTip` (`OverflowToolTip` for truncated text) | — |
162
+ | Chakra `Menu` for row/page actions | `Dropdown` | — |
163
+ | `Thead`/`Tr`/`Td` data lists | `Table` | `TableRoot` only for a tiny static key/value grid; prefer `DescriptionList` |
164
+ | `window.confirm`, a hand-built confirm `Modal` | `AlertDialog` / `ConfirmDialog` | `tone="danger"` for destructive |
165
+ | `alert()`, Chakra `useToast` | `useToaster().showToast` | `status` |
166
+ | Chakra `Spinner`, "Loading…" text | `Skeletons` shaped like the content; `Spinner` inline | — |
167
+ | A `Box` with border + shadow as a card | `Card` | default `elevated`; `variant="outline"` around a table or row list |
168
+ | A hand-built header row | `PageHeader` | one `solid` action |
169
+ | A blank area when there is no data | `EmptyState` / `QueryStateBoundary` | §7 |
170
+ | Tabs built from buttons | `Tabs` (panels) / `SegmentedControl` (a value) | defaults |
171
+
172
+ Layout and type (`Box`, `Flex`, `Stack`, `Grid`, `Text`, `Heading`, `Divider`) are not swaps — import
173
+ them from `pixelize-design-library` (§8). If a row's library component can't do what the screen
174
+ needs, report the gap rather than falling back to the raw one.
175
+
144
176
  ## 6. Page anatomy
145
177
 
146
178
  ```
@@ -292,7 +324,9 @@ hides its primary; when only one section is empty on a populated page, that sect
292
324
  passthrough at all — the owned component is the only one.
293
325
  - Reaching for `SelectV2` (`@deprecated`), `SearchSelect` or `SelectSearch` (not deprecated, but not the
294
326
  preferred picker) in new work.
295
- One picker now: `Select` (`native={false}` for the themed, searchable, multi popup).
327
+ One picker now: `Select`, always with `native={false}` in new work (the themed popup).
328
+ - Any browser-native control (`<select>`, `<input type="date">`, `<textarea>`, `window.confirm`)
329
+ or raw Chakra twin where §5a names a library component.
296
330
  `Dropdown` is the exception — it is an action menu, not a picker, and is not replaced.
297
331
  - A card inside a card; a border on a content `Card` (it is borderless by default), or any resting
298
332
  shadow heavier than `shadows.card`.
package/README.md CHANGED
@@ -75,6 +75,10 @@ function App() {
75
75
  export default App;
76
76
  ```
77
77
 
78
+ Building screens? Use the library component for every control, never the browser's or Chakra's —
79
+ [DESIGN-GUIDE.md §5a](DESIGN-GUIDE.md#5a-one-look-everywhere--the-swap-table) maps each native
80
+ element to its component and props (e.g. `Select` always takes `native={false}`).
81
+
78
82
  ## Theming and filled surfaces
79
83
 
80
84
  Nine brand presets with light/dark palettes. Wrap your app in `PixelizeThemeProvider` and read tokens
@@ -196,63 +196,30 @@ const getFormatForPickerType = (pickerType, dateFormat) => {
196
196
  }
197
197
  return dateFormat;
198
198
  };
199
- const normalizeTimeBuffer = (tokenChar, rawBuffer, segmentLength, is12Hour) => {
199
+ const normalizeTwoDigitSegment = (buf, firstMax, min, max) => {
200
+ if (buf.length === 1) {
201
+ const d = parseInt(buf, 10);
202
+ return d > firstMax ? { value: `0${d}`, completed: true } : { value: buf, completed: false };
203
+ }
204
+ const n = Math.min(max, Math.max(min, parseInt(buf, 10)));
205
+ return { value: n.toString().padStart(2, "0"), completed: true };
206
+ };
207
+ const normalizeSegmentBuffer = (tokenChar, rawBuffer, segmentLength, is12Hour) => {
200
208
  if (!tokenChar)
201
209
  return { value: rawBuffer, completed: rawBuffer.length >= segmentLength };
202
210
  const t = tokenChar.toLowerCase();
203
211
  const buf = rawBuffer.replace(/\D/g, "").slice(0, segmentLength);
204
- if (segmentLength !== 2) {
212
+ if (segmentLength !== 2 || buf.length === 0) {
205
213
  return { value: buf, completed: buf.length >= segmentLength };
206
214
  }
207
- if (t === "h") {
208
- // const maxHour = is12Hour ? 12 : 24;
209
- if (buf.length === 1) {
210
- const d = parseInt(buf[0], 10);
211
- const firstMax = is12Hour ? 1 : 2;
212
- if (d > firstMax) {
213
- return { value: `0${d}`, completed: true };
214
- }
215
- return { value: buf, completed: false };
216
- }
217
- if (buf.length === 2) {
218
- let h = parseInt(buf, 10);
219
- if (is12Hour) {
220
- if (h < 1)
221
- h = 1;
222
- if (h > 12)
223
- h = 12;
224
- }
225
- else {
226
- if (h < 1)
227
- h = 1;
228
- if (h > 24)
229
- h = 24;
230
- }
231
- const out = h.toString().padStart(2, "0");
232
- return { value: out, completed: true };
233
- }
234
- }
235
- if (t === "m") {
236
- if (buf.length === 1) {
237
- const d = parseInt(buf[0], 10);
238
- if (d > 5) {
239
- return { value: `0${d}`, completed: true };
240
- }
241
- if (d === 0) {
242
- return { value: "01", completed: true };
243
- }
244
- return { value: buf, completed: false };
245
- }
246
- if (buf.length === 2) {
247
- let m = parseInt(buf, 10);
248
- if (m < 1)
249
- m = 1;
250
- if (m > 60)
251
- m = 60;
252
- const out = m.toString().padStart(2, "0");
253
- return { value: out, completed: true };
254
- }
255
- }
215
+ if (tokenChar === "M")
216
+ return normalizeTwoDigitSegment(buf, 1, 1, 12);
217
+ if (t === "d")
218
+ return normalizeTwoDigitSegment(buf, 3, 1, 31);
219
+ if (t === "h")
220
+ return is12Hour ? normalizeTwoDigitSegment(buf, 1, 1, 12) : normalizeTwoDigitSegment(buf, 2, 0, 23);
221
+ if (tokenChar === "m")
222
+ return normalizeTwoDigitSegment(buf, 5, 0, 59);
256
223
  return { value: buf, completed: buf.length >= segmentLength };
257
224
  };
258
225
  function SingleDatePickerInner(props, ref) {
@@ -297,6 +264,7 @@ function SingleDatePickerInner(props, ref) {
297
264
  }
298
265
  return buildFormatSegments(activeFormat);
299
266
  }, [enableMask, activeFormat]);
267
+ const separatorKeys = (0, react_1.useMemo)(() => formatSegments.filter((segment) => segment.type === "literal").map((segment) => segment.placeholder), [formatSegments]);
300
268
  const tokenSegments = (0, react_1.useMemo)(() => (enableMask ? formatSegments.filter((segment) => segment.type === "token") : []), [enableMask, formatSegments]);
301
269
  const maskPlaceholder = (0, react_1.useMemo)(() => {
302
270
  if (!enableMask) {
@@ -565,6 +533,7 @@ function SingleDatePickerInner(props, ref) {
565
533
  setCurrentSegmentIndex(clamped);
566
534
  lastSegmentIndexRef.current = clamped;
567
535
  segmentInputBufferRef.current = "";
536
+ restoreSelectionRef.current = { start: segment.start, end: segment.end };
568
537
  const inputEl = inputRef.current;
569
538
  if (!inputEl)
570
539
  return;
@@ -649,6 +618,7 @@ function SingleDatePickerInner(props, ref) {
649
618
  return isSegmentComplete(segment, segmentValue);
650
619
  });
651
620
  };
621
+ const isMaskEmpty = (value) => !value || value === maskPlaceholder;
652
622
  const computeFinalDate = (parsed) => {
653
623
  if (minDate && (0, date_fns_1.isBefore)(parsed, minDate))
654
624
  return null;
@@ -732,7 +702,9 @@ function SingleDatePickerInner(props, ref) {
732
702
  if (!inputRef.current)
733
703
  return;
734
704
  const caret = (_a = inputRef.current.selectionStart) !== null && _a !== void 0 ? _a : 0;
735
- const index = tokenSegments.findIndex((segment) => caret >= segment.start && caret <= segment.end);
705
+ const index = isMaskEmpty(inputRef.current.value)
706
+ ? 0
707
+ : tokenSegments.findIndex((segment) => caret >= segment.start && caret <= segment.end);
736
708
  if (index >= 0) {
737
709
  requestAnimationFrame(() => selectSegment(index));
738
710
  }
@@ -843,6 +815,47 @@ function SingleDatePickerInner(props, ref) {
843
815
  return;
844
816
  }
845
817
  }
818
+ const isDigit = /^[0-9]$/.test(key);
819
+ if (isDigit || separatorKeys.includes(key)) {
820
+ e.preventDefault();
821
+ const baseValue = ensureMaskValue();
822
+ const buffered = segmentInputBufferRef.current !== "";
823
+ const typingIdx = buffered ? lastSegmentIndexRef.current : isMaskEmpty(baseValue) ? 0 : activeIdx;
824
+ const typingSegment = tokenSegments[typingIdx];
825
+ if (typingSegment.token === "a" || (!isDigit && !buffered))
826
+ return;
827
+ const segmentLength = typingSegment.placeholder.length;
828
+ const buffer = isDigit ? segmentInputBufferRef.current + key : segmentInputBufferRef.current.padStart(segmentLength, "0");
829
+ const { value: activeValue, completed } = normalizeSegmentBuffer(typingSegment.token, buffer, segmentLength, is12Hour);
830
+ const newSegmentValue = activeValue + typingSegment.placeholder.slice(activeValue.length);
831
+ const newValue = baseValue.slice(0, typingSegment.start) + newSegmentValue + baseValue.slice(typingSegment.end);
832
+ setInputValue(newValue);
833
+ setIsTyping(true);
834
+ maskInsertedRef.current = false;
835
+ lastSegmentIndexRef.current = typingIdx;
836
+ updateTempDateFromMask(newValue);
837
+ const inputEl = inputRef.current;
838
+ if (completed) {
839
+ segmentInputBufferRef.current = "";
840
+ const nextIdx = typingIdx + 1;
841
+ if (nextIdx < tokenSegments.length && inputEl) {
842
+ const nextSegment = tokenSegments[nextIdx];
843
+ pendingSegmentNavigationRef.current = nextIdx;
844
+ restoreSelectionRef.current = { start: nextSegment.start, end: nextSegment.end };
845
+ inputEl.value = newValue;
846
+ inputEl.focus();
847
+ inputEl.setSelectionRange(nextSegment.start, nextSegment.end);
848
+ }
849
+ }
850
+ else {
851
+ segmentInputBufferRef.current = activeValue;
852
+ if (inputEl) {
853
+ inputEl.value = newValue;
854
+ inputEl.setSelectionRange(typingSegment.start + activeValue.length, typingSegment.end);
855
+ }
856
+ }
857
+ return;
858
+ }
846
859
  if (((_e = segment.token) === null || _e === void 0 ? void 0 : _e.toLowerCase()) === "a") {
847
860
  const lower = key.toLowerCase();
848
861
  if (lower === "a" || lower === "p") {
@@ -875,48 +888,6 @@ function SingleDatePickerInner(props, ref) {
875
888
  e.preventDefault();
876
889
  return;
877
890
  }
878
- if (/^[0-9]$/.test(key)) {
879
- e.preventDefault();
880
- const baseValue = ensureMaskValue();
881
- const placeholderChars = segment.placeholder.split("");
882
- const buffer = segmentInputBufferRef.current + key;
883
- const normalized = normalizeTimeBuffer(segment.token, buffer, segment.placeholder.length, is12Hour);
884
- const activeValue = normalized.value;
885
- const completed = normalized.completed;
886
- placeholderChars.forEach((_char, idx) => {
887
- if (idx < activeValue.length) {
888
- placeholderChars[idx] = activeValue[idx];
889
- }
890
- });
891
- const newSegmentValue = placeholderChars.join("");
892
- const newValue = baseValue.slice(0, segment.start) + newSegmentValue + baseValue.slice(segment.end);
893
- setInputValue(newValue);
894
- setIsTyping(true);
895
- maskInsertedRef.current = false;
896
- updateTempDateFromMask(newValue);
897
- if (completed) {
898
- segmentInputBufferRef.current = "";
899
- const nextIdx = activeIdx + 1;
900
- if (nextIdx < tokenSegments.length && inputRef.current) {
901
- const nextSegment = tokenSegments[nextIdx];
902
- pendingSegmentNavigationRef.current = nextIdx;
903
- restoreSelectionRef.current = { start: nextSegment.start, end: nextSegment.end };
904
- inputRef.current.value = newValue;
905
- inputRef.current.focus();
906
- inputRef.current.setSelectionRange(nextSegment.start, nextSegment.end);
907
- }
908
- }
909
- else {
910
- segmentInputBufferRef.current = activeValue;
911
- const caretStart = segment.start + activeValue.length;
912
- requestAnimationFrame(() => {
913
- if (inputRef.current) {
914
- inputRef.current.setSelectionRange(caretStart, segment.end);
915
- }
916
- });
917
- }
918
- return;
919
- }
920
891
  if (key === "ArrowUp" || key === "ArrowDown") {
921
892
  e.preventDefault();
922
893
  return;
@@ -91,6 +91,18 @@ const caretFromDigitIndex = (digitIndex, digitsLen) => {
91
91
  return 3;
92
92
  return digitIndex + 1;
93
93
  };
94
+ const pad2 = (n) => n.toString().padStart(2, "0");
95
+ const digitsFromDate = (date, is12Hour) => {
96
+ const hours = date.getHours();
97
+ const displayHour = is12Hour ? (hours % 12 === 0 ? 12 : hours % 12) : hours;
98
+ return `${pad2(displayHour)}${pad2(date.getMinutes())}`;
99
+ };
100
+ const dateFromDigits = (digits, is12Hour, meridiem) => {
101
+ const hour = parseInt(digits.slice(0, 2), 10);
102
+ const hour24 = is12Hour ? (hour % 12) + (meridiem === "PM" ? 12 : 0) : hour;
103
+ const today = new Date();
104
+ return new Date(today.getFullYear(), today.getMonth(), today.getDate(), hour24, parseInt(digits.slice(2, 4), 10), 0, 0);
105
+ };
94
106
  const formatToPlaceholder = (formatStr) => formatStr.replace(/h{1,2}/gi, "HH").replace(/m{1,2}/gi, "mm").replace(/a{1,2}/gi, "AM");
95
107
  /** Masked HH:mm digit input, no seconds; `ref` is the `<input>`. */
96
108
  exports.TimePickerInput = (0, react_1.forwardRef)(function TimePickerInput({ value, onChange, dateFormat, isDisabled: disabled = false, placeholder, id, name, isRequired, describedBy, onFocus, onBlur, error, size = controlSizes_1.DEFAULT_CONTROL_SIZE, }, ref) {
@@ -108,16 +120,15 @@ exports.TimePickerInput = (0, react_1.forwardRef)(function TimePickerInput({ val
108
120
  const is12Hour = (0, react_1.useMemo)(() => /h{1,2}/i.test(dateFormat) && !/H{1,2}/.test(dateFormat), [dateFormat]);
109
121
  const placeholderText = (0, react_1.useMemo)(() => placeholder || formatToPlaceholder(dateFormat), [placeholder, dateFormat]);
110
122
  const ampmRef = (0, react_1.useRef)("AM");
123
+ const typedSinceFocusRef = (0, react_1.useRef)(false);
111
124
  const [ampm, setAmpm] = (0, react_1.useState)("AM");
112
125
  const setInputValueAndCaret = (0, react_1.useCallback)((formatted, caretDigitIndex) => {
113
- requestAnimationFrame(() => {
114
- const el = inputRef.current;
115
- if (!el)
116
- return;
117
- el.value = formatted;
118
- const caretPos = Math.min(caretFromDigitIndex(caretDigitIndex, digitsRef.current.length), formatted.length);
119
- el.setSelectionRange(caretPos, caretPos);
120
- });
126
+ const el = inputRef.current;
127
+ if (!el)
128
+ return;
129
+ el.value = formatted;
130
+ const caretPos = Math.min(caretFromDigitIndex(caretDigitIndex, digitsRef.current.length), formatted.length);
131
+ el.setSelectionRange(caretPos, caretPos);
121
132
  }, []);
122
133
  const applyDigits = (0, react_1.useCallback)((rawDigits, desiredDigitIndex) => {
123
134
  const clamped = adjustDigits(rawDigits, is12Hour);
@@ -128,16 +139,13 @@ exports.TimePickerInput = (0, react_1.forwardRef)(function TimePickerInput({ val
128
139
  const nextDigitIndex = Math.max(0, Math.min(desiredDigitIndex, maxDigitIndex));
129
140
  setInputValueAndCaret(formatted, nextDigitIndex);
130
141
  if (clamped.length === 4) {
131
- const formattedInput = is12Hour ? `${formatted} ${ampmRef.current || "AM"}` : formatted;
132
- const parsed = (0, date_fns_1.parse)(formattedInput, dateFormat, new Date());
133
- if ((0, date_fns_1.isValid)(parsed))
134
- onChange(parsed);
142
+ onChange(dateFromDigits(clamped, is12Hour, ampmRef.current || "AM"));
135
143
  }
136
144
  else if (clamped.length === 0) {
137
145
  onChange(null);
138
146
  }
139
147
  return { digits: clamped, nextDigitIndex };
140
- }, [dateFormat, is12Hour, onChange, setInputValueAndCaret]);
148
+ }, [is12Hour, onChange, setInputValueAndCaret]);
141
149
  const updateAmpmValue = (0, react_1.useCallback)((next) => {
142
150
  if (!is12Hour)
143
151
  return;
@@ -146,9 +154,7 @@ exports.TimePickerInput = (0, react_1.forwardRef)(function TimePickerInput({ val
146
154
  ampmRef.current = upperNext;
147
155
  setAmpm(upperNext);
148
156
  if (digitsRef.current.length === 4) {
149
- const parsed = (0, date_fns_1.parse)(`${formattedDigits} ${upperNext}`, dateFormat, new Date());
150
- if ((0, date_fns_1.isValid)(parsed))
151
- onChange(parsed);
157
+ onChange(dateFromDigits(digitsRef.current, is12Hour, upperNext));
152
158
  }
153
159
  const el = inputRef.current;
154
160
  if (!el)
@@ -159,7 +165,7 @@ exports.TimePickerInput = (0, react_1.forwardRef)(function TimePickerInput({ val
159
165
  else {
160
166
  el.value = formattedDigits ? `${formattedDigits} ${upperNext}` : "";
161
167
  }
162
- }, [dateFormat, is12Hour, onChange]);
168
+ }, [is12Hour, onChange]);
163
169
  const toggleAmpm = (0, react_1.useCallback)(() => {
164
170
  if (!is12Hour)
165
171
  return;
@@ -259,6 +265,8 @@ exports.TimePickerInput = (0, react_1.forwardRef)(function TimePickerInput({ val
259
265
  if (disabled)
260
266
  return;
261
267
  const key = e.key;
268
+ if (/^[0-9]$/.test(key) || key === "Backspace" || key === "Delete")
269
+ typedSinceFocusRef.current = true;
262
270
  if (/^[0-9]$/.test(key)) {
263
271
  e.preventDefault();
264
272
  handleDigitInput(key);
@@ -307,9 +315,10 @@ exports.TimePickerInput = (0, react_1.forwardRef)(function TimePickerInput({ val
307
315
  setIsFocused(true);
308
316
  isFocusedRef.current = true;
309
317
  setActiveSegment("hour");
318
+ typedSinceFocusRef.current = false;
310
319
  requestAnimationFrame(() => {
311
320
  const el = inputRef.current;
312
- if (!el)
321
+ if (!el || typedSinceFocusRef.current)
313
322
  return;
314
323
  el.value = formatDigits(digitsRef.current);
315
324
  el.focus();
@@ -368,8 +377,7 @@ exports.TimePickerInput = (0, react_1.forwardRef)(function TimePickerInput({ val
368
377
  }, [applyDigits]);
369
378
  (0, react_1.useEffect)(() => {
370
379
  if (value) {
371
- const formattedValue = (0, date_fns_1.format)(value, dateFormat);
372
- const newDigits = adjustDigits(formattedValue.replace(/\D/g, ""), is12Hour);
380
+ const newDigits = digitsFromDate(value, is12Hour);
373
381
  digitsRef.current = newDigits;
374
382
  setDigits(newDigits);
375
383
  if (is12Hour) {
@@ -399,7 +407,7 @@ exports.TimePickerInput = (0, react_1.forwardRef)(function TimePickerInput({ val
399
407
  inputRef.current.value = "";
400
408
  }
401
409
  }
402
- }, [value, dateFormat, is12Hour]);
410
+ }, [value, is12Hour]);
403
411
  (0, react_1.useEffect)(() => {
404
412
  const formatted = formatDigits(digits);
405
413
  if (!isFocusedRef.current && inputRef.current) {
@@ -81,6 +81,15 @@ const truncateLabel = (label, max) => max !== undefined && label.length > max ?
81
81
  const asIdSet = (values) => new Set((values !== null && values !== void 0 ? values : []).map((v) => v.toString()));
82
82
  /** Regression-guarded id scheme — tickets e2e (`e2e/tests/helpers/selectV2.ts`) resolves it verbatim. */
83
83
  const optionDomId = (listboxId, id) => `${listboxId}-option-${id.toString().replace(/[^a-zA-Z0-9_-]/g, "-")}`;
84
+ // NOTE: a Drawer/Modal aria-hides sibling portals on open, which hid this popup's options too.
85
+ const unhideFromModal = (popup, trigger) => {
86
+ if (trigger.closest('[aria-hidden="true"]'))
87
+ return;
88
+ for (let node = popup.parentElement; node && !node.contains(trigger); node = node.parentElement) {
89
+ if (node.getAttribute("aria-hidden") === "true" && node.hasAttribute("data-aria-hidden"))
90
+ node.removeAttribute("aria-hidden");
91
+ }
92
+ };
84
93
  const parseRemToPx = (value, fallbackPx) => {
85
94
  const match = /^(\d*\.?\d+)rem$/.exec(value);
86
95
  return match ? parseFloat(match[1]) * 16 : fallbackPx;
@@ -90,7 +99,9 @@ const OptionRow = react_1.default.memo(function OptionRow({ option, index, listb
90
99
  const solidDisabledInk = option.isDisabled ? ink.disabled : null;
91
100
  const checkSlotPx = Math.max(CHECK_SLOT_MIN_PX, spec.iconSize);
92
101
  const checkSlot = ((0, jsx_runtime_1.jsx)(react_2.Box, { as: "span", "aria-hidden": true, display: "inline-flex", justifyContent: "center", flexShrink: 0, width: `${checkSlotPx}px`, children: isSingleSelected ? (0, jsx_runtime_1.jsx)(react_2.Box, { as: lucide_react_1.Check, size: spec.iconSize, color: theme.colors.accentText }) : null }));
93
- return ((0, jsx_runtime_1.jsxs)(react_2.Box, { id: optionDomId(listboxId, option.id), "data-index": index, role: "option", "aria-selected": isSelected, "aria-disabled": option.isDisabled, onMouseEnter: () => onActivate(index), onClick: () => onSelect(option), mx: spec.mx, px: spec.px, py: spec.py, minH: spec.minH, borderRadius: "md", cursor: option.isDisabled ? "not-allowed" : "pointer", display: "flex", alignItems: "center", gap: spec.gap, fontSize: spec.fontSize, fontWeight: (0, optionRowInk_1.optionRowWeight)(isSingleSelected), color: solidDisabledInk !== null && solidDisabledInk !== void 0 ? solidDisabledInk : (isSingleSelected ? ink.selected : ink.rest), bg: (0, selectRowInk_1.selectRowFill)(backgrounds, { isSelected, isActive }), boxShadow: showRing ? (0, selectKeyboardRing_1.keyboardRingShadow)(backgrounds.keyboardRing) : undefined, transition: ROW_TRANSITION, sx: option.isDisabled && !ink.disabled ? { ...(0, motion_2.reducedMotionSx)(), ...DISABLED_CONTENT_SX } : (0, motion_2.reducedMotionSx)(), children: [!isMulti && checkPlacement === "start" ? checkSlot : null, isMulti ? ((0, jsx_runtime_1.jsx)(react_2.Checkbox, { id: `${optionDomId(listboxId, option.id)}-checkbox`, isChecked: isSelected, isDisabled: option.isDisabled, pointerEvents: "none", tabIndex: -1, sx: DECORATIVE_CHECKBOX_SX })) : null, renderOption ? ((0, jsx_runtime_1.jsx)(react_2.Box, { flex: 1, minW: 0, children: renderOption(option, { isSelected, isActive }) })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [option.icon ? ((0, jsx_runtime_1.jsx)(react_2.Box, { as: "span", display: "inline-flex", flexShrink: 0, children: option.icon })) : null, (0, jsx_runtime_1.jsxs)(react_2.Box, { flex: 1, minW: 0, isTruncated: true, children: [(0, jsx_runtime_1.jsx)(react_2.Box, { as: "span", isTruncated: true, children: option.label }), option.description ? ((0, jsx_runtime_1.jsx)(react_2.Box, { as: "span", display: "block", fontSize: spec.descriptionFontSize, color: solidDisabledInk !== null && solidDisabledInk !== void 0 ? solidDisabledInk : ink.description, isTruncated: true, children: option.description })) : null] })] })), renderOptionEnd ? ((0, jsx_runtime_1.jsx)(react_2.Box, { as: "span", display: "inline-flex", flexShrink: 0, children: renderOptionEnd(option, { isSelected, isActive }) })) : null, optionAction ? ((0, jsx_runtime_1.jsx)(react_2.Box, { as: "span", "aria-hidden": true, title: optionAction.label, onMouseDown: (event) => event.preventDefault(), onClick: (event) => {
102
+ const rowId = optionDomId(listboxId, option.id);
103
+ const hasOwnText = !renderOption;
104
+ return ((0, jsx_runtime_1.jsxs)(react_2.Box, { id: rowId, "data-index": index, role: "option", "aria-labelledby": hasOwnText ? `${rowId}-label` : undefined, "aria-describedby": hasOwnText && option.description ? `${rowId}-description` : undefined, "aria-selected": isSelected, "aria-disabled": option.isDisabled, onMouseEnter: () => onActivate(index), onClick: () => onSelect(option), mx: spec.mx, px: spec.px, py: spec.py, minH: spec.minH, borderRadius: "md", cursor: option.isDisabled ? "not-allowed" : "pointer", display: "flex", alignItems: "center", gap: spec.gap, fontSize: spec.fontSize, fontWeight: (0, optionRowInk_1.optionRowWeight)(isSingleSelected), color: solidDisabledInk !== null && solidDisabledInk !== void 0 ? solidDisabledInk : (isSingleSelected ? ink.selected : ink.rest), bg: (0, selectRowInk_1.selectRowFill)(backgrounds, { isSelected, isActive }), boxShadow: showRing ? (0, selectKeyboardRing_1.keyboardRingShadow)(backgrounds.keyboardRing) : undefined, transition: ROW_TRANSITION, sx: option.isDisabled && !ink.disabled ? { ...(0, motion_2.reducedMotionSx)(), ...DISABLED_CONTENT_SX } : (0, motion_2.reducedMotionSx)(), children: [!isMulti && checkPlacement === "start" ? checkSlot : null, isMulti ? ((0, jsx_runtime_1.jsx)(react_2.Checkbox, { id: `${rowId}-checkbox`, isChecked: isSelected, isDisabled: option.isDisabled, pointerEvents: "none", tabIndex: -1, sx: DECORATIVE_CHECKBOX_SX })) : null, renderOption ? ((0, jsx_runtime_1.jsx)(react_2.Box, { flex: 1, minW: 0, children: renderOption(option, { isSelected, isActive }) })) : ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [option.icon ? ((0, jsx_runtime_1.jsx)(react_2.Box, { as: "span", display: "inline-flex", flexShrink: 0, children: option.icon })) : null, (0, jsx_runtime_1.jsxs)(react_2.Box, { flex: 1, minW: 0, isTruncated: true, children: [(0, jsx_runtime_1.jsx)(react_2.Box, { as: "span", id: `${rowId}-label`, isTruncated: true, children: option.label }), option.description ? ((0, jsx_runtime_1.jsx)(react_2.Box, { as: "span", id: `${rowId}-description`, display: "block", fontSize: spec.descriptionFontSize, color: solidDisabledInk !== null && solidDisabledInk !== void 0 ? solidDisabledInk : ink.description, isTruncated: true, children: option.description })) : null] })] })), renderOptionEnd ? ((0, jsx_runtime_1.jsx)(react_2.Box, { as: "span", display: "inline-flex", flexShrink: 0, children: renderOptionEnd(option, { isSelected, isActive }) })) : null, optionAction ? ((0, jsx_runtime_1.jsx)(react_2.Box, { as: "span", "aria-hidden": true, title: optionAction.label, onMouseDown: (event) => event.preventDefault(), onClick: (event) => {
94
105
  event.stopPropagation();
95
106
  optionAction.onAction(option);
96
107
  }, display: "inline-flex", alignItems: "center", justifyContent: "center", flexShrink: 0, cursor: "pointer", color: ink.description, _hover: { color: ink.selected }, children: optionAction.icon })) : null, !isMulti && checkPlacement === "end" ? checkSlot : null] }));
@@ -262,6 +273,17 @@ const SelectPopup = (0, react_1.forwardRef)(function SelectPopup(props, ref) {
262
273
  return;
263
274
  setTriggerWidth(node.getBoundingClientRect().width);
264
275
  }, [isOpen]);
276
+ (0, react_1.useEffect)(() => {
277
+ if (!isOpen)
278
+ return;
279
+ const reveal = () => {
280
+ if (listRef.current && triggerRef.current)
281
+ unhideFromModal(listRef.current, triggerRef.current);
282
+ };
283
+ reveal();
284
+ const frame = requestAnimationFrame(reveal);
285
+ return () => cancelAnimationFrame(frame);
286
+ }, [isOpen]);
265
287
  (0, react_1.useEffect)(() => {
266
288
  if (!isOpen || !isSearchable)
267
289
  return;
@@ -157,63 +157,30 @@ const getFormatForPickerType = (pickerType, dateFormat) => {
157
157
  }
158
158
  return dateFormat;
159
159
  };
160
- const normalizeTimeBuffer = (tokenChar, rawBuffer, segmentLength, is12Hour) => {
160
+ const normalizeTwoDigitSegment = (buf, firstMax, min, max) => {
161
+ if (buf.length === 1) {
162
+ const d = parseInt(buf, 10);
163
+ return d > firstMax ? { value: `0${d}`, completed: true } : { value: buf, completed: false };
164
+ }
165
+ const n = Math.min(max, Math.max(min, parseInt(buf, 10)));
166
+ return { value: n.toString().padStart(2, "0"), completed: true };
167
+ };
168
+ const normalizeSegmentBuffer = (tokenChar, rawBuffer, segmentLength, is12Hour) => {
161
169
  if (!tokenChar)
162
170
  return { value: rawBuffer, completed: rawBuffer.length >= segmentLength };
163
171
  const t = tokenChar.toLowerCase();
164
172
  const buf = rawBuffer.replace(/\D/g, "").slice(0, segmentLength);
165
- if (segmentLength !== 2) {
173
+ if (segmentLength !== 2 || buf.length === 0) {
166
174
  return { value: buf, completed: buf.length >= segmentLength };
167
175
  }
168
- if (t === "h") {
169
- // const maxHour = is12Hour ? 12 : 24;
170
- if (buf.length === 1) {
171
- const d = parseInt(buf[0], 10);
172
- const firstMax = is12Hour ? 1 : 2;
173
- if (d > firstMax) {
174
- return { value: `0${d}`, completed: true };
175
- }
176
- return { value: buf, completed: false };
177
- }
178
- if (buf.length === 2) {
179
- let h = parseInt(buf, 10);
180
- if (is12Hour) {
181
- if (h < 1)
182
- h = 1;
183
- if (h > 12)
184
- h = 12;
185
- }
186
- else {
187
- if (h < 1)
188
- h = 1;
189
- if (h > 24)
190
- h = 24;
191
- }
192
- const out = h.toString().padStart(2, "0");
193
- return { value: out, completed: true };
194
- }
195
- }
196
- if (t === "m") {
197
- if (buf.length === 1) {
198
- const d = parseInt(buf[0], 10);
199
- if (d > 5) {
200
- return { value: `0${d}`, completed: true };
201
- }
202
- if (d === 0) {
203
- return { value: "01", completed: true };
204
- }
205
- return { value: buf, completed: false };
206
- }
207
- if (buf.length === 2) {
208
- let m = parseInt(buf, 10);
209
- if (m < 1)
210
- m = 1;
211
- if (m > 60)
212
- m = 60;
213
- const out = m.toString().padStart(2, "0");
214
- return { value: out, completed: true };
215
- }
216
- }
176
+ if (tokenChar === "M")
177
+ return normalizeTwoDigitSegment(buf, 1, 1, 12);
178
+ if (t === "d")
179
+ return normalizeTwoDigitSegment(buf, 3, 1, 31);
180
+ if (t === "h")
181
+ return is12Hour ? normalizeTwoDigitSegment(buf, 1, 1, 12) : normalizeTwoDigitSegment(buf, 2, 0, 23);
182
+ if (tokenChar === "m")
183
+ return normalizeTwoDigitSegment(buf, 5, 0, 59);
217
184
  return { value: buf, completed: buf.length >= segmentLength };
218
185
  };
219
186
  function SingleDatePickerInner(props, ref) {
@@ -258,6 +225,7 @@ function SingleDatePickerInner(props, ref) {
258
225
  }
259
226
  return buildFormatSegments(activeFormat);
260
227
  }, [enableMask, activeFormat]);
228
+ const separatorKeys = useMemo(() => formatSegments.filter((segment) => segment.type === "literal").map((segment) => segment.placeholder), [formatSegments]);
261
229
  const tokenSegments = useMemo(() => (enableMask ? formatSegments.filter((segment) => segment.type === "token") : []), [enableMask, formatSegments]);
262
230
  const maskPlaceholder = useMemo(() => {
263
231
  if (!enableMask) {
@@ -526,6 +494,7 @@ function SingleDatePickerInner(props, ref) {
526
494
  setCurrentSegmentIndex(clamped);
527
495
  lastSegmentIndexRef.current = clamped;
528
496
  segmentInputBufferRef.current = "";
497
+ restoreSelectionRef.current = { start: segment.start, end: segment.end };
529
498
  const inputEl = inputRef.current;
530
499
  if (!inputEl)
531
500
  return;
@@ -610,6 +579,7 @@ function SingleDatePickerInner(props, ref) {
610
579
  return isSegmentComplete(segment, segmentValue);
611
580
  });
612
581
  };
582
+ const isMaskEmpty = (value) => !value || value === maskPlaceholder;
613
583
  const computeFinalDate = (parsed) => {
614
584
  if (minDate && isBefore(parsed, minDate))
615
585
  return null;
@@ -693,7 +663,9 @@ function SingleDatePickerInner(props, ref) {
693
663
  if (!inputRef.current)
694
664
  return;
695
665
  const caret = (_a = inputRef.current.selectionStart) !== null && _a !== void 0 ? _a : 0;
696
- const index = tokenSegments.findIndex((segment) => caret >= segment.start && caret <= segment.end);
666
+ const index = isMaskEmpty(inputRef.current.value)
667
+ ? 0
668
+ : tokenSegments.findIndex((segment) => caret >= segment.start && caret <= segment.end);
697
669
  if (index >= 0) {
698
670
  requestAnimationFrame(() => selectSegment(index));
699
671
  }
@@ -804,6 +776,47 @@ function SingleDatePickerInner(props, ref) {
804
776
  return;
805
777
  }
806
778
  }
779
+ const isDigit = /^[0-9]$/.test(key);
780
+ if (isDigit || separatorKeys.includes(key)) {
781
+ e.preventDefault();
782
+ const baseValue = ensureMaskValue();
783
+ const buffered = segmentInputBufferRef.current !== "";
784
+ const typingIdx = buffered ? lastSegmentIndexRef.current : isMaskEmpty(baseValue) ? 0 : activeIdx;
785
+ const typingSegment = tokenSegments[typingIdx];
786
+ if (typingSegment.token === "a" || (!isDigit && !buffered))
787
+ return;
788
+ const segmentLength = typingSegment.placeholder.length;
789
+ const buffer = isDigit ? segmentInputBufferRef.current + key : segmentInputBufferRef.current.padStart(segmentLength, "0");
790
+ const { value: activeValue, completed } = normalizeSegmentBuffer(typingSegment.token, buffer, segmentLength, is12Hour);
791
+ const newSegmentValue = activeValue + typingSegment.placeholder.slice(activeValue.length);
792
+ const newValue = baseValue.slice(0, typingSegment.start) + newSegmentValue + baseValue.slice(typingSegment.end);
793
+ setInputValue(newValue);
794
+ setIsTyping(true);
795
+ maskInsertedRef.current = false;
796
+ lastSegmentIndexRef.current = typingIdx;
797
+ updateTempDateFromMask(newValue);
798
+ const inputEl = inputRef.current;
799
+ if (completed) {
800
+ segmentInputBufferRef.current = "";
801
+ const nextIdx = typingIdx + 1;
802
+ if (nextIdx < tokenSegments.length && inputEl) {
803
+ const nextSegment = tokenSegments[nextIdx];
804
+ pendingSegmentNavigationRef.current = nextIdx;
805
+ restoreSelectionRef.current = { start: nextSegment.start, end: nextSegment.end };
806
+ inputEl.value = newValue;
807
+ inputEl.focus();
808
+ inputEl.setSelectionRange(nextSegment.start, nextSegment.end);
809
+ }
810
+ }
811
+ else {
812
+ segmentInputBufferRef.current = activeValue;
813
+ if (inputEl) {
814
+ inputEl.value = newValue;
815
+ inputEl.setSelectionRange(typingSegment.start + activeValue.length, typingSegment.end);
816
+ }
817
+ }
818
+ return;
819
+ }
807
820
  if (((_e = segment.token) === null || _e === void 0 ? void 0 : _e.toLowerCase()) === "a") {
808
821
  const lower = key.toLowerCase();
809
822
  if (lower === "a" || lower === "p") {
@@ -836,48 +849,6 @@ function SingleDatePickerInner(props, ref) {
836
849
  e.preventDefault();
837
850
  return;
838
851
  }
839
- if (/^[0-9]$/.test(key)) {
840
- e.preventDefault();
841
- const baseValue = ensureMaskValue();
842
- const placeholderChars = segment.placeholder.split("");
843
- const buffer = segmentInputBufferRef.current + key;
844
- const normalized = normalizeTimeBuffer(segment.token, buffer, segment.placeholder.length, is12Hour);
845
- const activeValue = normalized.value;
846
- const completed = normalized.completed;
847
- placeholderChars.forEach((_char, idx) => {
848
- if (idx < activeValue.length) {
849
- placeholderChars[idx] = activeValue[idx];
850
- }
851
- });
852
- const newSegmentValue = placeholderChars.join("");
853
- const newValue = baseValue.slice(0, segment.start) + newSegmentValue + baseValue.slice(segment.end);
854
- setInputValue(newValue);
855
- setIsTyping(true);
856
- maskInsertedRef.current = false;
857
- updateTempDateFromMask(newValue);
858
- if (completed) {
859
- segmentInputBufferRef.current = "";
860
- const nextIdx = activeIdx + 1;
861
- if (nextIdx < tokenSegments.length && inputRef.current) {
862
- const nextSegment = tokenSegments[nextIdx];
863
- pendingSegmentNavigationRef.current = nextIdx;
864
- restoreSelectionRef.current = { start: nextSegment.start, end: nextSegment.end };
865
- inputRef.current.value = newValue;
866
- inputRef.current.focus();
867
- inputRef.current.setSelectionRange(nextSegment.start, nextSegment.end);
868
- }
869
- }
870
- else {
871
- segmentInputBufferRef.current = activeValue;
872
- const caretStart = segment.start + activeValue.length;
873
- requestAnimationFrame(() => {
874
- if (inputRef.current) {
875
- inputRef.current.setSelectionRange(caretStart, segment.end);
876
- }
877
- });
878
- }
879
- return;
880
- }
881
852
  if (key === "ArrowUp" || key === "ArrowDown") {
882
853
  e.preventDefault();
883
854
  return;
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { forwardRef, useState, useRef, useEffect, useMemo, useCallback } from "react";
3
3
  import { Box, Input, InputGroup, InputRightElement, useMergeRefs } from "@chakra-ui/react";
4
- import { format, parse, isValid } from "date-fns";
4
+ import { format } from "date-fns";
5
5
  import { ClockIcon } from "lucide-react";
6
6
  import { useCustomTheme } from "../../Theme/useCustomTheme.js";
7
7
  import { DEFAULT_CONTROL_SIZE } from "../../Theme/tokens/primitives/controlSizes.js";
@@ -88,6 +88,18 @@ const caretFromDigitIndex = (digitIndex, digitsLen) => {
88
88
  return 3;
89
89
  return digitIndex + 1;
90
90
  };
91
+ const pad2 = (n) => n.toString().padStart(2, "0");
92
+ const digitsFromDate = (date, is12Hour) => {
93
+ const hours = date.getHours();
94
+ const displayHour = is12Hour ? (hours % 12 === 0 ? 12 : hours % 12) : hours;
95
+ return `${pad2(displayHour)}${pad2(date.getMinutes())}`;
96
+ };
97
+ const dateFromDigits = (digits, is12Hour, meridiem) => {
98
+ const hour = parseInt(digits.slice(0, 2), 10);
99
+ const hour24 = is12Hour ? (hour % 12) + (meridiem === "PM" ? 12 : 0) : hour;
100
+ const today = new Date();
101
+ return new Date(today.getFullYear(), today.getMonth(), today.getDate(), hour24, parseInt(digits.slice(2, 4), 10), 0, 0);
102
+ };
91
103
  const formatToPlaceholder = (formatStr) => formatStr.replace(/h{1,2}/gi, "HH").replace(/m{1,2}/gi, "mm").replace(/a{1,2}/gi, "AM");
92
104
  /** Masked HH:mm digit input, no seconds; `ref` is the `<input>`. */
93
105
  export const TimePickerInput = forwardRef(function TimePickerInput({ value, onChange, dateFormat, isDisabled: disabled = false, placeholder, id, name, isRequired, describedBy, onFocus, onBlur, error, size = DEFAULT_CONTROL_SIZE, }, ref) {
@@ -105,16 +117,15 @@ export const TimePickerInput = forwardRef(function TimePickerInput({ value, onCh
105
117
  const is12Hour = useMemo(() => /h{1,2}/i.test(dateFormat) && !/H{1,2}/.test(dateFormat), [dateFormat]);
106
118
  const placeholderText = useMemo(() => placeholder || formatToPlaceholder(dateFormat), [placeholder, dateFormat]);
107
119
  const ampmRef = useRef("AM");
120
+ const typedSinceFocusRef = useRef(false);
108
121
  const [ampm, setAmpm] = useState("AM");
109
122
  const setInputValueAndCaret = useCallback((formatted, caretDigitIndex) => {
110
- requestAnimationFrame(() => {
111
- const el = inputRef.current;
112
- if (!el)
113
- return;
114
- el.value = formatted;
115
- const caretPos = Math.min(caretFromDigitIndex(caretDigitIndex, digitsRef.current.length), formatted.length);
116
- el.setSelectionRange(caretPos, caretPos);
117
- });
123
+ const el = inputRef.current;
124
+ if (!el)
125
+ return;
126
+ el.value = formatted;
127
+ const caretPos = Math.min(caretFromDigitIndex(caretDigitIndex, digitsRef.current.length), formatted.length);
128
+ el.setSelectionRange(caretPos, caretPos);
118
129
  }, []);
119
130
  const applyDigits = useCallback((rawDigits, desiredDigitIndex) => {
120
131
  const clamped = adjustDigits(rawDigits, is12Hour);
@@ -125,16 +136,13 @@ export const TimePickerInput = forwardRef(function TimePickerInput({ value, onCh
125
136
  const nextDigitIndex = Math.max(0, Math.min(desiredDigitIndex, maxDigitIndex));
126
137
  setInputValueAndCaret(formatted, nextDigitIndex);
127
138
  if (clamped.length === 4) {
128
- const formattedInput = is12Hour ? `${formatted} ${ampmRef.current || "AM"}` : formatted;
129
- const parsed = parse(formattedInput, dateFormat, new Date());
130
- if (isValid(parsed))
131
- onChange(parsed);
139
+ onChange(dateFromDigits(clamped, is12Hour, ampmRef.current || "AM"));
132
140
  }
133
141
  else if (clamped.length === 0) {
134
142
  onChange(null);
135
143
  }
136
144
  return { digits: clamped, nextDigitIndex };
137
- }, [dateFormat, is12Hour, onChange, setInputValueAndCaret]);
145
+ }, [is12Hour, onChange, setInputValueAndCaret]);
138
146
  const updateAmpmValue = useCallback((next) => {
139
147
  if (!is12Hour)
140
148
  return;
@@ -143,9 +151,7 @@ export const TimePickerInput = forwardRef(function TimePickerInput({ value, onCh
143
151
  ampmRef.current = upperNext;
144
152
  setAmpm(upperNext);
145
153
  if (digitsRef.current.length === 4) {
146
- const parsed = parse(`${formattedDigits} ${upperNext}`, dateFormat, new Date());
147
- if (isValid(parsed))
148
- onChange(parsed);
154
+ onChange(dateFromDigits(digitsRef.current, is12Hour, upperNext));
149
155
  }
150
156
  const el = inputRef.current;
151
157
  if (!el)
@@ -156,7 +162,7 @@ export const TimePickerInput = forwardRef(function TimePickerInput({ value, onCh
156
162
  else {
157
163
  el.value = formattedDigits ? `${formattedDigits} ${upperNext}` : "";
158
164
  }
159
- }, [dateFormat, is12Hour, onChange]);
165
+ }, [is12Hour, onChange]);
160
166
  const toggleAmpm = useCallback(() => {
161
167
  if (!is12Hour)
162
168
  return;
@@ -256,6 +262,8 @@ export const TimePickerInput = forwardRef(function TimePickerInput({ value, onCh
256
262
  if (disabled)
257
263
  return;
258
264
  const key = e.key;
265
+ if (/^[0-9]$/.test(key) || key === "Backspace" || key === "Delete")
266
+ typedSinceFocusRef.current = true;
259
267
  if (/^[0-9]$/.test(key)) {
260
268
  e.preventDefault();
261
269
  handleDigitInput(key);
@@ -304,9 +312,10 @@ export const TimePickerInput = forwardRef(function TimePickerInput({ value, onCh
304
312
  setIsFocused(true);
305
313
  isFocusedRef.current = true;
306
314
  setActiveSegment("hour");
315
+ typedSinceFocusRef.current = false;
307
316
  requestAnimationFrame(() => {
308
317
  const el = inputRef.current;
309
- if (!el)
318
+ if (!el || typedSinceFocusRef.current)
310
319
  return;
311
320
  el.value = formatDigits(digitsRef.current);
312
321
  el.focus();
@@ -365,8 +374,7 @@ export const TimePickerInput = forwardRef(function TimePickerInput({ value, onCh
365
374
  }, [applyDigits]);
366
375
  useEffect(() => {
367
376
  if (value) {
368
- const formattedValue = format(value, dateFormat);
369
- const newDigits = adjustDigits(formattedValue.replace(/\D/g, ""), is12Hour);
377
+ const newDigits = digitsFromDate(value, is12Hour);
370
378
  digitsRef.current = newDigits;
371
379
  setDigits(newDigits);
372
380
  if (is12Hour) {
@@ -396,7 +404,7 @@ export const TimePickerInput = forwardRef(function TimePickerInput({ value, onCh
396
404
  inputRef.current.value = "";
397
405
  }
398
406
  }
399
- }, [value, dateFormat, is12Hour]);
407
+ }, [value, is12Hour]);
400
408
  useEffect(() => {
401
409
  const formatted = formatDigits(digits);
402
410
  if (!isFocusedRef.current && inputRef.current) {
@@ -43,6 +43,15 @@ const truncateLabel = (label, max) => max !== undefined && label.length > max ?
43
43
  const asIdSet = (values) => new Set((values !== null && values !== void 0 ? values : []).map((v) => v.toString()));
44
44
  /** Regression-guarded id scheme — tickets e2e (`e2e/tests/helpers/selectV2.ts`) resolves it verbatim. */
45
45
  const optionDomId = (listboxId, id) => `${listboxId}-option-${id.toString().replace(/[^a-zA-Z0-9_-]/g, "-")}`;
46
+ // NOTE: a Drawer/Modal aria-hides sibling portals on open, which hid this popup's options too.
47
+ const unhideFromModal = (popup, trigger) => {
48
+ if (trigger.closest('[aria-hidden="true"]'))
49
+ return;
50
+ for (let node = popup.parentElement; node && !node.contains(trigger); node = node.parentElement) {
51
+ if (node.getAttribute("aria-hidden") === "true" && node.hasAttribute("data-aria-hidden"))
52
+ node.removeAttribute("aria-hidden");
53
+ }
54
+ };
46
55
  const parseRemToPx = (value, fallbackPx) => {
47
56
  const match = /^(\d*\.?\d+)rem$/.exec(value);
48
57
  return match ? parseFloat(match[1]) * 16 : fallbackPx;
@@ -52,7 +61,9 @@ const OptionRow = React.memo(function OptionRow({ option, index, listboxId, isSe
52
61
  const solidDisabledInk = option.isDisabled ? ink.disabled : null;
53
62
  const checkSlotPx = Math.max(CHECK_SLOT_MIN_PX, spec.iconSize);
54
63
  const checkSlot = (_jsx(Box, { as: "span", "aria-hidden": true, display: "inline-flex", justifyContent: "center", flexShrink: 0, width: `${checkSlotPx}px`, children: isSingleSelected ? _jsx(Box, { as: Check, size: spec.iconSize, color: theme.colors.accentText }) : null }));
55
- return (_jsxs(Box, { id: optionDomId(listboxId, option.id), "data-index": index, role: "option", "aria-selected": isSelected, "aria-disabled": option.isDisabled, onMouseEnter: () => onActivate(index), onClick: () => onSelect(option), mx: spec.mx, px: spec.px, py: spec.py, minH: spec.minH, borderRadius: "md", cursor: option.isDisabled ? "not-allowed" : "pointer", display: "flex", alignItems: "center", gap: spec.gap, fontSize: spec.fontSize, fontWeight: optionRowWeight(isSingleSelected), color: solidDisabledInk !== null && solidDisabledInk !== void 0 ? solidDisabledInk : (isSingleSelected ? ink.selected : ink.rest), bg: selectRowFill(backgrounds, { isSelected, isActive }), boxShadow: showRing ? keyboardRingShadow(backgrounds.keyboardRing) : undefined, transition: ROW_TRANSITION, sx: option.isDisabled && !ink.disabled ? { ...reducedMotionSx(), ...DISABLED_CONTENT_SX } : reducedMotionSx(), children: [!isMulti && checkPlacement === "start" ? checkSlot : null, isMulti ? (_jsx(Checkbox, { id: `${optionDomId(listboxId, option.id)}-checkbox`, isChecked: isSelected, isDisabled: option.isDisabled, pointerEvents: "none", tabIndex: -1, sx: DECORATIVE_CHECKBOX_SX })) : null, renderOption ? (_jsx(Box, { flex: 1, minW: 0, children: renderOption(option, { isSelected, isActive }) })) : (_jsxs(_Fragment, { children: [option.icon ? (_jsx(Box, { as: "span", display: "inline-flex", flexShrink: 0, children: option.icon })) : null, _jsxs(Box, { flex: 1, minW: 0, isTruncated: true, children: [_jsx(Box, { as: "span", isTruncated: true, children: option.label }), option.description ? (_jsx(Box, { as: "span", display: "block", fontSize: spec.descriptionFontSize, color: solidDisabledInk !== null && solidDisabledInk !== void 0 ? solidDisabledInk : ink.description, isTruncated: true, children: option.description })) : null] })] })), renderOptionEnd ? (_jsx(Box, { as: "span", display: "inline-flex", flexShrink: 0, children: renderOptionEnd(option, { isSelected, isActive }) })) : null, optionAction ? (_jsx(Box, { as: "span", "aria-hidden": true, title: optionAction.label, onMouseDown: (event) => event.preventDefault(), onClick: (event) => {
64
+ const rowId = optionDomId(listboxId, option.id);
65
+ const hasOwnText = !renderOption;
66
+ return (_jsxs(Box, { id: rowId, "data-index": index, role: "option", "aria-labelledby": hasOwnText ? `${rowId}-label` : undefined, "aria-describedby": hasOwnText && option.description ? `${rowId}-description` : undefined, "aria-selected": isSelected, "aria-disabled": option.isDisabled, onMouseEnter: () => onActivate(index), onClick: () => onSelect(option), mx: spec.mx, px: spec.px, py: spec.py, minH: spec.minH, borderRadius: "md", cursor: option.isDisabled ? "not-allowed" : "pointer", display: "flex", alignItems: "center", gap: spec.gap, fontSize: spec.fontSize, fontWeight: optionRowWeight(isSingleSelected), color: solidDisabledInk !== null && solidDisabledInk !== void 0 ? solidDisabledInk : (isSingleSelected ? ink.selected : ink.rest), bg: selectRowFill(backgrounds, { isSelected, isActive }), boxShadow: showRing ? keyboardRingShadow(backgrounds.keyboardRing) : undefined, transition: ROW_TRANSITION, sx: option.isDisabled && !ink.disabled ? { ...reducedMotionSx(), ...DISABLED_CONTENT_SX } : reducedMotionSx(), children: [!isMulti && checkPlacement === "start" ? checkSlot : null, isMulti ? (_jsx(Checkbox, { id: `${rowId}-checkbox`, isChecked: isSelected, isDisabled: option.isDisabled, pointerEvents: "none", tabIndex: -1, sx: DECORATIVE_CHECKBOX_SX })) : null, renderOption ? (_jsx(Box, { flex: 1, minW: 0, children: renderOption(option, { isSelected, isActive }) })) : (_jsxs(_Fragment, { children: [option.icon ? (_jsx(Box, { as: "span", display: "inline-flex", flexShrink: 0, children: option.icon })) : null, _jsxs(Box, { flex: 1, minW: 0, isTruncated: true, children: [_jsx(Box, { as: "span", id: `${rowId}-label`, isTruncated: true, children: option.label }), option.description ? (_jsx(Box, { as: "span", id: `${rowId}-description`, display: "block", fontSize: spec.descriptionFontSize, color: solidDisabledInk !== null && solidDisabledInk !== void 0 ? solidDisabledInk : ink.description, isTruncated: true, children: option.description })) : null] })] })), renderOptionEnd ? (_jsx(Box, { as: "span", display: "inline-flex", flexShrink: 0, children: renderOptionEnd(option, { isSelected, isActive }) })) : null, optionAction ? (_jsx(Box, { as: "span", "aria-hidden": true, title: optionAction.label, onMouseDown: (event) => event.preventDefault(), onClick: (event) => {
56
67
  event.stopPropagation();
57
68
  optionAction.onAction(option);
58
69
  }, display: "inline-flex", alignItems: "center", justifyContent: "center", flexShrink: 0, cursor: "pointer", color: ink.description, _hover: { color: ink.selected }, children: optionAction.icon })) : null, !isMulti && checkPlacement === "end" ? checkSlot : null] }));
@@ -224,6 +235,17 @@ const SelectPopup = forwardRef(function SelectPopup(props, ref) {
224
235
  return;
225
236
  setTriggerWidth(node.getBoundingClientRect().width);
226
237
  }, [isOpen]);
238
+ useEffect(() => {
239
+ if (!isOpen)
240
+ return;
241
+ const reveal = () => {
242
+ if (listRef.current && triggerRef.current)
243
+ unhideFromModal(listRef.current, triggerRef.current);
244
+ };
245
+ reveal();
246
+ const frame = requestAnimationFrame(reveal);
247
+ return () => cancelAnimationFrame(frame);
248
+ }, [isOpen]);
227
249
  useEffect(() => {
228
250
  if (!isOpen || !isSearchable)
229
251
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pixelize-design-library",
3
- "version": "3.3.0",
3
+ "version": "3.3.2",
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",