@delacour/react-native-ui 0.6.0 → 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.0",
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.0",
186
- "@delacour/react-native-charts": ">=0.6.0",
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",
@@ -30,7 +30,8 @@ Compound root plus `Avatar.Badge` and `Avatar.Group`.
30
30
  because there is nothing to swap.
31
31
  - **A failure is remembered by key, not by object.** `resolveAvatarSourceKey`
32
32
  turns the source into a JSON string — every request field (URI, bundle,
33
- method, sorted headers, body, cache mode), or the asset's module id — and
33
+ method, sorted headers, body, cache mode) and the entry's width, height and
34
+ scale, or the asset's module id — and
34
35
  `onError` stores the key that failed. Keyed by object identity, an
35
36
  inline `source={{ uri }}` is new every render and a dead URL would retry
36
37
  forever; keyed by URI alone, a token refresh in the headers would never retry.
@@ -2,6 +2,7 @@ import type { ReactElement, ReactNode } from "react";
2
2
  import { View, type ViewProps } from "react-native";
3
3
  import { cn } from "../../lib/cn";
4
4
  import { useAvatarPart } from "./avatar.context";
5
+ import { resolveAvatarBadgeHasContent } from "./avatar.utils";
5
6
  import { type AvatarBadgePlacement, type AvatarColor, avatarVariants } from "./avatar.variants";
6
7
 
