@delacour/react-native-ui 0.11.0-alpha.20261124142708 → 0.11.0-alpha.20261124152158

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.11.0-alpha.20261124142708",
3
+ "version": "0.11.0-alpha.20261124152158",
4
4
  "description": "React Native UI components — Uniwind, Reanimated, Gesture Handler",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -186,8 +186,8 @@
186
186
  "expo-blur": ">=15",
187
187
  "@maplibre/maplibre-react-native": "^11.5.0",
188
188
  "@central-icons-react-native/round-outlined-radius-1-stroke-1.5": "^1.1",
189
- "@delacour/react-native-bottom-sheet": "0.11.0-alpha.20261124142708",
190
- "@delacour/react-native-charts": "0.11.0-alpha.20261124142708",
189
+ "@delacour/react-native-bottom-sheet": "0.11.0-alpha.20261124152158",
190
+ "@delacour/react-native-charts": "0.11.0-alpha.20261124152158",
191
191
  "@legendapp/list": ">=3.3",
192
192
  "react-native-skia": ">=3.9.0",
193
193
  "expo-linear-gradient": ">=15",
@@ -62,8 +62,13 @@ The subpath imports `BottomSheet`, so an app using it installs the optional
62
62
  lag otherwise. Every tap cancels the last tap's pending close, so starting a new range inside
63
63
  that pause keeps the sheet open.
64
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
65
+ `null`; the picker keeps the day, reports no change and closes. A user who opens a date of birth to
66
66
  check it and taps it must not clear it. Clear (`isClearable`) is the way to empty a single day.
67
+ - **`onConfirm` says a single pick happened, changed or not.** It fires on every completed single
68
+ pick — the re-tap above included, inline too — after `onValueChange`, and never on Clear or a
69
+ dismiss. Without it a re-tap and a dismiss look the same (`onOpenChange(false)`, then `onClose`),
70
+ so a form that moves on after a pick stalls on a prefilled day. `range` and `multiple` type it as
71
+ `never`, so it is a type error outside single mode and the root can pull it out of the `View` props.
67
72
  - **A half-picked range is never reported.** The first tap is held in `rangeDraft` inside the
68
73
  root; `onValueChange` fires once the range is complete, and on Clear. Dismissing the sheet —
69
74
  swipe, scrim, close, Done, or a controlled `isOpen={false}` — drops the draft and any pending
@@ -194,6 +194,41 @@ describe("DatePicker single mode", () => {
194
194
  expect(trigger()).toHaveAccessibilityValue({ text: "12 October 2026" });
195
195
  });
196
196
 
197
+ test("onConfirm fires after onValueChange for a new day, and alone for the shown day tapped again", async () => {
198
+ const calls: string[] = [];
199
+ const onValueChange = jest.fn((_value: unknown) => void calls.push("change"));
200
+ const onConfirm = jest.fn((_value: unknown) => void calls.push("confirm"));
201
+ await renderWithProviders(
202
+ <Picker defaultOpen defaultValue={OCT_12} onConfirm={onConfirm} onValueChange={onValueChange} />,
203
+ { wrapper: Providers }
204
+ );
205
+
206
+ await tap(day("2026-10-12"));
207
+ expect(onConfirm).toHaveBeenLastCalledWith(OCT_12);
208
+ expect(onValueChange).not.toHaveBeenCalled();
209
+ await settle();
210
+
211
+ await tap(trigger());
212
+ await tap(day("2026-10-14"));
213
+ expect(onConfirm).toHaveBeenLastCalledWith(OCT_14);
214
+ expect(onConfirm).toHaveBeenCalledTimes(2);
215
+ expect(calls).toEqual(["confirm", "change", "confirm"]);
216
+ });
217
+
218
+ test("onConfirm never fires on Clear or a dismiss", async () => {
219
+ const onConfirm = jest.fn();
220
+ const onValueChange = jest.fn();
221
+ await renderWithProviders(
222
+ <Picker defaultOpen defaultValue={OCT_12} isClearable onConfirm={onConfirm} onValueChange={onValueChange} />,
223
+ { wrapper: Providers }
224
+ );
225
+ await tap(screen.getByRole("button", { name: "Clear" }));
226
+ expect(onValueChange).toHaveBeenCalledWith(null);
227
+ await tap(screen.getByTestId("stay-close"));
228
+ await settle();
229
+ expect(onConfirm).not.toHaveBeenCalled();
230
+ });
231
+
197
232
  test("the picked day is announced as selected", async () => {
198
233
  await renderWithProviders(<Picker defaultOpen defaultValue={OCT_12} />, { wrapper: Providers });
199
234
  expect(day("2026-10-12")).toBeSelected();
@@ -379,6 +414,13 @@ describe("DatePicker inline", () => {
379
414
  await settle();
380
415
  expect(onOpenChange).not.toHaveBeenCalled();
381
416
  });
417
+
418
+ test("onConfirm fires for an inline pick too", async () => {
419
+ const onConfirm = jest.fn();
420
+ await renderWithProviders(<Picker onConfirm={onConfirm} presentation="inline" />, { wrapper: Providers });
421
+ await tap(day("2026-10-12"));
422
+ expect(onConfirm).toHaveBeenCalledWith(OCT_12);
423
+ });
382
424
  });
