@delacour/react-native-ui 0.6.1-alpha.20261104101519 → 0.7.0-alpha.20261104102829

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delacour/react-native-ui",
3
- "version": "0.6.1-alpha.20261104101519",
3
+ "version": "0.7.0-alpha.20261104102829",
4
4
  "description": "React Native UI components — Uniwind, Reanimated, Gesture Handler",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -182,8 +182,8 @@
182
182
  "expo-blur": ">=15",
183
183
  "@maplibre/maplibre-react-native": "^11.5.0",
184
184
  "@central-icons-react-native/round-outlined-radius-1-stroke-1.5": "^1.1",
185
- "@delacour/react-native-bottom-sheet": "0.6.1-alpha.20261104101519",
186
- "@delacour/react-native-charts": "0.6.1-alpha.20261104101519",
185
+ "@delacour/react-native-bottom-sheet": "0.7.0-alpha.20261104102829",
186
+ "@delacour/react-native-charts": "0.7.0-alpha.20261104102829",
187
187
  "@legendapp/list": ">=3.3",
188
188
  "react-native-skia": ">=3.9.0",
189
189
  "expo-linear-gradient": ">=15",
@@ -46,14 +46,24 @@ The subpath imports `BottomSheet`, so an app using it installs the optional
46
46
  asserts the trigger's class is a superset. A picker beside an `Input` is the same box by
47
47
  construction, invalid outranking focus included.
48
48
 
49
+ ## Controlled or not
50
+
51
+ - **Passing `value` controls the picker, even as `undefined`.** `controlledValue` checks
52
+ `"value" in props`, not `value === undefined`, and reads `undefined` as empty. A form field
53
+ starts `undefined` and resets to it; a value test would flip the picker to its own state and keep
54
+ showing a day the form no longer holds. Use `null` (or an empty range or list) for "none".
55
+
49
56
  ## The finish rule
50
57
 
51
58
  - **The sheet closes when the selection is finished, not when it changes.**
52
59
  `resolveShouldClose`: a single day → yes, `null` → no; a range → only with both ends; multiple →
53
60
  never, Done closes it. Closing waits `DATE_PICKER_CLOSE_DELAY` (120 ms) so the filled circle is
54
61
  seen; under calm motion it does not wait, because the pause is there for the eye and reads as
55
- lag otherwise. Every tap cancels the last tap's pending close, so starting a new range or
56
- deselecting the day inside that pause keeps the sheet open.
62
+ lag otherwise. Every tap cancels the last tap's pending close, so starting a new range inside
63
+ that pause keeps the sheet open.
64
+ - **A re-tap on the shown single day confirms it.** The calendar's `applySingleTap` reports it as
65
+ `null`; the picker keeps the day, reports nothing and closes. A user who opens a date of birth to
66
+ check it and taps it must not clear it. Clear (`isClearable`) is the way to empty a single day.
57
67
  - **A half-picked range is never reported.** The first tap is held in `rangeDraft` inside the
58
68
  root; `onValueChange` fires once the range is complete, and on Clear. Dismissing the sheet —
59
69
  swipe, scrim, close, Done, or a controlled `isOpen={false}` — drops the draft and any pending
@@ -77,7 +87,8 @@ The subpath imports `BottomSheet`, so an app using it installs the optional
77
87
  - **Disabled and read-only never open**, from the trigger, a `Field.Label` tap or `open()`. Read-only
78
88
  shows the value at full strength; disabled fades it. Only disabled sets `accessibilityState.disabled`,
79
89
  so a screen reader does not read a read-only value as dimmed. A trigger that cannot open drops the
80
- "Opens calendar" hint, its press handler and its press feedback.
90
+ "Opens calendar" hint, its press handler and its press feedback. Read-only also drops the button
91
+ role and reads as text, so VoiceOver does not offer a double-tap that does nothing.
81
92
  - **`Field` cascade, nearest wins.** `isInvalid ?? field.isInvalid`, `isDisabled ??
82
93
  field.isDisabled` — `??`, so `isInvalid={false}` opts out. The accessible name is
