@delacour/react-native-ui 0.11.0-alpha.20261124171114 → 0.11.0-alpha.20261124173354

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.
Files changed (97) hide show
  1. package/package.json +4 -3
  2. package/src/components/avatar/AGENTS.md +5 -0
  3. package/src/components/avatar/avatar.tsx +6 -0
  4. package/src/components/avatar/avatar.variants.test.ts +25 -0
  5. package/src/components/avatar/avatar.variants.ts +14 -0
  6. package/src/components/badge/AGENTS.md +13 -1
  7. package/src/components/badge/badge-close-button.tsx +9 -1
  8. package/src/components/badge/badge.render.test.tsx +83 -2
  9. package/src/components/badge/badge.tsx +39 -5
  10. package/src/components/badge/badge.variants.test.ts +56 -1
  11. package/src/components/badge/badge.variants.ts +56 -0
  12. package/src/components/button/AGENTS.md +17 -0
  13. package/src/components/button/button.tsx +10 -0
  14. package/src/components/button/button.variants.test.ts +54 -0
  15. package/src/components/button/button.variants.ts +38 -1
  16. package/src/components/chart/AGENTS.md +53 -0
  17. package/src/components/chart/chart-accessibility.render.test.tsx +109 -0
  18. package/src/components/chart/chart-accessibility.test.ts +179 -0
  19. package/src/components/chart/chart-accessibility.ts +156 -0
  20. package/src/components/chart/chart-frame.tsx +172 -0
  21. package/src/components/chart/chart-legend.render.test.tsx +55 -0
  22. package/src/components/chart/chart-legend.tsx +47 -1
  23. package/src/components/chart/chart-line.tsx +14 -3
  24. package/src/components/chart/chart-tooltip.tsx +2 -1
  25. package/src/components/chart/chart.tsx +37 -7
  26. package/src/components/chart/chart.types.ts +14 -0
  27. package/src/components/chart/chart.variants.test.ts +6 -0
  28. package/src/components/chart/chart.variants.ts +1 -0
  29. package/src/components/chart/index.ts +9 -0
  30. package/src/components/chart/pie-chart-slice-targets.tsx +100 -0
  31. package/src/components/chart/pie-chart.render.test.tsx +119 -0
  32. package/src/components/chart/pie-chart.tsx +66 -16
  33. package/src/components/chip/AGENTS.md +7 -2
  34. package/src/components/chip/chip-close-button.tsx +10 -4
  35. package/src/components/chip/chip.render.test.tsx +19 -0
  36. package/src/components/chip/chip.variants.test.ts +53 -4
  37. package/src/components/chip/chip.variants.ts +61 -5
  38. package/src/components/chip/index.ts +2 -0
  39. package/src/components/color-picker/AGENTS.md +1 -0
  40. package/src/components/color-picker/color-picker-swatch.tsx +13 -1
  41. package/src/components/color-picker/color-picker.variants.test.ts +32 -1
  42. package/src/components/color-picker/color-picker.variants.ts +9 -0
  43. package/src/components/combobox/AGENTS.md +4 -0
  44. package/src/components/combobox/combobox-trigger.tsx +4 -4
  45. package/src/components/combobox/combobox.variants.test.ts +41 -1
  46. package/src/components/combobox/combobox.variants.ts +32 -0
  47. package/src/components/dialog/AGENTS.md +3 -2
  48. package/src/components/dialog/dialog-close.tsx +5 -3
  49. package/src/components/dialog/dialog.variants.test.ts +2 -1
  50. package/src/components/dialog/dialog.variants.ts +6 -2
  51. package/src/components/drawer/AGENTS.md +1 -0
  52. package/src/components/drawer/drawer-close.tsx +5 -3
  53. package/src/components/drawer/drawer.variants.test.ts +2 -1
  54. package/src/components/drawer/drawer.variants.ts +6 -2
  55. package/src/components/kpi/AGENTS.md +5 -0
  56. package/src/components/kpi/kpi-sparkline.tsx +1 -0
  57. package/src/components/map/AGENTS.md +5 -0
  58. package/src/components/map/map-controls.tsx +11 -1
  59. package/src/components/map/map.variants.test.ts +33 -0
  60. package/src/components/map/map.variants.ts +24 -0
  61. package/src/components/popover/AGENTS.md +1 -0
  62. package/src/components/popover/popover-close.tsx +5 -3
  63. package/src/components/popover/popover.variants.test.ts +2 -1
  64. package/src/components/popover/popover.variants.ts +6 -2
  65. package/src/components/pressable/AGENTS.md +28 -1
  66. package/src/components/pressable/index.ts +7 -0
  67. package/src/components/pressable/pressable.tsx +19 -1
  68. package/src/components/pressable/pressable.variants.test.ts +81 -0
  69. package/src/components/pressable/pressable.variants.ts +87 -0
  70. package/src/components/provider/AGENTS.md +10 -3
  71. package/src/components/provider/provider.render.test.tsx +40 -2
  72. package/src/components/provider/provider.tsx +17 -4
  73. package/src/components/screen/AGENTS.md +3 -0
  74. package/src/components/screen/screen-navbar-back-button.tsx +6 -1
  75. package/src/components/screen/screen.variants.test.ts +13 -0
  76. package/src/components/screen/screen.variants.ts +11 -0
  77. package/src/components/search-bar/AGENTS.md +4 -0
  78. package/src/components/search-bar/search-bar-clear.tsx +5 -3
  79. package/src/components/search-bar/search-bar.variants.test.ts +41 -1
  80. package/src/components/search-bar/search-bar.variants.ts +31 -2
  81. package/src/components/sketch/AGENTS.md +4 -0
  82. package/src/components/sketch/sketch-swatches.tsx +6 -1
  83. package/src/components/sketch/sketch.variants.test.ts +26 -1
  84. package/src/components/sketch/sketch.variants.ts +11 -1
  85. package/src/components/table/AGENTS.md +6 -0
  86. package/src/components/table/table-head.tsx +4 -0
  87. package/src/components/table/table.variants.test.ts +39 -0
  88. package/src/components/table/table.variants.ts +29 -0
  89. package/src/components/tabs/AGENTS.md +5 -0
  90. package/src/components/tabs/tabs-trigger.tsx +11 -1
  91. package/src/components/tabs/tabs.variants.test.ts +62 -0
  92. package/src/components/tabs/tabs.variants.ts +37 -0
  93. package/src/components/tree/AGENTS.md +6 -4
  94. package/src/components/tree/tree-indicator.tsx +4 -2
  95. package/src/components/tree/tree.variants.test.ts +14 -2
  96. package/src/components/tree/tree.variants.ts +8 -6
  97. package/src/hooks/use-minimum-hit-target.tsx +53 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delacour/react-native-ui",
