@delacour/react-native-ui 0.9.0-alpha.20261109201759 → 0.9.0-alpha.20261109205732
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 +3 -3
- package/src/components/checkbox/AGENTS.md +10 -4
- package/src/components/checkbox/checkbox-group.tsx +24 -2
- package/src/components/checkbox/checkbox.render.test.tsx +100 -0
- package/src/components/checkbox/checkbox.tsx +21 -5
- package/src/components/checkbox/checkbox.variants.test.ts +45 -0
- package/src/components/checkbox/checkbox.variants.ts +41 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@delacour/react-native-ui",
|
|
3
|
-
"version": "0.9.0-alpha.
|
|
3
|
+
"version": "0.9.0-alpha.20261109205732",
|
|
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.9.0-alpha.
|
|
190
|
-
"@delacour/react-native-charts": "0.9.0-alpha.
|
|
189
|
+
"@delacour/react-native-bottom-sheet": "0.9.0-alpha.20261109205732",
|
|
190
|
+
"@delacour/react-native-charts": "0.9.0-alpha.20261109205732",
|
|
191
191
|
"@legendapp/list": ">=3.3",
|
|
192
192
|
"react-native-skia": ">=3.9.0",
|
|
193
193
|
"expo-linear-gradient": ">=15",
|
|
@@ -167,10 +167,16 @@ Root plus `Checkbox.Label` and `Checkbox.Group`.
|
|
|
167
167
|
had to opt out because its animation *is* the status signal.
|
|
168
168
|
- **`hitSlop` is new to this package, and only a bare box gets any.** A bare `md`
|
|
169
169
|
checkbox is a 20pt square against a 44pt minimum, with no padded capsule to
|
|
170
|
-
absorb the difference the way [`Badge.CloseButton`](../badge/AGENTS.md) has.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
170
|
+
absorb the difference the way [`Badge.CloseButton`](../badge/AGENTS.md) has. A label widens the
|
|
171
|
+
row but not its height, so a labelled row is padded instead (`hasLabel`:
|
|
172
|
+
`py-3`/`py-2.5`/`py-2` over 20/24/28pt lines) to reach 44pt, and
|
|
173
|
+
`resolveCheckboxHitSlop` returns nothing for it. `Checkbox.Group` has no gap:
|
|
174
|
+
padded rows meet edge to edge, so targets neither overlap nor leave a dead strip.
|
|
175
|
+
- **A bare box takes its name from the field.** A sibling `Field.Label` is outside
|
|
176
|
+
the box's accessible subtree, so `resolveCheckboxAccessibilityLabel` falls back
|
|
177
|
+
to `field.label` when there is no inline content and no `accessibilityLabel`.
|
|
178
|
+
- **A caller's `accessibilityState` is merged, not replaced.** `checked` is set
|
|
179
|
+
after the caller's fields, so `{ busy: true }` cannot drop the checked state.
|
|
174
180
|
- **There is no `Checkbox.Description` and no `Checkbox.Indicator`.**
|
|
175
181
|
`Field.Description` already is the first, and a label defined twice is a type
|
|
176
182
|
scale that can drift. The second has nothing to configure that
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ReactElement, type ReactNode, useCallback, useMemo } from "react";
|
|
1
|
+
import { type ReactElement, type ReactNode, useCallback, useMemo, useRef } from "react";
|
|
2
2
|
import { View, type ViewProps } from "react-native";
|
|
3
3
|
import { useControllableState } from "../../hooks/use-controllable-state";
|
|
4
4
|
import { type CheckboxGroupContextValue, CheckboxGroupProvider } from "./checkbox.context";
|
|
@@ -46,7 +46,29 @@ function CheckboxGroupRoot({
|
|
|
46
46
|
value: checked,
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
// Two toggles in one handler must build on each other, or the second would
|
|
50
|
+
// start from the same render's list and drop the first. So toggles in the
|
|
51
|
+
// same task share a pending list, and a microtask clears it once the
|
|
52
|
+
// handler returns. The next interaction starts from `settled` again, so a
|
|
53
|
+
// controlled parent that rejects a change (and never re-renders) does not
|
|
54
|
+
// see the rejected value carried into the next proposal.
|
|
55
|
+
const settled = useRef(values);
|
|
56
|
+
settled.current = values;
|
|
57
|
+
const pending = useRef<string[] | null>(null);
|
|
58
|
+
|
|
59
|
+
const toggle = useCallback(
|
|
60
|
+
(value: string) => {
|
|
61
|
+
if (pending.current === null) {
|
|
62
|
+
queueMicrotask(() => {
|
|
63
|
+
pending.current = null;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
const next = toggleCheckedValue(pending.current ?? settled.current, value);
|
|
67
|
+
pending.current = next;
|
|
68
|
+
setValues(next);
|
|
69
|
+
},
|
|
70
|
+
[setValues]
|
|
71
|
+
);
|
|
50
72
|
|
|
51
73
|
const context = useMemo<CheckboxGroupContextValue>(
|
|
52
74
|
() => ({ alignment, checked: values, color, isDisabled, isInvalid, size, toggle }),
|
|
@@ -1,9 +1,24 @@
|
|
|
1
1
|
import { afterEach, beforeEach, describe, expect, jest, test } from "@jest/globals";
|
|
2
2
|
import { fireEvent, renderWithProviders, screen } from "../../test/render";
|
|
3
3
|
import { Field } from "../field";
|
|
4
|
+
import { Pressable } from "../pressable";
|
|
4
5
|
import { Checkbox } from "./checkbox";
|
|
5
6
|
import { useCheckbox, useCheckboxGroup } from "./checkbox.context";
|
|
6
7
|
|
|
8
|
+
/** A custom control that flips two values in one handler, before a render. */
|
|
9
|
+
function ToggleBoth() {
|
|
10
|
+
const group = useCheckboxGroup();
|
|
11
|
+
return (
|
|
12
|
+
<Pressable
|
|
13
|
+
accessibilityLabel="Both"
|
|
14
|
+
onPress={() => {
|
|
15
|
+
group.toggle("email");
|
|
16
|
+
group.toggle("sms");
|
|
17
|
+
}}
|
|
18
|
+
/>
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
7
22
|
const tap = (element: Parameters<typeof fireEvent>[0]) => fireEvent(element, "accessibilityTap");
|
|
8
23
|
|
|
9
24
|
describe("Checkbox", () => {
|
|
@@ -136,9 +151,94 @@ describe("Checkbox", () => {
|
|
|
136
151
|
await tap(screen.getByRole("checkbox"));
|
|
137
152
|
expect(onCheckedChange).toHaveBeenCalledWith(true);
|
|
138
153
|
});
|
|
154
|
+
|
|
155
|
+
test("a bare box is named by a sibling Field.Label", async () => {
|
|
156
|
+
await renderWithProviders(
|
|
157
|
+
<Field>
|
|
158
|
+
<Field.Label>Accept the terms</Field.Label>
|
|
159
|
+
<Checkbox />
|
|
160
|
+
</Field>
|
|
161
|
+
);
|
|
162
|
+
expect(screen.getByRole("checkbox", { name: "Accept the terms" })).toBeOnTheScreen();
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
test("a conditional label that renders nothing still lets the Field.Label name the box", async () => {
|
|
166
|
+
const showInlineLabel = false as boolean;
|
|
167
|
+
await renderWithProviders(
|
|
168
|
+
<Field>
|
|
169
|
+
<Field.Label>Accept the terms</Field.Label>
|
|
170
|
+
<Checkbox>{showInlineLabel && <Checkbox.Label>Inline</Checkbox.Label>}</Checkbox>
|
|
171
|
+
</Field>
|
|
172
|
+
);
|
|
173
|
+
expect(screen.getByRole("checkbox", { name: "Accept the terms" })).toBeOnTheScreen();
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("a caller's accessibilityState keeps the checked state", async () => {
|
|
177
|
+
await renderWithProviders(
|
|
178
|
+
<Checkbox accessibilityState={{ busy: true }} defaultChecked>
|
|
179
|
+
Newsletter
|
|
180
|
+
</Checkbox>
|
|
181
|
+
);
|
|
182
|
+
expect(screen.getByRole("checkbox").props.accessibilityState).toMatchObject({ busy: true, checked: true });
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test("a caller's accessibilityState keeps the mixed state", async () => {
|
|
186
|
+
await renderWithProviders(
|
|
187
|
+
<Checkbox accessibilityState={{ busy: true }} isIndeterminate>
|
|
188
|
+
Newsletter
|
|
189
|
+
</Checkbox>
|
|
190
|
+
);
|
|
191
|
+
expect(screen.getByRole("checkbox").props.accessibilityState).toMatchObject({ busy: true, checked: "mixed" });
|
|
192
|
+
});
|
|
139
193
|
});
|
|
140
194
|
|
|
141
195
|
describe("Checkbox.Group", () => {
|
|
196
|
+
test("toggles made before the next render build on each other", async () => {
|
|
197
|
+
const onChecked = jest.fn();
|
|
198
|
+
await renderWithProviders(
|
|
199
|
+
<Checkbox.Group onChecked={onChecked}>
|
|
200
|
+
<ToggleBoth />
|
|
201
|
+
<Checkbox value="email">Email</Checkbox>
|
|
202
|
+
<Checkbox value="sms">SMS</Checkbox>
|
|
203
|
+
</Checkbox.Group>
|
|
204
|
+
);
|
|
205
|
+
await tap(screen.getByRole("button", { name: "Both" }));
|
|
206
|
+
expect(onChecked).toHaveBeenNthCalledWith(1, ["email"]);
|
|
207
|
+
expect(onChecked).toHaveBeenNthCalledWith(2, ["email", "sms"]);
|
|
208
|
+
expect(screen.getByRole("checkbox", { name: "Email" })).toBeChecked();
|
|
209
|
+
expect(screen.getByRole("checkbox", { name: "SMS" })).toBeChecked();
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
test("a change a controlled parent rejects does not carry into the next tap", async () => {
|
|
213
|
+
const onChecked = jest.fn();
|
|
214
|
+
await renderWithProviders(
|
|
215
|
+
<Checkbox.Group checked={[]} onChecked={onChecked}>
|
|
216
|
+
<Checkbox value="email">Email</Checkbox>
|
|
217
|
+
<Checkbox value="sms">SMS</Checkbox>
|
|
218
|
+
</Checkbox.Group>
|
|
219
|
+
);
|
|
220
|
+
await tap(screen.getByRole("checkbox", { name: "Email" }));
|
|
221
|
+
expect(onChecked).toHaveBeenLastCalledWith(["email"]);
|
|
222
|
+
await tap(screen.getByRole("checkbox", { name: "SMS" }));
|
|
223
|
+
expect(onChecked).toHaveBeenLastCalledWith(["sms"]);
|
|
224
|
+
expect(screen.getByRole("checkbox", { name: "Email" })).not.toBeChecked();
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
test("a grouped box still reports its own change", async () => {
|
|
228
|
+
const onCheckedChange = jest.fn();
|
|
229
|
+
await renderWithProviders(
|
|
230
|
+
<Checkbox.Group defaultChecked={["email"]}>
|
|
231
|
+
<Checkbox onCheckedChange={onCheckedChange} value="email">
|
|
232
|
+
Email
|
|
233
|
+
</Checkbox>
|
|
234
|
+
</Checkbox.Group>
|
|
235
|
+
);
|
|
236
|
+
await tap(screen.getByRole("checkbox", { name: "Email" }));
|
|
237
|
+
expect(onCheckedChange).toHaveBeenLastCalledWith(false);
|
|
238
|
+
await tap(screen.getByRole("checkbox", { name: "Email" }));
|
|
239
|
+
expect(onCheckedChange).toHaveBeenLastCalledWith(true);
|
|
240
|
+
});
|
|
241
|
+
|
|
142
242
|
test("uncontrolled: defaultChecked ticks matching children and toggling reports the whole list", async () => {
|
|
143
243
|
const onChecked = jest.fn();
|
|
144
244
|
await renderWithProviders(
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
type CheckboxColor,
|
|
10
10
|
type CheckboxSize,
|
|
11
11
|
checkboxVariants,
|
|
12
|
+
resolveCheckboxAccessibilityLabel,
|
|
12
13
|
resolveCheckboxAxes,
|
|
13
14
|
resolveCheckboxHitSlop,
|
|
14
15
|
} from "./checkbox.variants";
|
|
@@ -26,6 +27,7 @@ export type CheckboxProps = Omit<PressableProps, "asChild" | "busy" | "disabled"
|
|
|
26
27
|
isChecked?: boolean;
|
|
27
28
|
/** Starting state while uncontrolled. */
|
|
28
29
|
defaultChecked?: boolean;
|
|
30
|
+
/** Fired with the box's next state on every toggle, inside a `Checkbox.Group` too. */
|
|
29
31
|
onCheckedChange?: (isChecked: boolean) => void;
|
|
30
32
|
/**
|
|
31
33
|
* Draws a dash rather than a tick and reports `mixed` to a screen reader, for
|
|
@@ -59,6 +61,8 @@ function CheckboxRoot({
|
|
|
59
61
|
feedback = "fade",
|
|
60
62
|
haptic = "selection",
|
|
61
63
|
className,
|
|
64
|
+
accessibilityLabel,
|
|
65
|
+
accessibilityState,
|
|
62
66
|
children,
|
|
63
67
|
...props
|
|
64
68
|
}: CheckboxProps): ReactElement {
|
|
@@ -86,11 +90,14 @@ function CheckboxRoot({
|
|
|
86
90
|
const toggle = useCallback(() => {
|
|
87
91
|
if (axes.isDisabled) return;
|
|
88
92
|
if (group && groupValue !== undefined) {
|
|
93
|
+
// The group owns the state, so `setOwnChecked` is skipped — and with
|
|
94
|
+
// it the only path that calls `onCheckedChange`. Report it here.
|
|
89
95
|
group.toggle(groupValue);
|
|
96
|
+
onCheckedChange?.(!checked);
|
|
90
97
|
return;
|
|
91
98
|
}
|
|
92
99
|
setOwnChecked(!checked);
|
|
93
|
-
}, [axes.isDisabled, checked, group, groupValue, setOwnChecked]);
|
|
100
|
+
}, [axes.isDisabled, checked, group, groupValue, onCheckedChange, setOwnChecked]);
|
|
94
101
|
|
|
95
102
|
// Offered to an enclosing `Field` so tapping the label or the description
|
|
96
103
|
// beside the box ticks it. A checkbox in a form is a small square next to a
|
|
@@ -124,20 +131,29 @@ function CheckboxRoot({
|
|
|
124
131
|
);
|
|
125
132
|
|
|
126
133
|
const content = useMemo(() => wrapTextChildren(children), [children]);
|
|
134
|
+
// From the normalized content, not `children`: `Children.count` counts a
|
|
135
|
+
// `false` from `{cond && <Checkbox.Label />}`, which renders nothing and
|
|
136
|
+
// would suppress the field-label fallback.
|
|
137
|
+
const hasLabel = content.length > 0;
|
|
127
138
|
// The box draws itself, including everything the fill state changes, so the
|
|
128
139
|
// root is left with the row and nothing else.
|
|
129
|
-
const rootClassName = checkboxVariants(axes).root({ className });
|
|
140
|
+
const rootClassName = checkboxVariants({ ...axes, hasLabel }).root({ className });
|
|
130
141
|
|
|
131
142
|
return (
|
|
132
143
|
<CheckboxProvider value={context}>
|
|
133
144
|
<Pressable
|
|
145
|
+
accessibilityLabel={resolveCheckboxAccessibilityLabel({
|
|
146
|
+
fieldLabel: field?.label,
|
|
147
|
+
hasContent: hasLabel,
|
|
148
|
+
own: accessibilityLabel,
|
|
149
|
+
})}
|
|
134
150
|
accessibilityRole="checkbox"
|
|
135
|
-
accessibilityState={{ checked: isIndeterminate ? "mixed" : checked }}
|
|
151
|
+
accessibilityState={{ ...accessibilityState, checked: isIndeterminate ? "mixed" : checked }}
|
|
136
152
|
className={rootClassName}
|
|
137
153
|
disabled={axes.isDisabled}
|
|
138
154
|
feedback={feedback}
|
|
139
155
|
haptic={haptic}
|
|
140
|
-
hitSlop={resolveCheckboxHitSlop({ hasLabel
|
|
156
|
+
hitSlop={resolveCheckboxHitSlop({ hasLabel, size: axes.size })}
|
|
141
157
|
onPress={toggle}
|
|
142
158
|
{...props}
|
|
143
159
|
>
|
|
@@ -172,7 +188,7 @@ function requireValue(value: string | undefined): string {
|
|
|
172
188
|
* gap would otherwise space the parts of one sentence apart, the same rule and
|
|
173
189
|
* the same reason as `Badge`.
|
|
174
190
|
*/
|
|
175
|
-
function wrapTextChildren(children: ReactNode): ReactNode {
|
|
191
|
+
function wrapTextChildren(children: ReactNode): ReactNode[] {
|
|
176
192
|
const items = Children.toArray(children);
|
|
177
193
|
const output: ReactNode[] = [];
|
|
178
194
|
let run: (string | number)[] = [];
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
CHECKBOX_SIZES,
|
|
18
18
|
CHECKBOX_SURFACE_TOKEN,
|
|
19
19
|
checkboxVariants,
|
|
20
|
+
resolveCheckboxAccessibilityLabel,
|
|
20
21
|
resolveCheckboxAxes,
|
|
21
22
|
resolveCheckboxBorderTokens,
|
|
22
23
|
resolveCheckboxFilled,
|
|
@@ -308,6 +309,30 @@ describe("checkboxVariants root slot", () => {
|
|
|
308
309
|
expect(checkboxVariants({ isDisabled: true }).root()).toContain("opacity-50");
|
|
309
310
|
expect(checkboxVariants({ isDisabled: false }).root()).not.toContain("opacity-50");
|
|
310
311
|
});
|
|
312
|
+
|
|
313
|
+
test("pads a labelled one-line row up to the 44pt touch minimum", () => {
|
|
314
|
+
// The label's line box at each size: 20/24/28.
|
|
315
|
+
const lineHeight = { sm: 20, md: 24, lg: 28 } as const;
|
|
316
|
+
for (const size of CHECKBOX_SIZES) {
|
|
317
|
+
const root = checkboxVariants({ hasLabel: true, size }).root();
|
|
318
|
+
const py = Number(root.match(/\bpy-([\d.]+)\b/)?.[1] ?? 0) * 4;
|
|
319
|
+
expect(lineHeight[size] + py * 2).toBe(44);
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
test("adds no padding to a bare box, which takes hit slop instead", () => {
|
|
324
|
+
for (const size of CHECKBOX_SIZES) {
|
|
325
|
+
expect(checkboxVariants({ hasLabel: false, size }).root()).not.toMatch(/\bpy-/);
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
|
|
330
|
+
describe("checkboxVariants group slot", () => {
|
|
331
|
+
test("leaves the spacing between rows to their own padding", () => {
|
|
332
|
+
// A gap would sit between two rows' touch targets as a dead strip, and
|
|
333
|
+
// slop across it would overlap. Padded rows meet edge to edge instead.
|
|
334
|
+
expect(checkboxVariants().group()).not.toMatch(/\bgap-/);
|
|
335
|
+
});
|
|
311
336
|
});
|
|
312
337
|
|
|
313
338
|
describe("checkboxVariants label slot", () => {
|
|
@@ -561,6 +586,26 @@ describe("resolveCheckboxHitSlop", () => {
|
|
|
561
586
|
});
|
|
562
587
|
});
|
|
563
588
|
|
|
589
|
+
describe("resolveCheckboxAccessibilityLabel", () => {
|
|
590
|
+
test("an explicit label wins", () => {
|
|
591
|
+
expect(resolveCheckboxAccessibilityLabel({ fieldLabel: "Terms", hasContent: false, own: "Consent" })).toBe(
|
|
592
|
+
"Consent"
|
|
593
|
+
);
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
test("a bare box takes the field's label", () => {
|
|
597
|
+
expect(resolveCheckboxAccessibilityLabel({ fieldLabel: "Terms", hasContent: false })).toBe("Terms");
|
|
598
|
+
});
|
|
599
|
+
|
|
600
|
+
test("inline content names the box itself, so the field's label is not used", () => {
|
|
601
|
+
expect(resolveCheckboxAccessibilityLabel({ fieldLabel: "Terms", hasContent: true })).toBeUndefined();
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
test("is undefined with nothing to go on", () => {
|
|
605
|
+
expect(resolveCheckboxAccessibilityLabel({ fieldLabel: null, hasContent: false })).toBeUndefined();
|
|
606
|
+
});
|
|
607
|
+
});
|
|
608
|
+
|
|
564
609
|
describe("CHECKBOX_HIT_SLOP", () => {
|
|
565
610
|
test("brings every bare box to at least 44 points", () => {
|
|
566
611
|
const BOX_PX = { sm: 18, md: 20, lg: 24 } as const;
|
|
@@ -209,8 +209,12 @@ export const checkboxVariants = tv({
|
|
|
209
209
|
label: "shrink",
|
|
210
210
|
/** Edge length the tick inherits. */
|
|
211
211
|
glyph: "",
|
|
212
|
-
/**
|
|
213
|
-
|
|
212
|
+
/**
|
|
213
|
+
* `Checkbox.Group`'s column. No gap: each labelled row is padded to the
|
|
214
|
+
* 44pt touch minimum, so rows meet edge to edge and the padding is the
|
|
215
|
+
* spacing. A gap would leave a dead strip between two targets.
|
|
216
|
+
*/
|
|
217
|
+
group: "",
|
|
214
218
|
},
|
|
215
219
|
variants: {
|
|
216
220
|
// Paints the fill and nothing else — see the note above on why the box
|
|
@@ -252,8 +256,15 @@ export const checkboxVariants = tv({
|
|
|
252
256
|
isFilled: { true: {}, false: {} },
|
|
253
257
|
isInvalid: { true: {}, false: {} },
|
|
254
258
|
isDisabled: { true: { root: "opacity-50" }, false: {} },
|
|
259
|
+
// A label widens the target but not its height. The padding per size
|
|
260
|
+
// below brings a one-line row (20/24/28) to the 44pt touch minimum. A
|
|
261
|
+
// bare box takes hit slop instead — see `resolveCheckboxHitSlop`.
|
|
262
|
+
hasLabel: { true: {}, false: {} },
|
|
255
263
|
},
|
|
256
264
|
compoundVariants: [
|
|
265
|
+
{ hasLabel: true, size: "sm", class: { root: "py-3" } },
|
|
266
|
+
{ hasLabel: true, size: "md", class: { root: "py-2.5" } },
|
|
267
|
+
{ hasLabel: true, size: "lg", class: { root: "py-2" } },
|
|
257
268
|
// Invalid outranks the colour on the fill, whether the box is ticked or
|
|
258
269
|
// not. A checkbox that stayed green while its value was rejected would
|
|
259
270
|
// drop the only signal it has, exactly while the value is being corrected
|
|
@@ -271,6 +282,7 @@ export const checkboxVariants = tv({
|
|
|
271
282
|
isFilled: false,
|
|
272
283
|
isInvalid: false,
|
|
273
284
|
isDisabled: false,
|
|
285
|
+
hasLabel: false,
|
|
274
286
|
},
|
|
275
287
|
});
|
|
276
288
|
|
|
@@ -434,13 +446,36 @@ export function resolveCheckboxLabelColor(isInvalid: boolean): TextColor | undef
|
|
|
434
446
|
return isInvalid ? "destructive" : undefined;
|
|
435
447
|
}
|
|
436
448
|
|
|
449
|
+
/**
|
|
450
|
+
* The name a screen reader announces for a checkbox.
|
|
451
|
+
*
|
|
452
|
+
* An explicit `accessibilityLabel` wins. Inline content (a `Checkbox.Label` or a
|
|
453
|
+
* bare string) sits inside the target and names it already. A bare box has
|
|
454
|
+
* neither, and a sibling `Field.Label` sits outside its accessible subtree, so
|
|
455
|
+
* the field's label is the fallback.
|
|
456
|
+
*
|
|
457
|
+
* Pure, so it is unit-testable. See AGENTS.md.
|
|
458
|
+
*/
|
|
459
|
+
export function resolveCheckboxAccessibilityLabel({
|
|
460
|
+
own,
|
|
461
|
+
fieldLabel,
|
|
462
|
+
hasContent,
|
|
463
|
+
}: {
|
|
464
|
+
own?: string;
|
|
465
|
+
fieldLabel: string | null | undefined;
|
|
466
|
+
hasContent: boolean;
|
|
467
|
+
}): string | undefined {
|
|
468
|
+
if (own !== undefined) return own;
|
|
469
|
+
if (hasContent) return undefined;
|
|
470
|
+
return fieldLabel ?? undefined;
|
|
471
|
+
}
|
|
472
|
+
|
|
437
473
|
/**
|
|
438
474
|
* The slop a checkbox's tap target takes beyond the box itself.
|
|
439
475
|
*
|
|
440
|
-
* Only a bare box gets any.
|
|
441
|
-
*
|
|
442
|
-
* making a tap between two checkboxes ambiguous
|
|
443
|
-
* being merely adequate.
|
|
476
|
+
* Only a bare box gets any. A labelled row is padded to the 44pt minimum by
|
|
477
|
+
* `checkboxVariants`' `hasLabel` instead, and slop on top of that would overlap
|
|
478
|
+
* the next row's — making a tap between two checkboxes ambiguous.
|
|
444
479
|
*
|
|
445
480
|
* Pure, so it is unit-testable. See AGENTS.md.
|
|
446
481
|
*/
|