83
94
  `accessibilityLabel ?? field.label ?? "Date"`, and the root registers `open` with the field's
@@ -109,6 +120,27 @@ The subpath imports `BottomSheet`, so an app using it installs the optional
109
120
  which draws the calendar on a card in place and renders no trigger. There is no popover import
110
121
  here and must not be until that merges.
111
122
 
123
+ ## Month bounds
124
+
125
+ - **`defaultMonth`, `startMonth` and `endMonth` pass through to the `Calendar`**, so the default
126
+ anatomy can open near a likely date and bound paging and the year list without a custom
127
+ `DatePicker.Calendar`. Omitted, the calendar derives `startMonth`/`endMonth` from
128
+ `minDate`/`maxDate`, and opens on the selection's month, else today's.
129
+ - **A date of birth sets `maxDate`.** Without it the picker allows future days and the year list
130
+ runs a century ahead:
131
+
132
+ ```tsx
133
+ const now = today();
134
+ <DatePicker
135
+ defaultMonth={{ year: now.year - 30, month: 1, day: 1 }}
136
+ maxDate={addYears(now, -18)}
137
+ minDate={{ year: now.year - 120, month: 1, day: 1 }}
138
+ onValueChange={field.onChange}
139
+ title="Date of birth"
140
+ value={field.value ?? null}
141
+ />
142
+ ```
143
+
112
144
  ## Open questions
113
145
 
114
146
  - A half-picked range is discarded on dismiss. If product wants it kept, commit it from
@@ -31,7 +31,9 @@ export function DatePickerCalendar(props: DatePickerCalendarProps): ReactElement
31
31
  const { calendar, shown, select } = picker;