3
- "version": "0.11.0-alpha.20261124171114",
3
+ "version": "0.11.0-alpha.20261124173354",
4
4
  "description": "React Native UI components — Uniwind, Reanimated, Gesture Handler",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -150,6 +150,7 @@
150
150
  "./hooks/use-calm-motion": "./src/hooks/use-calm-motion.tsx",
151
151
  "./hooks/use-controllable-state": "./src/hooks/use-controllable-state.ts",
152
152
  "./hooks/use-keyboard-state-sync": "./src/hooks/use-keyboard-state-sync.tsx",
153
+ "./hooks/use-minimum-hit-target": "./src/hooks/use-minimum-hit-target.tsx",
153
154
  "./hooks/use-navigation-theme": "./src/hooks/use-navigation-theme.ts",
154
155
  "./hooks/use-reduce-transparency": "./src/hooks/use-reduce-transparency.ts",
155
156
  "./hooks/use-scroll-sections": "./src/hooks/use-scroll-sections.ts",
@@ -186,8 +187,8 @@
186
187
  "expo-blur": ">=15",
187
188
  "@maplibre/maplibre-react-native": "^11.5.0",
188
189
  "@central-icons-react-native/round-outlined-radius-1-stroke-1.5": "^1.1",
189
- "@delacour/react-native-bottom-sheet": "0.11.0-alpha.20261124171114",
190
- "@delacour/react-native-charts": "0.11.0-alpha.20261124171114",
190
+ "@delacour/react-native-bottom-sheet": "0.11.0-alpha.20261124173354",
191
+ "@delacour/react-native-charts": "0.11.0-alpha.20261124173354",
191
192
  "@legendapp/list": ">=3.3",
192
193
  "react-native-skia": ">=3.9.0",
193
194
  "expo-linear-gradient": ">=15",
@@ -110,3 +110,8 @@ Compound root plus `Avatar.Badge` and `Avatar.Group`.
110
110
  `resolveAvatarOverlap` never slides a face further than a whole face nor
111
111
  backwards, and `overlap={0}` closes the stack into a plain row. A child's own
112
112
  `size` still beats the group's, but the overlap is computed from the group's.
113
+ - **A pressable avatar reaches the minimum touch target with `hitSlop`, not size.**
114
+ `sm` and `md` draw under 44, so a tappable one takes slop up to the app's
115
+ minimum and the face stays the size it was. Inside `Avatar.Group` the slop is
116
+ capped at 0: the faces overlap, and slop would hand the press to the later face
117
+ rather than the one under the finger. A caller's own `hitSlop` wins.
@@ -1,5 +1,6 @@
1
1
  import { type ReactElement, type ReactNode, useMemo, useState } from "react";
2
2
  import { Image, type ImageErrorEvent, type ImageProps, type ImageSourcePropType, View } from "react-native";
3
+ import { useMinimumHitSlop } from "../../hooks/use-minimum-hit-target";
3
4
  import { IconPeople } from "../../icons/central";
4
5
  import { cn } from "../../lib/cn";
5
6
  import { Icon } from "../icon";
@@ -19,6 +20,7 @@ import {
19
20
  type AvatarSize,
20
21
  type AvatarVariant,
21
22
  avatarVariants,
23
+ resolveAvatarHitTarget,
22
24
  resolveAvatarInteractive,
23
25
  resolveAvatarSize,
24
26
  } from "./avatar.variants";