383
425
 
384
426
  describe("DatePicker parts", () => {
@@ -116,6 +116,7 @@ function DatePickerRoot(props: DatePickerProps): ReactElement {
116
116
  value: _value,
117
117
  defaultValue: _defaultValue,
118
118
  onValueChange: _onValueChange,
119
+ onConfirm,
119
120
  ...viewProps
120
121
  } = props;
121
122
 
@@ -212,10 +213,12 @@ function DatePickerRoot(props: DatePickerProps): ReactElement {
212
213
  // when this selection is complete, so a new range start keeps the sheet open.
213
214
  // A single day tapped again is a confirmation, not a clear: the calendar reports it as `null`,
214
215
  // but the picker keeps the day and closes. Clearing a single day is Clear's job.
216
+ // `onConfirm` fires for both, after `onValueChange`, so a caller can tell a pick from a dismiss.
215
217
  const select = useCallback(
216
218
  (next: CalendarSelectionState) => {
217
219
  cancelPendingClose();
218
220
  if (next.mode === "single" && next.value === null && value.mode === "single" && value.value !== null) {
221
+ onConfirm?.(value.value);
219
222
  finish(value);
220
223
  return;
221
224
  }
@@ -225,9 +228,10 @@ function DatePickerRoot(props: DatePickerProps): ReactElement {
225
228
  }
226
229
  setRangeDraft(null);
227
230
  setValue(next);
231
+ if (next.mode === "single" && next.value !== null) onConfirm?.(next.value);
228
232
  if (resolveShouldClose(next)) finish(next);
229
233
  },
230
- [cancelPendingClose, finish, setValue, value]
234
+ [cancelPendingClose, finish, onConfirm, setValue, value]
231
235
  );
232
236
 
233
237
  const clear = useCallback(() => {
@@ -24,6 +24,12 @@ export type DatePickerSelectionProps =
24
24
  defaultValue?: CalendarDate | null;
25
25
  /** Fires when a day is picked, and with `null` on Clear. */
26
26
  onValueChange?: (value: CalendarDate | null) => void;
27
+ /**
28
+ * Fires on every pick, after `onValueChange`, including a re-tap of the shown day, which
29
+ * closes the sheet without `onValueChange`. Never on Clear or a dismiss. Lets a form move on
30
+ * after the user confirms the day it already holds.
31
+ */
32
+ onConfirm?: (value: CalendarDate) => void;
27
33
  }
28
34
  | {
29
35
  mode: "range";
@@ -34,6 +40,8 @@ export type DatePickerSelectionProps =
34
40
  * held inside the sheet and never reported.
35
41
  */
36
42
  onValueChange?: (value: CalendarDateRange) => void;
43
+ /** Single mode only. */
44
+ onConfirm?: never;
37
45
  }
38
46
  | {
39
47
  mode: "multiple";
@@ -41,6 +49,8 @@ export type DatePickerSelectionProps =
41
49
  defaultValue?: readonly CalendarDate[];
42
50
  /** Fires on every toggle, sorted earliest first. */
43
51
  onValueChange?: (value: readonly CalendarDate[]) => void;
52
+ /** Single mode only. */
53
+ onConfirm?: never;
44
54
  };
45
55
 
46
56
  export type DatePickerProps = Omit<ViewProps, "children"> &
@@ -72,7 +72,7 @@ engine. An app that imports no picker still never resolves it.
72
72
  disables a chosen row for `maxSelected`, or the selection could not be undone.
73
73
  A row disabled by the limit with no description of its own says "Limit
74
74
  reached" (`limitReachedText`).
75
- - **`onClose` is the sheet's, not the state's.** It is passed straight to `BottomSheet` and runs once the sheet has finished sliding down, later than `onValueChange` or the open state turning false. Move focus from here, never from the pick.
75
+ - **`onClose` is the sheet's, not the state's.** It is passed straight to `BottomSheet` and runs once the sheet has finished sliding down, later than `onValueChange` or the open state turning false. Move focus from here, never from the pick. `onConfirm` (single only) says a close came from a pick — a press on the chosen row of a non-clearable select included — and not from a clear or a dismiss. It fires after `onValueChange`, and never for a clearable deselect, which empties the selection.
76
76
  - **Multiple never closes on a pick.** A sticky `Done` footer closes it; every
77
77
  close path — a pick, Done, a swipe, the overlay, the close button, or a
78
78
  controlled `isOpen` set to false — clears the query, because the clear reads
@@ -216,6 +216,34 @@ describe("Select single", () => {
216
216
  await waitFor(() => expect(screen.queryByRole("radio", { name: "Engineer" })).not.toBeOnTheScreen());
217
217
  });
218
218
 
219
+ test("onConfirm fires alone for the chosen row pressed again, and after onValueChange for a new pick", async () => {
220
+ const calls: string[] = [];
221
+ const onValueChange = jest.fn((_value: unknown) => void calls.push("change"));
222
+ const onConfirm = jest.fn((_value: unknown) => void calls.push("confirm"));
223
+ await renderSelect({ defaultValue: "designer", onConfirm, onValueChange });
224
+ await openSheet();
225
+ await tap(screen.getByRole("radio", { name: "Designer" }));
226
+ expect(onConfirm).toHaveBeenLastCalledWith("designer");
227
+ expect(onValueChange).not.toHaveBeenCalled();
228
+ await waitFor(() => expect(screen.queryByRole("radio", { name: "Engineer" })).not.toBeOnTheScreen());
229
+
230
+ await openSheet();
231
+ await tap(screen.getByRole("radio", { name: "Engineer" }));
232
+ expect(onConfirm).toHaveBeenLastCalledWith("engineer");
233
+ expect(onConfirm).toHaveBeenCalledTimes(2);
234
+ expect(calls).toEqual(["confirm", "change", "confirm"]);
235
+ });
236
+
237
+ test("isClearable: clearing the chosen row does not confirm", async () => {
238
+ const onConfirm = jest.fn();
239
+ const onValueChange = jest.fn();
240
+ await renderSelect({ defaultValue: "designer", isClearable: true, onConfirm, onValueChange });
241
+ await openSheet();
242
+ await tap(screen.getByRole("radio", { name: "Designer" }));
243
+ expect(onValueChange).toHaveBeenCalledWith(null);
244
+ expect(onConfirm).not.toHaveBeenCalled();
245
+ });
246
+
219
247
  test("isClearable: pressing the chosen row clears it and reports null", async () => {
220
248
  const onValueChange = jest.fn();
221
249
  await renderSelect({ defaultValue: "designer", isClearable: true, onValueChange });
@@ -93,6 +93,12 @@ export type SelectSingleProps = SelectBaseProps & {
93
93
  onValueChange?: (value: string | null) => void;
94
94
  /** A second press on the chosen row clears it. @default false */
95
95
  isClearable?: boolean;
96
+ /**
97
+ * Fires on every pick, after `onValueChange`, including a press on the chosen row, which closes
98
+ * the sheet without `onValueChange`. Never on a clear or a dismiss. Lets a form move on after the
99
+ * user confirms the option it already holds.
100
+ */
101
+ onConfirm?: (value: string) => void;
96
102
  };
97
103
 
98
104
  export type SelectMultipleProps = SelectBaseProps & {
@@ -200,7 +206,10 @@ function SelectRoot(props: SelectProps): ReactElement {
200
206
  const result = toggleSelection(selected, value, toggleOptions);
201
207
  if (result.change === "blocked" || result.change === "limit-reached") playHaptic("warning");
202
208
  if (result.change !== "unchanged" && result.change !== "blocked") setSelected(result.selected);
203
- if (mode === "single") close();
209
+ if (mode !== "single") return;
210
+ const confirmed = result.selected[0];
211
+ if (confirmed !== undefined) single?.onConfirm?.(confirmed);
212
+ close();
204
213
  };
205
214
 
206
215
  // Offered to an enclosing `Field`, so tapping its label opens the sheet the