32
32
  const common = {
33
33
  captionLayout: calendar.captionLayout,
34
+ defaultMonth: calendar.defaultMonth,
34
35
  disabled: calendar.disabled,
36
+ endMonth: calendar.endMonth,
35
37
  isDisabled: picker.isDisabled,
36
38
  isInvalid: picker.isInvalid,
37
39
  isReadOnly: picker.isReadOnly,
@@ -40,6 +42,7 @@ export function DatePickerCalendar(props: DatePickerCalendarProps): ReactElement
40
42
  minDate: calendar.minDate,
41
43
  selectOutsideDays: calendar.selectOutsideDays,
42
44
  size: calendar.size,
45
+ startMonth: calendar.startMonth,
43
46
  today: calendar.today,
44
47
  testID: resolvePartTestID(picker.testID, "calendar"),
45
48
  weekStartsOn: calendar.weekStartsOn,
@@ -17,7 +17,8 @@ export type DatePickerTriggerProps = Omit<PressableProps, "asChild" | "busy" | "
17
17
  *
18
18
  * Only disabled reads as disabled. Read-only shows its value at full strength, so a screen reader
19
19
  * reads it as enabled — but it gets no press feedback, no press handler and no "Opens calendar"
20
- * hint, because it cannot open.
20
+ * hint, because it cannot open. It reads as text, not a button: a button that does nothing on a
21
+ * double-tap is a dead control. Disabled keeps the button role, so it reads as a dimmed button.
21
22
  *
22
23
  * Omitted children are `DatePicker.Value` then `DatePicker.Icon`.
23
24
  */
@@ -38,7 +39,7 @@ export function DatePickerTrigger({
38
39
  <Pressable
39
40
  accessibilityHint={state.canOpen ? accessibilityHint : undefined}
40
41
  accessibilityLabel={picker.accessibilityLabel}
41
- accessibilityRole="button"
42
+ accessibilityRole={state.canOpen || state.isDisabled ? "button" : "text"}
42
43
  accessibilityState={{ disabled: state.isDisabled, expanded: picker.isOpen }}
43
44
  accessibilityValue={{ text: picker.accessibilityValue }}
44
45
  className={resolveDatePickerTriggerClass({
@@ -52,6 +52,9 @@ export type DatePickerContextValue = {
52
52
  size: CalendarSize;
53
53
  minDate: CalendarDate | undefined;
54
54
  maxDate: CalendarDate | undefined;
55
+ defaultMonth: CalendarDate | undefined;
56
+ startMonth: CalendarDate | undefined;
57
+ endMonth: CalendarDate | undefined;
55
58
  disabled: readonly DateMatcher[] | undefined;
56
59
  weekStartsOn: Weekday | "auto";
57
60
  captionLayout: CalendarCaptionLayout;
@@ -84,9 +84,20 @@ describe("DatePicker trigger", () => {
84
84
  expect(onOpenChange).not.toHaveBeenCalled();
85
85
 
86
86
  await rerender(<Picker isReadOnly onOpenChange={onOpenChange} />);
87
- await tap(trigger());
87
+ await tap(screen.getByTestId("stay-trigger"));
88
88
  expect(onOpenChange).not.toHaveBeenCalled();
89
- expect(trigger()).not.toBeExpanded();
89
+ expect(screen.getByTestId("stay-trigger")).not.toBeExpanded();
90
+ });
91
+
92
+ test("a read-only trigger reads as text, not a button it cannot press", async () => {
93
+ await renderWithProviders(<Picker isReadOnly />, { wrapper: Providers });
94
+ expect(screen.queryByRole("button", { name: "Date" })).not.toBeOnTheScreen();
95
+ expect(screen.getByRole("text", { name: "Date" })).toBeEnabled();
96
+ });
97
+
98
+ test("a disabled trigger keeps the button role", async () => {
99
+ await renderWithProviders(<Picker isDisabled />, { wrapper: Providers });
100
+ expect(trigger()).toBeDisabled();
90
101
  });
91
102
  });
92
103
 
@@ -166,6 +177,23 @@ describe("DatePicker single mode", () => {
166
177
  expect(trigger()).not.toBeExpanded();
167
178
  });
168
179
 
180
+ test("a re-tap on the shown day keeps it, reports nothing and closes", async () => {
181
+ const onValueChange = jest.fn();
182
+ const onOpenChange = jest.fn();
183
+ await renderWithProviders(
184
+ <Picker defaultOpen defaultValue={OCT_12} onOpenChange={onOpenChange} onValueChange={onValueChange} />,
185
+ { wrapper: Providers }
186
+ );
187
+
188
+ await tap(day("2026-10-12"));
189
+ expect(day("2026-10-12")).toBeSelected();
190
+ expect(onValueChange).not.toHaveBeenCalled();
191
+
192
+ await settle();
193
+ expect(onOpenChange).toHaveBeenLastCalledWith(false);
194
+ expect(trigger()).toHaveAccessibilityValue({ text: "12 October 2026" });
195
+ });
196
+
169
197
  test("the picked day is announced as selected", async () => {
170
198
  await renderWithProviders(<Picker defaultOpen defaultValue={OCT_12} />, { wrapper: Providers });
171
199
  expect(day("2026-10-12")).toBeSelected();
@@ -197,6 +225,19 @@ describe("DatePicker single mode", () => {
197
225
  expect(day("2026-10-12")).not.toBeSelected();
198
226
  });
199
227
 
228
+ test("passing value keeps it controlled when a form resets it to undefined", async () => {
229
+ const { rerender } = await renderWithProviders(<Picker isOpen value={undefined} />, { wrapper: Providers });
230
+ await tap(day("2026-10-12"));
231
+ expect(day("2026-10-12")).not.toBeSelected();
232
+
233
+ await rerender(<Picker isOpen value={OCT_12} />);
234
+ expect(day("2026-10-12")).toBeSelected();
235
+
236
+ await rerender(<Picker isOpen value={undefined} />);
237
+ expect(day("2026-10-12")).not.toBeSelected();
238
+ expect(trigger()).toHaveAccessibilityValue({ text: "not set" });
239
+ });
240
+
200
241
  test("is not clearable by default; isClearable adds Clear, which empties, reports and stays open", async () => {
201
242
  const onValueChange = jest.fn();
202
243
  const onOpenChange = jest.fn();
@@ -239,6 +280,19 @@ describe("DatePicker single mode", () => {
239
280
  });
240
281
  });
241
282
 
283
+ describe("DatePicker month bounds", () => {
284
+ test("defaultMonth, startMonth and endMonth reach the default calendar", async () => {
285
+ const june1990: CalendarDate = { year: 1990, month: 6, day: 1 };
286
+ await renderWithProviders(
287
+ <Picker defaultMonth={june1990} defaultOpen endMonth={june1990} startMonth={june1990} />,
288
+ { wrapper: Providers }
289
+ );
290
+ expect(day("1990-06-15")).toBeOnTheScreen();
291
+ expect(screen.getByTestId("stay-calendar-prev")).toBeDisabled();
292
+ expect(screen.getByTestId("stay-calendar-next")).toBeDisabled();
293
+ });
294
+ });
295
+
242
296
  describe("DatePicker range mode", () => {
243
297
  test("the first tap is held, only the complete range is reported, then it closes", async () => {
244
298
  const onValueChange = jest.fn();
@@ -30,15 +30,22 @@ import { DatePickerIcon } from "./date-picker-icon";
30
30
  import { DatePickerTrigger } from "./date-picker-trigger";
31
31
  import { DatePickerValue } from "./date-picker-value";
32
32
 
33
- /** The controlled value, as selection state — `undefined` while the caller leaves it uncontrolled. */
33
+ /**
34
+ * The controlled value, as selection state — `undefined` while the caller leaves it uncontrolled.
35
+ *
36
+ * Passing `value` at all makes the picker controlled, even as `undefined`, which reads as empty. A
37
+ * form field starts `undefined` and goes back to it on reset, so a `value === undefined` test would
38
+ * flip the picker to its own state and keep showing a day the form no longer holds.
39
+ */
34
40
  function controlledValue(props: DatePickerSelectionProps): CalendarSelectionState | undefined {
41
+ if (!("value" in props)) return undefined;
35
42
  switch (props.mode) {
36
43
  case "range":
37
- return props.value === undefined ? undefined : { mode: "range", value: props.value };
44
+ return { mode: "range", value: props.value ?? { start: null, end: null } };
38
45
  case "multiple":
39
- return props.value === undefined ? undefined : { mode: "multiple", value: props.value };
46
+ return { mode: "multiple", value: props.value ?? [] };
40
47
  default:
41
- return props.value === undefined ? undefined : { mode: "single", value: props.value };
48
+ return { mode: "single", value: props.value ?? null };
42
49
  }
43
50
  }
44
51
 
@@ -78,6 +85,9 @@ function DatePickerRoot(props: DatePickerProps): ReactElement {
78
85
  captionLayout = "picker",
79
86
  minDate,
80
87
  maxDate,
88
+ defaultMonth,
89
+ startMonth,
90
+ endMonth,
81
91
  disabledDates,
82
92
  selectOutsideDays = false,
83
93
  today,
@@ -189,10 +199,16 @@ function DatePickerRoot(props: DatePickerProps): ReactElement {
189
199
  );
190
200
 
191
201
  // Every tap cancels the last selection's pending close. `finish()` schedules a new one only
192
- // when this selection is complete, so a new range start or a deselect keeps the sheet open.
202
+ // when this selection is complete, so a new range start keeps the sheet open.
203
+ // A single day tapped again is a confirmation, not a clear: the calendar reports it as `null`,
204
+ // but the picker keeps the day and closes. Clearing a single day is Clear's job.
193
205
  const select = useCallback(
194
206
  (next: CalendarSelectionState) => {
195
207
  cancelPendingClose();
208
+ if (next.mode === "single" && next.value === null && value.mode === "single" && value.value !== null) {
209
+ finish(value);
210
+ return;
211
+ }
196
212
  if (next.mode === "range" && !resolveShouldClose(next)) {
197
213
  setRangeDraft(next.value);
198
214
  return;
@@ -201,7 +217,7 @@ function DatePickerRoot(props: DatePickerProps): ReactElement {
201
217
  setValue(next);
202
218
  if (resolveShouldClose(next)) finish(next);
203
219
  },
204
- [cancelPendingClose, finish, setValue]
220
+ [cancelPendingClose, finish, setValue, value]
205
221
  );
206
222
 
207
223
  const clear = useCallback(() => {
@@ -229,11 +245,14 @@ function DatePickerRoot(props: DatePickerProps): ReactElement {
229
245
  accessibilityValue: resolveSelectionAccessibilityValue(shown, locale),
230
246
  calendar: {
231
247
  captionLayout,
248
+ defaultMonth,
232
249
  disabled: disabledDates,
250
+ endMonth,
233
251
  maxDate,
234
252
  minDate,
235
253
  selectOutsideDays,
236
254
  size: calendarSize,
255
+ startMonth,
237
256
  today,
238
257
  weekStartsOn,
239
258
  },
@@ -275,10 +294,12 @@ function DatePickerRoot(props: DatePickerProps): ReactElement {
275
294
  clear,
276
295
  clearLabel,
277
296
  close,
297
+ defaultMonth,
278
298
  description,
279
299
  disabledDates,
280
300
  display,
281
301
  doneLabel,
302
+ endMonth,
282
303
  field?.label,
283
304
  isClearable,
284
305
  isOpen,
@@ -292,6 +313,7 @@ function DatePickerRoot(props: DatePickerProps): ReactElement {
292
313
  select,
293
314
  selectOutsideDays,
294
315
  shown,
316
+ startMonth,
295
317
  testID,
296
318
  title,
297
319
  today,
@@ -365,6 +387,16 @@ function DatePickerRoot(props: DatePickerProps): ReactElement {
365
387
  *
366
388
  * @example
367
389
  * <DatePicker disabledDates={[{ type: "weekday", days: [0, 6] }]} mode="multiple" />
390
+ *
391
+ * @example
392
+ * // A date of birth: no future days, opens near a likely year, the year list bounded.
393
+ * <DatePicker
394
+ * defaultMonth={{ year: today().year - 30, month: 1, day: 1 }}
395
+ * maxDate={addYears(today(), -18)}
396
+ * minDate={{ year: today().year - 120, month: 1, day: 1 }}
397
+ * onValueChange={setDob}
398
+ * value={dob}
399
+ * />
368
400
  */
369
401
  export const DatePicker = Object.assign(DatePickerRoot, {
370
402
  /** The `Input`-shaped control that opens the sheet. Holds the value and the icon unless given children. */
@@ -15,7 +15,10 @@ import type { DatePickerFormat, DatePickerFormatRange, DatePickerPresentation }
15
15
  export type DatePickerSelectionProps =
16
16
  | {
17
17
  mode?: "single";
18
- /** Controlled day. `null` is none. */
18
+ /**
19
+ * Controlled day. `null` is none. Passing the prop at all controls the picker, so a form
20
+ * value that starts or resets to `undefined` reads as none too.
21
+ */
19
22
  value?: CalendarDate | null;
20
23
  /** Starting day while uncontrolled. */
21
24
  defaultValue?: CalendarDate | null;
@@ -58,6 +61,12 @@ export type DatePickerProps = Omit<ViewProps, "children"> &
58
61
  minDate?: CalendarDate;
59
62
  /** The latest day that can be picked, inclusive. */
60
63
  maxDate?: CalendarDate;
64
+ /** The month the calendar opens on. Omitted, the selection's month, else today's. */
65
+ defaultMonth?: CalendarDate;
66
+ /** The earliest month paging and the year list reach. Omitted, `minDate`'s month. */
67
+ startMonth?: CalendarDate;
68
+ /** The latest month paging and the year list reach. Omitted, `maxDate`'s month. */
69
+ endMonth?: CalendarDate;
61
70
  /** Further days that cannot be picked. */
62
71
  disabledDates?: readonly DateMatcher[];
63
72
  /** Lets a neighbouring month's day be picked. */