@@ -61,6 +63,7 @@ function AvatarRoot({
61
63
  accessibilityLabel,
62
64
  onPress,
63
65
  onLongPress,
66
+ hitSlop,
64
67
  haptic,
65
68
  feedback = "scale",
66
69
  pressedScale,
@@ -71,6 +74,8 @@ function AvatarRoot({
71
74
  }: AvatarProps): ReactElement {
72
75
  const group = useAvatarGroupContext();
73
76
  const size = resolveAvatarSize({ size: sizeProp, groupSize: group?.size });
77
+ const hitTarget = resolveAvatarHitTarget({ size, inGroup: group !== null });
78
+ const slop = useMinimumHitSlop(hitTarget.edge, { cap: hitTarget.cap });
74
79
  const context = useMemo<AvatarContextValue>(
75
80
  () => ({ size, variant, color, isDisabled }),
76
81
  [size, variant, color, isDisabled]
@@ -145,6 +150,7 @@ function AvatarRoot({
145
150
  disabled={isDisabled}
146
151
  feedback={feedback}
147
152
  haptic={haptic}
153
+ hitSlop={hitSlop ?? slop}
148
154
  onLongPress={onLongPress}
149
155
  onPress={onPress}
150
156
  pressedOpacity={pressedOpacity}
@@ -1,6 +1,7 @@
1
1
  import { describe, expect, test } from "bun:test";
2
2
  import { declaredTokens } from "../../styles/theme-tokens.test";
3
3
  import { ICON_SIZE_TOKENS } from "../../styles/tokens";
4
+ import { resolveMinimumHitSlop } from "../pressable/pressable.variants";
4
5
  import {
5
6
  AVATAR_BADGE_PLACEMENTS,
6
7
  AVATAR_COLORS,
@@ -9,6 +10,7 @@ import {
9
10
  AVATAR_SIZES,
10
11
  AVATAR_VARIANTS,
11
12
  avatarVariants,
13
+ resolveAvatarHitTarget,
12
14
  resolveAvatarInteractive,
13
15
  resolveAvatarOverlap,
14
16
  resolveAvatarSize,
@@ -261,3 +263,26 @@ describe("avatarVariants image", () => {
261
263
  expect(avatarVariants().image().split(" ")).toEqual(expect.arrayContaining(["absolute", "inset-0", "size-full"]));
262
264
  });
263
265
  });
266
+
267
+ describe("resolveAvatarHitTarget", () => {
268
+ test("a standalone avatar reaches 44 with the slop its edge asks for", () => {
269
+ for (const size of AVATAR_SIZES) {
270
+ const { edge, cap } = resolveAvatarHitTarget({ size, inGroup: false });
271
+ const slop = resolveMinimumHitSlop(edge, 44, { cap });
272
+ const side = typeof slop === "number" ? slop : 0;
273
+ expect(edge + 2 * side).toBeGreaterThanOrEqual(44);
274
+ expect(edge).toBe(AVATAR_SIZE_POINTS[size]);
275
+ }
276
+ });
277
+
278
+ test("an avatar already at 44 gets no slop", () => {
279
+ expect(resolveMinimumHitSlop(AVATAR_SIZE_POINTS.lg, 44)).toBeUndefined();
280
+ });
281
+
282
+ test("a grouped avatar takes no slop, so overlapping faces keep their own press", () => {
283
+ for (const size of AVATAR_SIZES) {
284
+ const { edge, cap } = resolveAvatarHitTarget({ size, inGroup: true });
285
+ expect(resolveMinimumHitSlop(edge, 44, { cap })).toBeUndefined();
286
+ }
287
+ });
288
+ });
@@ -277,4 +277,18 @@ export function resolveAvatarInteractive({
277
277
  return onPress !== undefined || onLongPress !== undefined;
278
278
  }
279
279
 
280
+ /**
281
+ * What a pressable avatar's touch area is measured from: its drawn edge.
282
+ *
283
+ * An avatar inside an `Avatar.Group` overlaps its neighbours, so the root takes no
284
+ * slop there (`cap` 0): slop would be hit-tested ahead of the face that is drawn
285
+ * under the finger.
286
+ */
287
+ export function resolveAvatarHitTarget({ size, inGroup }: { size: AvatarSize; inGroup: boolean }): {
288
+ edge: number;
289
+ cap: number | undefined;
290
+ } {
291
+ return { edge: AVATAR_SIZE_POINTS[size], cap: inGroup ? 0 : undefined };
292
+ }
293
+
280
294
  export type AvatarVariantProps = VariantProps<typeof avatarVariants>;
@@ -17,7 +17,7 @@ A compact label for status, category or count. Compound root plus `Badge.Label`,
17
17
  | `badge-close-button.tsx` | `Badge.CloseButton`, the dismiss pressable |
18
18
  | `badge.context.tsx` | `BadgeContext`, `useBadge()`, `useBadgeContext()`, `useBadgePart()` |
19
19
  | `badge.types.ts` | Prop types shared by two or more parts |
20
- | `badge.variants.ts` | Pure `tv()` slots + `resolveBadgeInteractive`, no RN imports |
20
+ | `badge.variants.ts` | Pure `tv()` slots + `resolveBadgeInteractive`, `resolveBadgeCloseExposure`, `resolveBadgeCloseHitSlop`; no RN imports |
21
21
  | `badge.variants.test.ts` | |
22
22
  | `badge.render.test.tsx` | Mounted under Jest — string children, content-vs-button root, press/long-press/disabled, onClose isolation, compound parts and out-of-root errors |
23
23
 
@@ -52,6 +52,18 @@ A compact label for status, category or count. Compound root plus `Badge.Label`,
52
52
  unless the root forwards one, so a flow or test could only find it by its label.
53
53
  `closeTestID` is named like `closeAccessibilityLabel`, the other prop the root
54
54
  passes through to it.
55
+ - **The dismiss glyph carries `hitSlop`, capped at half the gap.** The ✕ is
56
+ the bare 14–18pt icon, far under the 44pt minimum, but its only neighbour is the
57
+ label a gap away: slop reaching past half that gap would take presses from the
58
+ badge's own body. So the cap, not the minimum, sets it (2, 3, 4pt by size) and
59
+ the target stays small by design; a caller's own `hitSlop` wins.
60
+ - **A pressable badge offers `remove` as an accessibility action.** A pressable
61
+ root is one accessibility element and iOS folds its children into it, so the ✕
62
+ is unreachable by swipe and its label is read as part of the badge's. It is
63
+ hidden there and removal is a `remove` action on the root (VoiceOver's Actions
64
+ rotor, TalkBack's actions menu), labelled with `closeAccessibilityLabel` and
65
+ routed to `onClose`; a caller's own actions are kept. A plain badge's ✕ stays its own labelled
66
+ button. `resolveBadgeCloseExposure` is that decision.
55
67
  - **A size is padding, never a height.** `Text` respects OS font scaling, so a
56
68
  fixed height clips the label at a large accessibility step instead of growing
57
69
  with it — and unlike `h-button-*` or `h-navbar-row`, a badge lines up against
@@ -1,9 +1,10 @@
1
1
  import type { ReactElement } from "react";
2
+ import { useMinimumHitSlop } from "../../hooks/use-minimum-hit-target";
2
3
  import { IconCrossSmall } from "../../icons/central";
3
4
  import { Icon } from "../icon";
4
5
  import { Pressable, type PressableProps } from "../pressable";
5
6
  import { useBadgePart } from "./badge.context";
6
- import { badgeVariants } from "./badge.variants";
7
+ import { BADGE_CLOSE_HIT_SLOP_CAP, BADGE_CLOSE_SIZES, badgeVariants } from "./badge.variants";
7
8
 
8
9
  export type BadgeCloseButtonProps = Omit<PressableProps, "asChild" | "busy" | "children" | "disabled">;
9
10
 
@@ -21,6 +22,10 @@ export type BadgeCloseButtonProps = Omit<PressableProps, "asChild" | "busy" | "c
21
22
  * colour from the root's `IconDefaultsProvider`, so a dismiss on a `destructive`
22
23
  * badge is tinted without being told.
23
24
  *
25
+ * The glyph is 14–18pt, so it carries `hitSlop` up to the app's minimum target,
26
+ * capped at half the badge's gap so it never takes a press from the label beside
27
+ * it. A caller's own `hitSlop` wins.
28
+ *
24
29
  * `fade` rather than the root's `scale` — a spring on a glyph this small reads
25
30
  * as a jitter rather than as a press.
26
31
  */
@@ -28,9 +33,11 @@ export function BadgeCloseButton({
28
33
  accessibilityLabel = "Remove",
29
34
  className,
30
35
  feedback = "fade",
36
+ hitSlop,
31
37
  ...props
32
38
  }: BadgeCloseButtonProps): ReactElement {
33
39
  const { size, isDisabled, material } = useBadgePart("Badge.CloseButton");
40
+ const slop = useMinimumHitSlop(BADGE_CLOSE_SIZES[size], { cap: BADGE_CLOSE_HIT_SLOP_CAP[size] });
34
41
 
35
42
  return (
36
43
  <Pressable
@@ -39,6 +46,7 @@ export function BadgeCloseButton({
39
46
  className={badgeVariants({ material, size }).closeButton({ className })}
40
47
  disabled={isDisabled}
41
48
  feedback={feedback}
49
+ hitSlop={hitSlop ?? slop}
42
50
  {...props}
43
51
  >
44
52
  <Icon icon={IconCrossSmall} />
@@ -102,11 +102,11 @@ describe("Badge", () => {
102
102
  const onClose = jest.fn();
103
103
  const onPress = jest.fn();
104
104
  await renderWithProviders(
105
- <Badge onClose={onClose} onPress={onPress}>
105
+ <Badge closeTestID="close" onClose={onClose} onPress={onPress}>
106
106
  Tag
107
107
  </Badge>
108
108
  );
109
- await fireEvent(screen.getByRole("button", { name: "Remove" }), "accessibilityTap");
109
+ await fireEvent(screen.getByTestId("close", { includeHiddenElements: true }), "accessibilityTap");
110
110
  expect(onClose).toHaveBeenCalledTimes(1);
111
111
  expect(onPress).not.toHaveBeenCalled();
112
112
  });
@@ -129,6 +129,87 @@ describe("Badge", () => {
129
129
  expect(onClose).not.toHaveBeenCalled();
130
130
  });
131
131
 
132
+ test("a pressable badge offers remove as an accessibility action and hides the folded-in control", async () => {
133
+ const onClose = jest.fn();
134
+ const onPress = jest.fn();
135
+ await renderWithProviders(
136
+ <Badge
137
+ closeAccessibilityLabel="Remove React"
138
+ closeTestID="close"
139
+ onClose={onClose}
140
+ onPress={onPress}
141
+ testID="badge"
142
+ >
143
+ React
144
+ </Badge>
145
+ );
146
+ const root = screen.getByTestId("badge");
147
+ expect(root.props.accessibilityActions).toEqual([{ label: "Remove React", name: "remove" }]);
148
+ expect(screen.getByTestId("close", { includeHiddenElements: true })).toHaveProp("accessible", false);
149
+ await fireEvent(root, "accessibilityAction", { nativeEvent: { actionName: "remove" } });
150
+ expect(onClose).toHaveBeenCalledTimes(1);
151
+ expect(onPress).not.toHaveBeenCalled();
152
+ });
153
+
154
+ test("the remove action keeps a caller's actions and forwards every other one", async () => {
155
+ const onAccessibilityAction = jest.fn();
156
+ await renderWithProviders(
157
+ <Badge
158
+ accessibilityActions={[{ label: "Share", name: "share" }]}
159
+ onAccessibilityAction={onAccessibilityAction}
160
+ onClose={() => undefined}
161
+ onPress={() => undefined}
162
+ testID="badge"
163
+ >
164
+ React
165
+ </Badge>
166
+ );
167
+ const root = screen.getByTestId("badge");
168
+ expect(root.props.accessibilityActions).toEqual([
169
+ { label: "Share", name: "share" },
170
+ { label: "Remove", name: "remove" },
171
+ ]);
172
+ await fireEvent(root, "accessibilityAction", { nativeEvent: { actionName: "share" } });
173
+ expect(onAccessibilityAction).toHaveBeenCalledTimes(1);
174
+ });
175
+
176
+ test("a disabled pressable badge's remove action does nothing", async () => {
177
+ const onClose = jest.fn();
178
+ await renderWithProviders(
179
+ <Badge isDisabled onClose={onClose} onPress={() => undefined} testID="badge">
180
+ React
181
+ </Badge>
182
+ );
183
+ await fireEvent(screen.getByTestId("badge"), "accessibilityAction", { nativeEvent: { actionName: "remove" } });
184
+ expect(onClose).not.toHaveBeenCalled();
185
+ });
186
+
187
+ test("a plain badge keeps the control its own element and adds no action", async () => {
188
+ await renderWithProviders(
189
+ <Badge onClose={() => undefined} testID="badge">
190
+ Tag
191
+ </Badge>
192
+ );
193
+ expect(screen.getByTestId("badge").props.accessibilityActions).toBeUndefined();
194
+ expect(screen.getByRole("button", { name: "Remove" })).toBeOnTheScreen();
195
+ });
196
+
197
+ test("the dismiss control carries capped slop, and a caller's hitSlop wins", async () => {
198
+ await renderWithProviders(
199
+ <>
200
+ <Badge closeTestID="a" onClose={() => undefined}>
201
+ A
202
+ </Badge>
203
+ <Badge onClose={() => undefined} size="lg">
204
+ B
205
+ <Badge.CloseButton hitSlop={9} testID="b" />
206
+ </Badge>
207
+ </>
208
+ );
209
+ expect(screen.getByTestId("a")).toHaveProp("hitSlop", 3);
210
+ expect(screen.getByTestId("b")).toHaveProp("hitSlop", 9);
211
+ });
212
+
132
213
  test("no dismiss control without onClose", async () => {
133
214
  await renderWithProviders(<Badge onPress={() => undefined}>Tag</Badge>);
134
215
  expect(screen.queryByRole("button", { name: "Remove" })).not.toBeOnTheScreen();
@@ -1,5 +1,5 @@
1
1
  import { Children, type ReactElement, type ReactNode, useMemo } from "react";
2
- import { View } from "react-native";
2
+ import { type AccessibilityActionEvent, View } from "react-native";
3
3
  import { IconDefaultsProvider } from "../icon";
4
4
  import { Pressable, type PressableProps } from "../pressable";
5
5
  import { TextClassProvider } from "../text/text.context";
@@ -11,6 +11,7 @@ import {
11
11
  type BadgeSize,
12
12
  type BadgeVariant,
13
13
  badgeVariants,
14
+ resolveBadgeCloseExposure,
14
15
  resolveBadgeInteractive,
15
16
  } from "./badge.variants";
16
17
  import { BadgeCloseButton } from "./badge-close-button";
@@ -45,6 +46,8 @@ function BadgeRoot({
45
46
  onClose,
46
47
  closeAccessibilityLabel,
47
48
  closeTestID,
49
+ accessibilityActions,
50
+ onAccessibilityAction,
48
51
  onPress,
49
52
  onLongPress,
50
53
  haptic,
@@ -73,22 +76,49 @@ function BadgeRoot({
73
76
  const content = useMemo(() => wrapTextChildren(children), [children]);
74
77
  const rootClassName = slots.root({ className });
75
78
 
79
+ const interactive = resolveBadgeInteractive({ onPress, onLongPress });
80
+ const closeExposure = resolveBadgeCloseExposure({ hasClose: onClose !== undefined, interactive });
81
+ const closeHidden = closeExposure === "action";
76
82
  const inner = (
77
83
  <IconDefaultsProvider value={iconDefaults}>
78
84
  <TextClassProvider value={slots.label()}>
79
85
  {content}
80
86
  {onClose ? (
81
- <BadgeCloseButton accessibilityLabel={closeAccessibilityLabel} onPress={onClose} testID={closeTestID} />
87
+ <BadgeCloseButton
88
+ accessibilityElementsHidden={closeHidden}
89
+ accessibilityLabel={closeAccessibilityLabel}
90
+ accessible={!closeHidden}
91
+ importantForAccessibility={closeHidden ? "no-hide-descendants" : "auto"}
92
+ onPress={onClose}
93
+ testID={closeTestID}
94
+ />
82
95
  ) : null}
83
96
  </TextClassProvider>
84
97
  </IconDefaultsProvider>
85
98
  );
86
99
 
100
+ const actions = closeHidden
101
+ ? [...(accessibilityActions ?? []), { label: closeAccessibilityLabel ?? "Remove", name: "remove" }]
102
+ : accessibilityActions;
103
+
104
+ const handleAccessibilityAction = (event: AccessibilityActionEvent) => {
105
+ if (closeHidden && event.nativeEvent.actionName === "remove" && !isDisabled) {
106
+ onClose?.();
107
+ return;
108
+ }
109
+ onAccessibilityAction?.(event);
110
+ };
111
+
87
112
  // A badge with nothing to do stays a plain box — see `resolveBadgeInteractive`.
88
- if (!resolveBadgeInteractive({ onPress, onLongPress })) {
113
+ if (!interactive) {
89
114
  return (
90
115
  <BadgeProvider value={context}>
91
- <View className={rootClassName} {...props}>
116
+ <View
117
+ accessibilityActions={accessibilityActions}
118
+ className={rootClassName}
119
+ onAccessibilityAction={onAccessibilityAction}
120
+ {...props}
121
+ >
92
122
  {inner}
93
123
  </View>
94
124
  </BadgeProvider>
@@ -98,11 +128,13 @@ function BadgeRoot({
98
128
  return (
99
129
  <BadgeProvider value={context}>
100
130
  <Pressable
131
+ accessibilityActions={actions}
101
132
  accessibilityRole="button"
102
133
  className={rootClassName}
103
134
  disabled={isDisabled}
104
135
  feedback={feedback}
105
136
  haptic={haptic}
137
+ onAccessibilityAction={handleAccessibilityAction}
106
138
  onLongPress={onLongPress}
107
139
  onPress={onPress}
108
140
  pressedOpacity={pressedOpacity}
@@ -164,7 +196,9 @@ function wrapTextChildren(children: ReactNode): ReactNode {
164
196
  * default differs, `scale`.
165
197
  *
166
198
  * `onClose` composes a dismiss control in at the end. It is a pressable of its
167
- * own, so dismissing never also fires `onPress`.
199
+ * own, so dismissing never also fires `onPress`. On a pressable badge the root is
200
+ * one accessibility element that folds the control in, so the control is hidden
201
+ * there and offered as a `remove` accessibility action instead.
168
202
  *
169
203
  * Plain string or number children are wrapped in a `Badge.Label` automatically;
170
204
  * pass the compound parts when a layout needs more control.
@@ -1,12 +1,18 @@
1
1
  import { describe, expect, test } from "bun:test";
2
- import { declaredTokens } from "../../styles/theme-tokens.test";
2
+ import { declaredTokens, TOKENS_CSS } from "../../styles/theme-tokens.test";
3
3
  import { ICON_SIZE_TOKENS } from "../../styles/tokens";
4
+ import { resolveMinimumHitSlop } from "../pressable/pressable.variants";
4
5
  import {
6
+ BADGE_CLOSE_HIT_SLOP_CAP,
7
+ BADGE_CLOSE_SIZES,
5
8
  BADGE_COLORS,
6
9
  BADGE_FOREGROUND_TOKEN,
10
+ BADGE_GAPS,
7
11
  BADGE_SIZES,
8
12
  BADGE_VARIANTS,
9
13
  badgeVariants,
14
+ resolveBadgeCloseExposure,
15
+ resolveBadgeCloseHitSlop,
10
16
  resolveBadgeInteractive,
11
17
  } from "./badge.variants";
12
18
 
@@ -268,6 +274,55 @@ describe("resolveBadgeInteractive", () => {
268
274
  });
269
275
  });
270
276
 
277
+ describe("resolveBadgeCloseExposure", () => {
278
+ test("no onClose means no dismiss control", () => {
279
+ expect(resolveBadgeCloseExposure({ hasClose: false, interactive: true })).toBe("none");
280
+ expect(resolveBadgeCloseExposure({ hasClose: false, interactive: false })).toBe("none");
281
+ });
282
+
283
+ test("a plain root leaves the close control its own element", () => {
284
+ expect(resolveBadgeCloseExposure({ hasClose: true, interactive: false })).toBe("element");
285
+ });
286
+
287
+ test("a pressable root folds the close control in, so it is offered as an action", () => {
288
+ expect(resolveBadgeCloseExposure({ hasClose: true, interactive: true })).toBe("action");
289
+ });
290
+ });
291
+
292
+ describe("the dismiss control's hit target", () => {
293
+ const gapOf = (size: (typeof BADGE_SIZES)[number]) => BADGE_GAPS[size];
294
+
295
+ test("its drawn edge is the icon step the root's icon slot sets", () => {
296
+ for (const size of BADGE_SIZES) {
297
+ const token = badgeVariants({ size })
298
+ .icon()
299
+ .match(/\bsize-(icon-[\w-]+)\b/)?.[1];
300
+ expect(token).toBeDefined();
301
+ expect(TOKENS_CSS).toContain(`--spacing-${token}: ${BADGE_CLOSE_SIZES[size]}px;`);
302
+ }
303
+ });
304
+
305
+ test("the gap is the one the root sets between its children", () => {
306
+ for (const size of BADGE_SIZES) {
307
+ expect(badgeVariants({ size }).root()).toContain(`gap-${gapOf(size) / 4}`);
308
+ }
309
+ });
310
+
311
+ test("slop is capped at half the gap, so it never reaches into a neighbour's touch area", () => {
312
+ for (const size of BADGE_SIZES) {
313
+ expect(BADGE_CLOSE_HIT_SLOP_CAP[size]).toBe(gapOf(size) / 2);
314
+ const slop = resolveBadgeCloseHitSlop(size);
315
+ expect(slop).toBe(resolveMinimumHitSlop(BADGE_CLOSE_SIZES[size], 44, { cap: gapOf(size) / 2 }));
316
+ expect(slop).toBe(gapOf(size) / 2);
317
+ }
318
+ });
319
+
320
+ test("a smaller minimum than the cap allows is honoured uncapped", () => {
321
+ expect(resolveBadgeCloseHitSlop("md", 18)).toBe(1);
322
+ expect(resolveBadgeCloseHitSlop("md", 16)).toBeUndefined();
323
+ });
324
+ });
325
+
271
326
  describe("the etched badge material", () => {
272
327
  test("flat keeps the capsule", () => {
273
328
  expect(badgeVariants({}).root()).toContain("rounded-full");
@@ -1,5 +1,6 @@
1
1
  import type { VariantProps } from "tailwind-variants";
2
2
  import { tv } from "../../lib/tv";
3
+ import { MIN_HIT_TARGET, resolveMinimumHitSlop } from "../pressable/pressable.variants";
3
4
 
4
5
  /** How the surface is painted. Orthogonal to {@link BADGE_COLORS}. */
5
6
  export const BADGE_VARIANTS = ["solid", "soft", "outline", "ghost"] as const;
@@ -255,4 +256,59 @@ export function resolveBadgeInteractive({
255
256
  return onPress !== undefined || onLongPress !== undefined;
256
257
  }
257
258
 
259
+ /** Edge, in points, of the dismiss glyph at each size: the `--spacing-icon-*` step the `icon` slot sets. */
260
+ export const BADGE_CLOSE_SIZES: Record<BadgeSize, number> = { sm: 14, md: 16, lg: 18 };
261
+
262
+ /** The gap, in points, the root sets between its children at each size: `gap-1`, `gap-1.5`, `gap-2`. */
263
+ export const BADGE_GAPS: Record<BadgeSize, number> = { sm: 4, md: 6, lg: 8 };
264
+
265
+ /**
266
+ * How far the dismiss control's slop may reach, per side.
267
+ *
268
+ * Half the root's gap: the label beside it is the neighbour, and slop that
269
+ * overlapped it would take presses from the badge's own body. The glyph is
270
+ * bare, so the cap — not the 44pt minimum — is what sets the slop here.
271
+ */
272
+ export const BADGE_CLOSE_HIT_SLOP_CAP: Record<BadgeSize, number> = {
273
+ sm: BADGE_GAPS.sm / 2,
274
+ md: BADGE_GAPS.md / 2,
275
+ lg: BADGE_GAPS.lg / 2,
276
+ };
277
+
278
+ /**
279
+ * The `hitSlop` for the dismiss glyph at `size`, bounded by
280
+ * {@link BADGE_CLOSE_HIT_SLOP_CAP}. `min` is the app's minimum touch target.
281
+ * Pure, so it is unit-testable; the component reaches it through `useMinimumHitSlop`.
282
+ */
283
+ export function resolveBadgeCloseHitSlop(
284
+ size: BadgeSize,
285
+ min = MIN_HIT_TARGET
286
+ ): ReturnType<typeof resolveMinimumHitSlop> {
287
+ return resolveMinimumHitSlop(BADGE_CLOSE_SIZES[size], min, { cap: BADGE_CLOSE_HIT_SLOP_CAP[size] });
288
+ }
289
+
290
+ /**
291
+ * How a screen reader reaches the dismiss control.
292
+ *
293
+ * - `none` — there is no `onClose`.
294
+ * - `element` — a plain root is not an accessibility element, so the control
295
+ * is announced on its own, as a button.
296
+ * - `action` — a pressable root is one accessibility element and iOS folds its
297
+ * descendants into it: the control is unreachable by swipe. It is hidden and
298
+ * offered as a `remove` accessibility action on the root instead.
299
+ */
300
+ export type BadgeCloseExposure = "none" | "element" | "action";
301
+
302
+ /** See {@link BadgeCloseExposure}. Pure, so it is unit-testable. */
303
+ export function resolveBadgeCloseExposure({
304
+ hasClose,
305
+ interactive,
306
+ }: {
307
+ hasClose: boolean;
308
+ interactive: boolean;
309
+ }): BadgeCloseExposure {
310
+ if (!hasClose) return "none";
311
+ return interactive ? "action" : "element";
312
+ }
313
+
258
314
  export type BadgeVariantProps = VariantProps<typeof badgeVariants>;
@@ -105,6 +105,23 @@ The reference implementation for the patterns in the package
105
105
  the left edge unless it also sets `self-center`. This is what made an earlier
106
106
  `only` implementation collapse a full-width button into a small box flush
107
107
  left. Prefer not taking the width at all.
108
+ - **`sm` and `icon-sm` reach 44pt with `hitSlop`, not with size.** Both draw
109
+ at 36. `resolveButtonHitTarget` says what the button draws at — a labelled
110
+ button's height (its width follows the label), an `icon-*` button's square —
111
+ and `useMinimumHitSlop` grows it to the app's minimum: 4pt a side, or 6 on
112
+ Android under `DelacourProvider isMaterialHitTarget`. `md` and `lg` get
113
+ nothing. Inside a `Button.Group` the axis the run lies along gets none, so a
114
+ member's slop never lands on its neighbour. Two `sm` / `icon-sm` buttons
115
+ that abut outside a `Button.Group` need their own `hitSlop` with nothing on
116
+ the shared edge: the later one is hit-tested first and its slop takes presses
117
+ on the drawn neighbour (Map's zoom pair does this). A caller's `hitSlop` wins
118
+ outright. The heights are `BUTTON_HEIGHTS`, pinned to `--spacing-button-*`;
119
+ an app that retunes density at runtime moves the drawn height and not the
120
+ slop, which is the trade for not measuring every button on layout.
121
+ On Android the slop does not land yet: the root's `overflow-hidden`
122
+ (load-bearing, see above) stops Gesture Handler's orchestrator descending
123
+ into the button for a touch outside its bounds — see
124
+ [Pressable](../pressable/AGENTS.md). iOS takes it.
108
125
 
109
126
  ## Button.Group
110
127
 
@@ -1,4 +1,5 @@
1
1
  import { Children, isValidElement, type ReactElement, type ReactNode, useMemo } from "react";
2
+ import { useMinimumHitSlop } from "../../hooks/use-minimum-hit-target";
2
3
  import { Icon, IconDefaultsProvider } from "../icon";
3
4
  import { Pressable, type PressableProps } from "../pressable";
4
5
  import { Spinner } from "../spinner";
@@ -13,6 +14,7 @@ import {
13
14
  type ButtonVariant,
14
15
  buttonVariants,
15
16
  resolveButtonFeedback,
17
+ resolveButtonHitTarget,
16
18
  resolveButtonLayout,
17
19
  resolveGroupedButtonSize,
18
20
  resolveSpinnerSwapIndex,
@@ -50,6 +52,7 @@ function ButtonRoot({
50
52
  accessibilityLabel,
51
53
  className,
52
54
  children,
55
+ hitSlop,
53
56
  ...props
54
57
  }: ButtonProps): ReactElement {
55
58
  // Deliberately not defaulted in the destructure above: a default there would
@@ -92,6 +95,12 @@ function ButtonRoot({
92
95
  [iconClassName, resolvedVariant]
93
96
  );
94
97
 
98
+ // `sm` and `icon-sm` draw at 36pt; slop takes the target to the app's
99
+ // minimum without moving a pixel. A caller's own `hitSlop` wins outright.
100
+ const minimumHitSlop = useMinimumHitSlop(
101
+ resolveButtonHitTarget({ orientation: item?.orientation, size: resolvedSize })
102
+ );
103
+
95
104
  const label = accessibilityLabel ?? (layout.isSpinnerOnly ? textOf(children) : undefined);
96
105
 
97
106
  return (
@@ -103,6 +112,7 @@ function ButtonRoot({
103
112
  className={slots.root({ className })}
104
113
  disabled={resolvedIsDisabled}
105
114
  feedback={resolveButtonFeedback(feedback, item?.feedback, item !== null, item?.isAttached)}
115
+ hitSlop={hitSlop ?? minimumHitSlop}
106
116
  {...props}
107
117
  >
108
118
  <IconDefaultsProvider value={iconDefaults}>