7
8
  export type AvatarBadgeProps = ViewProps & {
@@ -18,7 +19,8 @@ export type AvatarBadgeProps = ViewProps & {
18
19
  * An overlay pinned to a corner of the avatar — an unread count, a presence dot.
19
20
  *
20
21
  * **Empty, it is a presence dot** sized to the face it sits on and ringed in the
21
- * page background, so it reads as separate from the photo underneath. Given
22
+ * page background, so it reads as separate from the photo underneath. Empty
23
+ * means no element: a `0` or `""` from a conditional count is a dot too. Given
22
24
  * children, it is only the pin: a `Badge` or an `Icon` dropped in keeps its own
23
25
  * look, which is what lets a count and a dot share one part.
24
26
  *
@@ -38,7 +40,7 @@ export function AvatarBadge({
38
40
  const { size } = useAvatarPart("Avatar.Badge");
39
41
  const slots = avatarVariants({ size, placement, color });
40
42
 
41
- if (children === undefined || children === null || children === false) {
43
+ if (!resolveAvatarBadgeHasContent(children)) {
42
44
  return <View className={cn(slots.badge(), slots.dot(), className)} pointerEvents="none" {...props} />;
43
45
  }
44
46
 
@@ -1,7 +1,7 @@
1
1
  import { afterEach, beforeEach, describe, expect, jest, test } from "@jest/globals";
2
2
  import { Platform, Text } from "react-native";
3
3
  import { fireEvent, renderWithProviders, screen } from "../../test/render";
4
- import { Avatar } from "./avatar";
4
+ import { Avatar, type AvatarProps } from "./avatar";
5
5
  import { useAvatar } from "./avatar.context";
6
6
 
7
7
  const PHOTO = { uri: "https://example.com/aria.png" };
@@ -92,6 +92,16 @@ describe("Avatar", () => {
92
92
  expect(screen.queryByTestId("photo")).not.toBeOnTheScreen();
93
93
  });
94
94
 
95
+ test("imageProps takes no source override, so source alone drives the request and the retry key", () => {
96
+ const overrides: NonNullable<AvatarProps["imageProps"]>[] = [
97
+ // @ts-expect-error `src` would win over `source` and skip the retry key.
98
+ { src: "https://example.com/other.png" },
99
+ // @ts-expect-error `srcSet` would win over `source` and skip the retry key.
100
+ { srcSet: "https://example.com/other.png 1x" },
101
+ ];
102
+ expect(overrides).toHaveLength(2);
103
+ });
104
+
95
105
  test("imageProps are forwarded to the image", async () => {
96
106
  await renderWithProviders(
97
107
  <Avatar imageProps={{ accessibilityLabel: "portrait", testID: "photo" }} name="Aria Whitlock" source={PHOTO} />
@@ -119,6 +129,17 @@ describe("Avatar", () => {
119
129
  expect(screen.queryByTestId("photo")).not.toBeOnTheScreen();
120
130
  });
121
131
 
132
+ test("a new source mounts a new image, so a late error from the old one cannot fail it", async () => {
133
+ const view = await renderWithProviders(
134
+ <Avatar imageProps={{ testID: "photo" }} name="Aria Whitlock" source={PHOTO} />
135
+ );
136
+ const expired = screen.getByTestId("photo");
137
+ await view.rerender(<Avatar imageProps={{ testID: "photo" }} name="Aria Whitlock" source={OTHER_PHOTO} />);
138
+ expect(screen.getByTestId("photo")).not.toBe(expired);
139
+ await fireEvent(expired, "error", { nativeEvent: { error: "expired" } });
140
+ expect(screen.getByTestId("photo")).toBeOnTheScreen();
141
+ });
142
+
122
143
  test("a different source is tried again", async () => {
123
144
  const view = await renderWithProviders(
124
145
  <Avatar imageProps={{ testID: "photo" }} name="Aria Whitlock" source={PHOTO} />
@@ -154,6 +175,11 @@ describe("Avatar", () => {
154
175
  }
155
176
  });
156
177
 
178
+ test("a pressable avatar with no name, fallback or label is still named", async () => {
179
+ await renderWithProviders(<Avatar onPress={jest.fn()} />);
180
+ expect(screen.getByRole("button", { name: "Avatar" })).toBeOnTheScreen();
181
+ });
182
+
157
183
  test("isDisabled is announced and blocks onPress and onLongPress", async () => {
158
184
  const onPress = jest.fn();
159
185
  const onLongPress = jest.fn();
@@ -204,6 +230,16 @@ describe("Avatar", () => {
204
230
  expect(screen.getByTestId("dot")).toHaveProp("pointerEvents", "none");
205
231
  });
206
232
 
233
+ test("an Avatar.Badge given a 0 from a conditional count is a dot, not a raw 0", async () => {
234
+ const unread = 0;
235
+ await renderWithProviders(
236
+ <Avatar name="Aria Whitlock">
237
+ <Avatar.Badge testID="dot">{unread && <Text>{unread}</Text>}</Avatar.Badge>
238
+ </Avatar>
239
+ );
240
+ expect(screen.getByTestId("dot")).toHaveProp("pointerEvents", "none");
241
+ });
242
+
207
243
  test("Avatar.Badge with children pins them and lets touches through", async () => {
208
244
  await renderWithProviders(
209
245
  <Avatar name="Aria Whitlock">
@@ -14,6 +14,7 @@ import {
14
14
  } from "./avatar.utils";
15
15
  import {
16
16
  AVATAR_FOREGROUND_TOKEN,
17
+ AVATAR_SIZE_POINTS,
17
18
  type AvatarColor,
18
19
  type AvatarSize,
19
20
  type AvatarVariant,
@@ -38,8 +39,12 @@ export type AvatarProps = Omit<PressableProps, "asChild" | "busy" | "children" |
38
39
  /** Default `md`, or the enclosing group's size. */
39
40
  size?: AvatarSize;
40
41
  isDisabled?: boolean;
41
- /** Passed to the `Image`. `onError` still fires, after the fallback has taken over. */
42
- imageProps?: Omit<ImageProps, "source">;
42
+ /**
43
+ * Passed to the `Image`. `onError` still fires, after the fallback has taken
44
+ * over. `src` and `srcSet` are left out: `Image` prefers them to `source`, and
45
+ * `source` is what the retry key is built from.
46
+ */
47
+ imageProps?: Omit<ImageProps, "source" | "src" | "srcSet">;
43
48
  /** Overlays — an `Avatar.Badge`. */
44
49
  children?: ReactNode;
45
50
  };
@@ -72,14 +77,16 @@ function AvatarRoot({
72
77
  );
73
78
 
74
79
  // Remembered by key, not by object: an inline `source={{ uri }}` is a new
75
- // object every render, and a new URI has to retry on its own.
76
- const sourceKey = resolveAvatarSourceKey(source);
80
+ // object every render, and a new URI has to retry on its own. The edge is in
81
+ // the key because a list of resolutions picks its entry by the face's size.
82
+ const sourceKey = resolveAvatarSourceKey(source, { edge: AVATAR_SIZE_POINTS[size] });
77
83
  const [failedKey, setFailedKey] = useState<string | null>(null);
78
84
  const showsImage = resolveAvatarShowsImage({ sourceKey, failedKey });
79
85
  const slots = avatarVariants({ size, variant, color, isDisabled, hasImage: showsImage });
80
86
 
81
87
  const initials = fallback?.trim() || resolveAvatarInitials(name);
82
- const label = resolveAvatarAccessibilityLabel({ accessibilityLabel, name, fallback });
88
+ const isInteractive = resolveAvatarInteractive({ onPress, onLongPress });
89
+ const label = resolveAvatarAccessibilityLabel({ accessibilityLabel, name, fallback, isInteractive });
83
90
 
84
91
  const onImageError = (event: ImageErrorEvent) => {
85
92
  setFailedKey(sourceKey);
@@ -87,7 +94,9 @@ function AvatarRoot({
87
94
  };
88
95
 
89
96
  // The fallback is always painted and the image goes over it, so the circle is
90
- // never empty while a picture loads or after it fails.
97
+ // never empty while a picture loads or after it fails. The image is keyed by
98
+ // its source, so a new source mounts a new image: a late error from the old
99
+ // request cannot mark the new one as failed.
91
100
  const face = (
92
101
  <View className={slots.face()}>
93
102
  {initials ? (
@@ -99,6 +108,7 @@ function AvatarRoot({
99
108
  )}
100
109
  {showsImage && source !== undefined ? (
101
110
  <Image
111
+ key={sourceKey}
102
112
  accessibilityIgnoresInvertColors
103
113
  {...imageProps}
104
114
  className={cn(slots.image(), imageProps?.className)}
@@ -109,7 +119,7 @@ function AvatarRoot({
109
119
  </View>
110
120
  );
111
121
 
112
- if (!resolveAvatarInteractive({ onPress, onLongPress })) {
122
+ if (!isInteractive) {
113
123
  return (
114
124
  <AvatarProvider value={context}>
115
125
  <View
@@ -1,8 +1,10 @@
1
1
  import { describe, expect, test } from "bun:test";
2
2
  import { createElement, Fragment } from "react";
3
3
  import {
4
+ AVATAR_BUTTON_FALLBACK_LABEL,
4
5
  flattenAvatarChildren,
5
6
  resolveAvatarAccessibilityLabel,
7
+ resolveAvatarBadgeHasContent,
6
8
  resolveAvatarGroup,
7
9
  resolveAvatarInitials,
8
10
  resolveAvatarOverflowLabel,
@@ -36,6 +38,10 @@ describe("resolveAvatarInitials", () => {
36
38
  expect(resolveAvatarInitials("𝒜ria 𝒲hitlock")).toBe("𝒜𝒲");
37
39
  });
38
40
 
41
+ test("keeps an accent from a decomposed (NFD) name", () => {
42
+ expect(resolveAvatarInitials("E\u0301mile Zola")).toBe("\u00C9Z");
43
+ });
44
+
39
45
  test("keeps letters in scripts with no case", () => {
40
46
  expect(resolveAvatarInitials("森山 健二")).toBe("森健");
41
47
  });
@@ -89,6 +95,32 @@ describe("resolveAvatarSourceKey", () => {
89
95
  );
90
96
  });
91
97
 
98
+ test("changes when entry dimensions change, so a list that picks another uri can retry", () => {
99
+ const before = resolveAvatarSourceKey([
100
+ { uri: "https://a.test/1x.png", width: 40, height: 40 },
101
+ { uri: "https://a.test/2x.png", width: 80, height: 80 },
102
+ ]);
103
+ const swapped = resolveAvatarSourceKey([
104
+ { uri: "https://a.test/1x.png", width: 80, height: 80 },
105
+ { uri: "https://a.test/2x.png", width: 40, height: 40 },
106
+ ]);
107
+ expect(before).not.toBe(swapped);
108
+ expect(resolveAvatarSourceKey({ uri: "https://a.test/1.png", scale: 1 })).not.toBe(
109
+ resolveAvatarSourceKey({ uri: "https://a.test/1.png", scale: 2 })
110
+ );
111
+ });
112
+
113
+ test("changes with the face's edge for a list, so a failure at one size does not block another resolution", () => {
114
+ const list = [{ uri: "https://a.test/1x.png" }, { uri: "https://a.test/3x.png" }];
115
+ expect(resolveAvatarSourceKey(list, { edge: 32 })).not.toBe(resolveAvatarSourceKey(list, { edge: 96 }));
116
+ });
117
+
118
+ test("ignores the edge for a single source, which loads the same image at every size", () => {
119
+ const one = { uri: "https://a.test/1.png" };
120
+ expect(resolveAvatarSourceKey(one, { edge: 32 })).toBe(resolveAvatarSourceKey(one, { edge: 96 }));
121
+ expect(resolveAvatarSourceKey([one], { edge: 32 })).toBe(resolveAvatarSourceKey([one], { edge: 96 }));
122
+ });
123
+
92
124
  test("changes when the uri changes", () => {
93
125
  expect(resolveAvatarSourceKey({ uri: "https://a.test/1.png" })).not.toBe(
94
126
  resolveAvatarSourceKey({ uri: "https://a.test/2.png" })
@@ -186,6 +218,12 @@ describe("resolveAvatarOverflowLabel", () => {
186
218
  });
187
219
 
188
220
  describe("resolveAvatarAccessibilityLabel", () => {
221
+ test("a pressable avatar with nothing to read gets a generic name, never a bare button", () => {
222
+ expect(resolveAvatarAccessibilityLabel({ isInteractive: true })).toBe(AVATAR_BUTTON_FALLBACK_LABEL);
223
+ expect(resolveAvatarAccessibilityLabel({ isInteractive: true, name: " " })).toBe(AVATAR_BUTTON_FALLBACK_LABEL);
224
+ expect(resolveAvatarAccessibilityLabel({ isInteractive: true, name: "Aria Whitlock" })).toBe("Aria Whitlock");
225
+ });
226
+
189
227
  test("prefers the name", () => {
190
228
  expect(resolveAvatarAccessibilityLabel({ name: "Aria Whitlock", fallback: "AW" })).toBe("Aria Whitlock");
191
229
  });
@@ -204,6 +242,19 @@ describe("resolveAvatarAccessibilityLabel", () => {
204
242
  });
205
243
  });
206
244
 
245
+ describe("resolveAvatarBadgeHasContent", () => {
246
+ test("is false for nothing to pin, including a 0 or an empty string from a conditional", () => {
247
+ for (const children of [undefined, null, false, true, 0, "", [0, ""]]) {
248
+ expect(resolveAvatarBadgeHasContent(children)).toBe(false);
249
+ }
250
+ });
251
+
252
+ test("is true when there is an element to pin", () => {
253
+ expect(resolveAvatarBadgeHasContent(createElement("Badge"))).toBe(true);
254
+ expect(resolveAvatarBadgeHasContent([0, createElement("Badge", { key: "badge" })])).toBe(true);
255
+ });
256
+ });
257
+
207
258
  describe("flattenAvatarChildren", () => {
208
259
  const face = (name: string, key?: string) => createElement("Face", { key, name });
209
260
  const names = (children: Parameters<typeof flattenAvatarChildren>[0]) =>
@@ -13,9 +13,9 @@ import { Children, cloneElement, Fragment, isValidElement, type ReactElement, ty
13
13
  export type AvatarSourceCache = "default" | "reload" | "force-cache" | "only-if-cached";
14
14
 
15
15
  /**
16
- * A URI request, as `Image` accepts it. Holds only the fields that change what
17
- * is fetched. `width`, `height` and `scale` are left out: they pick an entry,
18
- * they do not change the request.
16
+ * A URI request, as `Image` accepts it. Holds the fields that change what is
17
+ * fetched, and `width`, `height` and `scale`, which pick the entry of a
18
+ * multi-resolution list that is fetched.
19
19
  */
20
20
  export type AvatarSourceRequest = {
21
21
  uri?: string | null;
@@ -24,6 +24,9 @@ export type AvatarSourceRequest = {
24
24
  headers?: Readonly<Record<string, string>> | null;
25
25
  body?: string | null;
26
26
  cache?: AvatarSourceCache | null;
27
+ width?: number | null;
28
+ height?: number | null;
29
+ scale?: number | null;
27
30
  };
28
31
 
29
32
  /** One entry of an image source, as `Image` accepts it — a URI request or a bundled asset's module id. */
@@ -47,10 +50,12 @@ function initialOf(word: string): string {
47
50
  *
48
51
  * Walks code points rather than UTF-16 units, so a letter outside the basic
49
52
  * plane is kept whole instead of drawn as a replacement box, and skips leading
50
- * punctuation so a quoted nickname still gives a letter.
53
+ * punctuation so a quoted nickname still gives a letter. The name is put in
54
+ * NFC form first: in NFD form, as servers and macOS input often send it,
55
+ * `É` is `E` plus a combining accent, and only the `E` would be kept.
51
56
  */
52
57
  export function resolveAvatarInitials(name: string | undefined): string {
53
- const words = (name ?? "").trim().split(/\s+/).filter(Boolean);
58
+ const words = (name ?? "").normalize("NFC").trim().split(/\s+/).filter(Boolean);
54
59
  if (words.length === 0) return "";
55
60
  const first = initialOf(words[0] ?? "");
56
61
  const last = words.length > 1 ? initialOf(words[words.length - 1] ?? "") : "";
@@ -70,6 +75,9 @@ function entryKey(entry: AvatarSourceEntry): unknown {
70
75
  headers,
71
76
  entry.body ?? null,
72
77
  entry.cache ?? null,
78
+ entry.width ?? null,
79
+ entry.height ?? null,
80
+ entry.scale ?? null,
73
81
  ];
74
82
  }
75
83
 
@@ -81,17 +89,22 @@ function entryKey(entry: AvatarSourceEntry): unknown {
81
89
  * keyed by identity, a failed image would retry forever. Keyed by URI alone, a
82
90
  * token refresh in the headers would never retry at all. Every field that
83
91
  * changes the request is part of the key, including `cache`, so a cache miss
84
- * retries when the cache mode changes. The key is a JSON array, so no value can
92
+ * retries when the cache mode changes. So are `width`, `height` and `scale`:
93
+ * with the same URIs, new dimensions can pick another entry of a list. The key is a JSON array, so no value can
85
94
  * look like a separator, and header order is normalised so an equal request is
86
95
  * an equal key.
87
96
  *
88
97
  * `null` means there is nothing to load.
89
98
  */
90
- export function resolveAvatarSourceKey(source: AvatarSource | null | undefined): string | null {
99
+ export function resolveAvatarSourceKey(
100
+ source: AvatarSource | null | undefined,
101
+ { edge }: { edge?: number } = {}
102
+ ): string | null {
91
103
  if (source === null || source === undefined) return null;
92
104
  const entries: readonly AvatarSourceEntry[] = Array.isArray(source) ? source : [source as AvatarSourceEntry];
93
105
  const keys = entries.map(entryKey).filter((key) => key !== null);
94
- return keys.length === 0 ? null : JSON.stringify(keys);
106
+ if (keys.length === 0) return null;
107
+ return JSON.stringify(keys.length > 1 && edge !== undefined ? [...keys, ["edge", edge]] : keys);
95
108
  }
96
109
 
97
110
  /**
@@ -150,6 +163,17 @@ export function flattenAvatarChildren(children: ReactNode): ReactElement[] {
150
163
  });
151
164
  }
152
165
 
166
+ /**
167
+ * Whether an `Avatar.Badge` has something to pin, or is a presence dot.
168
+ *
169
+ * Only an element counts. `{unread && <Badge />}` with `unread = 0` passes a
170
+ * raw `0`, and a raw string or number in a `View` throws on native. So `0`,
171
+ * `""` and other non-elements mean the dot.
172
+ */
173
+ export function resolveAvatarBadgeHasContent(children: ReactNode): boolean {
174
+ return Children.toArray(children).some(isValidElement);
175
+ }
176
+
153
177
  /** The most the overflow tile draws before it reads `99+`. Three digits do not fit a small circle. */
154
178
  export const AVATAR_OVERFLOW_DISPLAY_MAX = 99;
155
179
 
@@ -166,23 +190,31 @@ export function resolveAvatarOverflowLabel(overflow: number): { text: string; ac
166
190
  };
167
191
  }
168
192
 
193
+ /** What a pressable avatar is called when it has no label, name or fallback. */
194
+ export const AVATAR_BUTTON_FALLBACK_LABEL = "Avatar";
195
+
169
196
  /**
170
197
  * The name a screen reader gives the avatar: an explicit label, else the
171
198
  * person's name, else the fallback text. Blank strings count as absent, so an
172
199
  * avatar with nothing to say is not announced as an empty image.
200
+ *
201
+ * A pressable avatar always has a name. With nothing else to read it is
202
+ * {@link AVATAR_BUTTON_FALLBACK_LABEL}, so it is never announced as only "button".
173
203
  */
174
204
  export function resolveAvatarAccessibilityLabel({
175
205
  accessibilityLabel,
176
206
  name,
177
207
  fallback,
208
+ isInteractive = false,
178
209
  }: {
179
210
  accessibilityLabel?: string;
180
211
  name?: string;
181
212
  fallback?: string;
213
+ isInteractive?: boolean;
182
214
  }): string | undefined {
183
215
  for (const candidate of [accessibilityLabel, name, fallback]) {
184
216
  const trimmed = candidate?.trim();
185
217
  if (trimmed) return trimmed;
186
218
  }
187
- return undefined;
219
+ return isInteractive ? AVATAR_BUTTON_FALLBACK_LABEL : undefined;
188
220
  }
@@ -8,6 +8,7 @@ export {
8
8
  useAvatarGroupContext,
9
9
  } from "./avatar.context";
10
10
  export {
11
+ AVATAR_BUTTON_FALLBACK_LABEL,
11
12
  AVATAR_OVERFLOW_DISPLAY_MAX,
12
13
  type AvatarSource,
13
14
  type AvatarSourceCache,
@@ -15,6 +16,7 @@ export {
15
16
  type AvatarSourceRequest,
16
17
  flattenAvatarChildren,
17
18
  resolveAvatarAccessibilityLabel,
19
+ resolveAvatarBadgeHasContent,
18
20
  resolveAvatarGroup,
19
21
  resolveAvatarInitials,
20
22
  resolveAvatarOverflowLabel,
@@ -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. */