@delacour/react-native-ui 0.7.0 → 0.7.1-alpha.20261105125648

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.7.0",
3
+ "version": "0.7.1-alpha.20261105125648",
4
4
  "description": "React Native UI components — Uniwind, Reanimated, Gesture Handler",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -9,6 +9,10 @@
9
9
  "url": "git+https://github.com/delacournz/delacour-ui.git",
10
10
  "directory": "packages/react-native-ui"
11
11
  },
12
+ "homepage": "https://ui.delacour.co.nz/docs/native/getting-started",
13
+ "bugs": {
14
+ "url": "https://github.com/delacournz/delacour-ui/issues"
15
+ },
12
16
  "keywords": [
13
17
  "react-native",
14
18
  "expo",
@@ -182,8 +186,8 @@
182
186
  "expo-blur": ">=15",
183
187
  "@maplibre/maplibre-react-native": "^11.5.0",
184
188
  "@central-icons-react-native/round-outlined-radius-1-stroke-1.5": "^1.1",
185
- "@delacour/react-native-bottom-sheet": ">=0.7.0",
186
- "@delacour/react-native-charts": ">=0.7.0",
189
+ "@delacour/react-native-bottom-sheet": "0.7.1-alpha.20261105125648",
190
+ "@delacour/react-native-charts": "0.7.1-alpha.20261105125648",
187
191
  "@legendapp/list": ">=3.3",
188
192
  "react-native-skia": ">=3.9.0",
189
193
  "expo-linear-gradient": ">=15",
@@ -132,7 +132,9 @@ or drops its focus.
132
132
  slack under a footer's counter. The block takes a `-mt-*` / `-mb-*` equal to
133
133
  the multiline `py-*` (the `blockPosition` compounds), the way a horizontal
134
134
  `Separator` bleeds through the horizontal inset, so its own padding is all
135
- there is on either side.
135
+ there is on either side. Only the outermost block takes it — the first `start`
136
+ block and the last `end` block, picked by the pure `resolveOuterBlocks`. A
137
+ second block in a section would be pulled over its separator.
136
138
  - **A `Block` draws no border.** Divide it from the row with a `Separator`, or
137
139
  leave it flush. Bare text and `Icon`s in it take the decorator treatment.
138
140
  - **`Separator` has no `orientation` prop.** `InputGroupPlacementProvider` tells
@@ -2,7 +2,12 @@ import { type ReactElement, type ReactNode, useMemo } from "react";
2
2
  import { View } from "react-native";
3
3
  import { IconDefaultsProvider } from "../icon";
4
4
  import { TextClassProvider } from "../text/text.context";
5
- import { InputGroupPlacementProvider, useInputGroupPart, useInputGroupPlacement } from "./input.context";
5
+ import {
6
+ InputGroupPlacementProvider,
7
+ useInputGroupPart,
8
+ useInputGroupPlacement,
9
+ useIsOuterInputGroupBlock,
10
+ } from "./input.context";
6
11
  import { INPUT_DECORATOR_ICON_TOKEN, INPUT_INVALID_DECORATOR_ICON_TOKEN, inputVariants } from "./input.variants";
7
12
  import { wrapTextChildren } from "./input-group-decorator";
8
13
 
@@ -41,7 +46,10 @@ export type InputGroupBlockProps = {
41
46
  export function InputGroupBlock({ position, className, children }: InputGroupBlockProps): ReactElement {
42
47
  const { isInvalid, size } = useInputGroupPart("Input.Group.Block");
43
48
  const placement = useInputGroupPlacement();
44
- const slots = inputVariants({ blockPosition: position, isInvalid, size });
49
+ // Only the block against the border cancels the box's padding. Another
50
+ // block in the same section would be pulled over what sits beside it.
51
+ const isOuter = useIsOuterInputGroupBlock();
52
+ const slots = inputVariants({ blockPosition: isOuter ? position : "none", isInvalid, size });
45
53
 
46
54
  if (process.env.NODE_ENV !== "production" && placement === "row") {
47
55
  console.warn(
@@ -13,7 +13,12 @@ import { useButtonGroupItemContext } from "../button/button.context";
13
13
  import { resolveButtonSizeStep } from "../button/button.variants";
14
14
  import { useFieldContext } from "../field/field.context";
15
15
  import { Pressable } from "../pressable";
16
- import { type InputGroupContextValue, InputGroupPlacementProvider, InputGroupProvider } from "./input.context";
16
+ import {
17
+ type InputGroupContextValue,
18
+ InputGroupOuterBlockProvider,
19
+ InputGroupPlacementProvider,
20
+ InputGroupProvider,
21
+ } from "./input.context";
17
22
  import {
18
23
  type InputGroupChildKind,
19
24
  type InputGroupSegment,
@@ -22,6 +27,7 @@ import {
22
27
  resolveGroupSegments,
23
28
  resolveInputGroupClass,
24
29
  resolveInputGroupRowClass,
30
+ resolveOuterBlocks,
25
31
  } from "./input.variants";
26
32
  import { InputGroupBlock, type InputGroupBlockProps } from "./input-group-block";
27
33
  import { InputGroupButton } from "./input-group-button";
@@ -137,15 +143,26 @@ function InputGroupRoot({
137
143
  /**
138
144
  * Sorts a group's direct children into the box's three sections — above the
139
145
  * row, in it, and below it. `resolveGroupSegments` holds the rule; this only
140
- * names what each child is.
146
+ * names what each child is. The outermost block of each section is marked, so
147
+ * only it cancels the box's padding (`resolveOuterBlocks`).
141
148
  */
142
149
  function sortIntoSections(children: ReactNode): Record<InputGroupSegment, ReactNode[]> {
143
150
  const items = Children.toArray(children);
144
- const segments = resolveGroupSegments(items.map(classifyGroupChild));
151
+ const kinds = items.map(classifyGroupChild);
152
+ const segments = resolveGroupSegments(kinds);
153
+ const outer = resolveOuterBlocks(kinds);
145
154
  const sections: Record<InputGroupSegment, ReactNode[]> = { end: [], row: [], start: [] };
146
155
 
147
156
  for (const [index, child] of items.entries()) {
148
- sections[segments[index] ?? "row"].push(child);
157
+ const placed =
158
+ outer[index] && isValidElement(child) ? (
159
+ <InputGroupOuterBlockProvider key={child.key} value>
160
+ {child}
161
+ </InputGroupOuterBlockProvider>
162
+ ) : (
163
+ child
164
+ );
165
+ sections[segments[index] ?? "row"].push(placed);
149
166
  }
150
167
 
151
168
  return sections;
@@ -116,3 +116,26 @@ InputGroupPlacementProvider.displayName = "DelacourUI.Input.Group.PlacementProvi
116
116
  export function useInputGroupPlacement(): InputGroupPlacement | null {
117
117
  return use(InputGroupPlacementContext);
118
118
  }
119
+
120
+ const InputGroupOuterBlockContext = createContext(false);
121
+
122
+ /**
123
+ * Tells an `Input.Group.Block` that it is the outermost one in its section —
124
+ * the first `start` block or the last `end` block — and so sits against the
125
+ * box's border. `Input.Group` sets it while it sorts its children.
126
+ */
127
+ export function InputGroupOuterBlockProvider({
128
+ value,
129
+ children,
130
+ }: {
131
+ value: boolean;
132
+ children: ReactNode;
133
+ }): ReactElement {
134
+ return <InputGroupOuterBlockContext value={value}>{children}</InputGroupOuterBlockContext>;
135
+ }
136
+ InputGroupOuterBlockProvider.displayName = "DelacourUI.Input.Group.OuterBlockProvider";
137
+
138
+ /** Whether this block is the outermost one in its section. False outside a group. */
139
+ export function useIsOuterInputGroupBlock(): boolean {
140
+ return use(InputGroupOuterBlockContext);
141
+ }
@@ -24,6 +24,7 @@ import {
24
24
  resolveInputGroupClass,
25
25
  resolveInputGroupRowClass,
26
26
  resolveIsDecorative,
27
+ resolveOuterBlocks,
27
28
  resolvePlaceholderAccentClass,
28
29
  resolveSelectionAccentClass,
29
30
  } from "./input.variants";
@@ -660,6 +661,31 @@ describe("resolveGroupSegments", () => {
660
661
  });
661
662
  });
662
663
 
664
+ describe("resolveOuterBlocks", () => {
665
+ test("marks only the first start block and the last end block", () => {
666
+ expect(
667
+ resolveOuterBlocks(["block-start", "separator", "block-start", "content", "block-end", "separator", "block-end"])
668
+ ).toEqual([true, false, false, false, false, false, true]);
669
+ });
670
+
671
+ test("follows the written order, not the section order", () => {
672
+ expect(resolveOuterBlocks(["block-end", "content", "block-start", "block-end"])).toEqual([
673
+ false,
674
+ false,
675
+ true,
676
+ true,
677
+ ]);
678
+ });
679
+
680
+ test("marks a lone block on each edge", () => {
681
+ expect(resolveOuterBlocks(["block-start", "content", "block-end"])).toEqual([true, false, true]);
682
+ });
683
+
684
+ test("marks nothing when there are no blocks", () => {
685
+ expect(resolveOuterBlocks(["content", "separator", "content"])).toEqual([false, false, false]);
686
+ });
687
+ });
688
+
663
689
  describe("resolveInputAccessibilityLabel", () => {
664
690
  test("an explicit label wins over the enclosing Field.Label", () => {
665
691
  expect(resolveInputAccessibilityLabel("Work email", "Email")).toBe("Work email");
@@ -483,6 +483,22 @@ export function resolveGroupSegments(kinds: readonly InputGroupChildKind[]): Inp
483
483
  });
484
484
  }
485
485
 
486
+ /**
487
+ * Which of a group's direct children are the outermost blocks: the first
488
+ * `start` block and the last `end` block.
489
+ *
490
+ * Only these sit against the box's border, so only these take the negative
491
+ * margin that cancels the box's own padding. A second start block sits under a
492
+ * separator or another block, and pulling it up would draw it over that.
493
+ *
494
+ * Pure, so it is unit-testable. See AGENTS.md.
495
+ */
496
+ export function resolveOuterBlocks(kinds: readonly InputGroupChildKind[]): boolean[] {
497
+ const firstStart = kinds.indexOf("block-start");
498
+ const lastEnd = kinds.lastIndexOf("block-end");
499
+ return kinds.map((_, index) => index === firstStart || index === lastEnd);
500
+ }
501
+
486
502
  /**
487
503
  * The `accent-*` class uniwind resolves the placeholder colour from.
488
504
  *
@@ -19,7 +19,7 @@ imports an overlay never resolves it. The consequence is the same one thing to d
19
19
  | `overlay-portal.tsx` | `Overlay.Portal` — registers while mounted, reports `isExiting`, teleports to `"root"` in a `box-none` absolute fill carrying the registry's `zIndex`; inline without a provider |
20
20
  | `overlay-scrim.tsx` | `Overlay.Scrim` — `bg-overlay`, opacity follows presence, hidden from assistive technology |
21
21
  | `overlay.context.tsx` | **Leaf.** `OverlayContext`, `TeleportProvidedContext` and their hooks. `bottom-sheet/` imports it |
22
- | `overlay-registry.ts` | **Pure.** The z-order reducer, `zIndexOfOverlay`, `topOverlay`, `isTopOverlay`, `hasModalOverlay`, `topModalOverlay`, `isBelowTopModal`, `OVERLAY_LAYER_BASE` |
22
+ | `overlay-registry.ts` | **Pure.** The z-order reducer, `zIndexOfOverlay`, `topOverlay`, `isTopOverlay`, `hasModalOverlay`, `hidesAppContent`, `topModalOverlay`, `isBelowTopModal`, `OVERLAY_LAYER_BASE` |
23
23
  | `overlay-presence.ts` | **Pure.** `reducePresence` — `closed → entering → open → exiting → closed`; `isCurrentFinish` |
24
24
  | `overlay-teleport.ts` | **Pure.** `TELEPORT_INLINE`, `isTeleportInline` — whether teleport draws an overlay in place, as its Jest mock does |
25
25
  | `overlay.variants.ts` | `overlayVariants` (`scrim`), `OVERLAY_MOTION`, `OVERLAY_SCRIM_TOKEN` |
@@ -73,7 +73,7 @@ imports an overlay never resolves it. The consequence is the same one thing to d
73
73
  - **A modal overlay hides the app from screen readers.** Teleport's `"root"` host is a sibling of
74
74
  the provider's content `View`, so a panel's `accessibilityViewIsModal` hides only its siblings in
75
75
  the host, and VoiceOver or TalkBack could still reach the app behind a dialog. While
76
- `hasModalOverlay` is true the provider sets `accessibilityElementsHidden` and
76
+ `hidesAppContent` is true the provider sets `accessibilityElementsHidden` and
77
77
  `importantForAccessibility="no-hide-descendants"` on that `View`. Overlays and sheets draw in the
78
78
  host, outside it, and stay reachable. **An exiting modal does not count.** Pass
79
79
  `isExiting={phase === "exiting"}` to `Overlay.Portal`, as Dialog and Drawer do: the registry keeps
@@ -82,7 +82,9 @@ imports an overlay never resolves it. The consequence is the same one thing to d
82
82
  Jest mock renders a portal in place, inside that `View`, so hiding it would hide the dialog too
83
83
  and every query for it would fail. The test kit sets the global `TELEPORT_INLINE` symbol to say
84
84
  so, and the provider then leaves the app visible. It is a symbol on `globalThis`, not an import, so
85
- the test kit installs without Overlay.
85
+ the test kit installs without Overlay. **Not for a modal drawn in the app.** A portal with
86
+ `isInline` or a `hostName` other than `"root"` may be inside that `View`, so it registers with
87
+ `isInApp` and does not hide the app. It still stacks and takes the back button.
86
88
  - **Screen readers stay inside the top modal.** Hiding the app content does not hide a dialog under
87
89
  another dialog: both draw in the `"root"` host. So each portal reads the registry: the top open modal's frame sets `accessibilityViewIsModal`, and every frame drawn
88
90
  under it sets `accessibilityElementsHidden` and `importantForAccessibility="no-hide-descendants"`.
@@ -44,7 +44,8 @@ let hasWarnedMissingProvider = false;
44
44
  *
45
45
  * While a modal overlay is open above it, the frame is hidden from screen
46
46
  * readers, so VoiceOver and TalkBack cannot leave the top dialog for one under
47
- * it.
47
+ * it. A modal with `isInline` or a custom `hostName` still stacks this way, but
48
+ * does not make `OverlayProvider` hide the app content, which may hold it.
48
49
  *
49
50
  * Without an `OverlayProvider` above, or with `isInline`, the children render
50
51
  * where they are written, in an absolute fill of the nearest positioned
@@ -62,13 +63,17 @@ export function OverlayPortal({
62
63
  const overlayId = id ?? ownId;
63
64
  const registry = useOptionalOverlay();
64
65
 
66
+ // Only the `"root"` host sits beside the provider's app content. Inline, or
67
+ // in another host, the overlay may be inside that content, so its modal must
68
+ // not hide it.
69
+ const isInApp = isInline || hostName !== "root";
65
70
  const present = registry?.present;
66
71
  const dismissed = registry?.dismissed;
67
72
  useEffect(() => {
68
73
  if (present === undefined || dismissed === undefined) return;
69
- present(overlayId, layer);
74
+ present(overlayId, layer, isInApp);
70
75
  return () => dismissed(overlayId);
71
- }, [present, dismissed, overlayId, layer]);
76
+ }, [present, dismissed, overlayId, layer, isInApp]);
72
77
 
73
78
  const exiting = registry?.exiting;
74
79
  useEffect(() => {
@@ -1,6 +1,7 @@
1
1
  import { describe, expect, test } from "bun:test";
2
2
  import {
3
3
  hasModalOverlay,
4
+ hidesAppContent,
4
5
  INITIAL_OVERLAY_REGISTRY,
5
6
  isBelowTopModal,
6
7
  isTopOverlay,
@@ -169,6 +170,51 @@ describe("hasModalOverlay", () => {
169
170
  });
170
171
  });
171
172
 
173
+ describe("hidesAppContent", () => {
174
+ test("is true while a teleported modal is open", () => {
175
+ const state = apply({ type: "open", id: "dialog", layer: "modal", isInApp: false });
176
+ expect(hidesAppContent(state)).toBe(true);
177
+ });
178
+
179
+ test("is false while the only open modal draws inside the app content", () => {
180
+ const state = apply({ type: "open", id: "dialog", layer: "modal", isInApp: true });
181
+ expect(hidesAppContent(state)).toBe(false);
182
+ });
183
+
184
+ test("is true when a teleported modal is open beside one drawn in the app", () => {
185
+ const state = apply(
186
+ { type: "open", id: "inline", layer: "modal", isInApp: true },
187
+ { type: "open", id: "teleported", layer: "modal", isInApp: false }
188
+ );
189
+ expect(hidesAppContent(state)).toBe(true);
190
+ });
191
+
192
+ test("is false while the only teleported modal is exiting", () => {
193
+ const state = apply(
194
+ { type: "open", id: "dialog", layer: "modal", isInApp: false },
195
+ { type: "exiting", id: "dialog", isExiting: true }
196
+ );
197
+ expect(hidesAppContent(state)).toBe(false);
198
+ });
199
+
200
+ test("ignores anchored overlays and toasts", () => {
201
+ const state = apply(
202
+ { type: "open", id: "pop", layer: "anchored", isInApp: false },
203
+ { type: "open", id: "toast", layer: "toast", isInApp: false }
204
+ );
205
+ expect(hidesAppContent(state)).toBe(false);
206
+ });
207
+
208
+ test("a modal drawn in the app still stacks as the top modal", () => {
209
+ const state = apply(
210
+ { type: "open", id: "lower", layer: "modal", isInApp: false },
211
+ { type: "open", id: "upper", layer: "modal", isInApp: true }
212
+ );
213
+ expect(topModalOverlay(state)).toBe("upper");
214
+ expect(isBelowTopModal(state, "lower")).toBe(true);
215
+ });
216
+ });
217
+
172
218
  describe("topModalOverlay / isBelowTopModal", () => {
173
219
  test("is null with no modal open", () => {
174
220
  const state = apply({ type: "open", id: "pop", layer: "anchored" });
@@ -28,6 +28,11 @@ export type OverlayRegistryEntry = {
28
28
  seq: number;
29
29
  /** Playing its exit animation: still drawn, no longer what the screen is about. */
30
30
  isExiting: boolean;
31
+ /**
32
+ * Draws inside the provider's app content `View` — inline, or in a host other
33
+ * than `"root"` — rather than in the `"root"` host beside it.
34
+ */
35
+ isInApp: boolean;
31
36
  };
32
37
 
33
38
  export type OverlayRegistryState = {
@@ -38,7 +43,7 @@ export type OverlayRegistryState = {
38
43
  export const INITIAL_OVERLAY_REGISTRY: OverlayRegistryState = { nextSeq: 1, open: [] };
39
44
 
40
45
  export type OverlayRegistryAction =
41
- | { type: "open"; id: string; layer: OverlayLayer }
46
+ | { type: "open"; id: string; layer: OverlayLayer; isInApp?: boolean }
42
47
  | { type: "exiting"; id: string; isExiting: boolean }
43
48
  | { type: "close"; id: string };
44
49
 
@@ -47,7 +52,7 @@ export type OverlayRegistryAction =
47
52
  *
48
53
  * An `open` stamps the next sequence number; an overlay already open is
49
54
  * re-stamped rather than duplicated, which brings it forward and keeps its
50
- * `isExiting`. An `exiting` marks an overlay that is animating closed, and
55
+ * `isExiting`. `isInApp` defaults to false. An `exiting` marks an overlay that is animating closed, and
51
56
  * keeps its place in the z-order. A `close` of an overlay that is not open, or an `exiting` that
52
57
  * changes nothing, returns the same state object, so an unmount racing an exit
53
58
  * causes no render.
@@ -77,7 +82,10 @@ export function reduceOverlayRegistry(
77
82
  const isExiting = previous?.isExiting ?? false;
78
83
  return {
79
84
  nextSeq: state.nextSeq + 1,
80
- open: [...others, { id: action.id, layer: action.layer, seq: state.nextSeq, isExiting }],
85
+ open: [
86
+ ...others,
87
+ { id: action.id, layer: action.layer, seq: state.nextSeq, isExiting, isInApp: action.isInApp ?? false },
88
+ ],
81
89
  };
82
90
  }
83
91
  }
@@ -135,6 +143,18 @@ export function hasModalOverlay(state: OverlayRegistryState): boolean {
135
143
  return state.open.some((entry) => entry.layer === "modal" && !entry.isExiting);
136
144
  }
137
145
 
146
+ /**
147
+ * Whether `OverlayProvider` must hide its app content from screen readers.
148
+ *
149
+ * True while a modal that is not exiting draws in the `"root"` host, beside the
150
+ * app content. A modal that draws inside the app content — inline, or in another
151
+ * host — does not count: hiding the content would hide that modal too. It still
152
+ * stacks and answers the back button like any other modal.
153
+ */
154
+ export function hidesAppContent(state: OverlayRegistryState): boolean {
155
+ return state.open.some((entry) => entry.layer === "modal" && !entry.isExiting && !entry.isInApp);
156
+ }
157
+
138
158
  /**
139
159
  * The modal overlay drawn on top that is not animating closed, or `null`.
140
160
  *
@@ -6,7 +6,7 @@
6
6
  * A symbol on `globalThis` rather than an export the test kit imports, so the test kit needs no
7
7
  * Overlay to be installed beside it.
8
8
  */
9
- export const TELEPORT_INLINE: unique symbol = Symbol.for("delacour.overlay.teleportInline");
9
+ export const TELEPORT_INLINE = Symbol.for("delacour.overlay.teleportInline");
10
10
 
11
11
  /**
12
12
  * Whether an overlay draws inside the app content rather than beside it.
@@ -5,8 +5,11 @@ import type { OverlayLayer, OverlayRegistryState } from "./overlay-registry";
5
5
  export type OverlayContextValue = {
6
6
  /** The open set and its z-order. A change re-renders every presented portal. */
7
7
  state: OverlayRegistryState;
8
- /** A portal reports that its overlay is presented, and in which layer. */
9
- present: (id: string, layer: OverlayLayer) => void;
8
+ /**
9
+ * A portal reports that its overlay is presented, in which layer, and
10
+ * whether it draws inside the app content rather than in the `"root"` host.
11
+ */
12
+ present: (id: string, layer: OverlayLayer, isInApp: boolean) => void;
10
13
  /** A portal reports that its overlay started, or stopped, animating closed. */
11
14
  exiting: (id: string, isExiting: boolean) => void;
12
15
  /** The overlay's portal unmounted. */
@@ -25,6 +25,8 @@ type DemoProps = {
25
25
  onDismiss?: () => void;
26
26
  onBack?: () => void;
27
27
  onExited?: () => void;
28
+ isInline?: boolean;
29
+ hostName?: string;
28
30
  };
29
31
 
30
32
  function Demo({
@@ -34,6 +36,8 @@ function Demo({
34
36
  onDismiss,
35
37
  onBack,
36
38
  onExited,
39
+ isInline,
40
+ hostName,
37
41
  }: DemoProps): ReactElement | null {
38
42
  const [isOpen, setIsOpen] = useState(defaultOpen);
39
43
  const { isPresent, phase, progress } = useOverlayPresence({ isOpen, enterMs: 1, exitMs: 1, onExited });
@@ -54,7 +58,7 @@ function Demo({
54
58
  <>
55
59
  <Text onPress={() => setIsOpen(true)}>{`open ${name}`}</Text>
56
60
  {isPresent ? (
57
- <Overlay.Portal id={name} isExiting={phase === "exiting"} layer={layer}>
61
+ <Overlay.Portal hostName={hostName} id={name} isExiting={phase === "exiting"} isInline={isInline} layer={layer}>
58
62
  <Overlay.Scrim onDismiss={close} progress={progress} testID={`${name}-scrim`} />
59
63
  <View testID={`${name}-panel`}>
60
64
  <Text>{`${name} panel`}</Text>
@@ -181,6 +185,13 @@ async function withTeleportOutOfTree(body: () => Promise<void>): Promise<void> {
181
185
  }
182
186
  }
183
187
 
188
+ /** The provider's app content `View`: the parent of a demo's trigger text, hidden or not. */
189
+ function appContent(name: string): { props: { accessibilityElementsHidden?: boolean } } {
190
+ const parent = screen.getByText(`open ${name}`, { includeHiddenElements: true }).parent;
191
+ if (parent === null) throw new Error(`No app content around the ${name} trigger`);
192
+ return parent;
193
+ }
194
+
184
195
  describe("OverlayProvider and screen readers", () => {
185
196
  test("the test kit marks teleport inline, so an open modal and the app stay reachable", async () => {
186
197
  await renderWithProviders(<Demo name="kit" />, { wrapper: Provider });
@@ -246,6 +257,34 @@ describe("OverlayProvider and screen readers", () => {
246
257
  expect(frame("lower").props.accessibilityViewIsModal).toBe(true);
247
258
  });
248
259
 
260
+ test("an inline modal does not hide the app content that holds it", async () => {
261
+ await withTeleportOutOfTree(async () => {
262
+ await renderWithProviders(<Demo isInline name="dialog" />, { wrapper: Provider });
263
+ expect(appContent("dialog").props.accessibilityElementsHidden).toBe(false);
264
+ expect(frame("dialog").props.accessibilityViewIsModal).toBe(true);
265
+ });
266
+ });
267
+
268
+ test("a modal in a custom host does not hide the app content", async () => {
269
+ await withTeleportOutOfTree(async () => {
270
+ await renderWithProviders(<Demo hostName="sheet" name="dialog" />, { wrapper: Provider });
271
+ expect(appContent("dialog").props.accessibilityElementsHidden).toBe(false);
272
+ });
273
+ });
274
+
275
+ test("a teleported modal still hides the app content beside an inline one", async () => {
276
+ await withTeleportOutOfTree(async () => {
277
+ await renderWithProviders(
278
+ <>
279
+ <Demo isInline name="inline" />
280
+ <Demo name="teleported" />
281
+ </>,
282
+ { wrapper: Provider }
283
+ );
284
+ expect(appContent("teleported").props.accessibilityElementsHidden).toBe(true);
285
+ });
286
+ });
287
+
249
288
  test("a toast does not hide the app content", async () => {
250
289
  await withTeleportOutOfTree(async () => {
251
290
  await renderWithProviders(<Demo name="toast" layer="toast" />, { wrapper: Provider });
@@ -9,7 +9,7 @@ import {
9
9
  } from "./overlay.context";
10
10
  import { OverlayPortal } from "./overlay-portal";
11
11
  import {
12
- hasModalOverlay,
12
+ hidesAppContent,
13
13
  INITIAL_OVERLAY_REGISTRY,
14
14
  type OverlayLayer,
15
15
  type OverlayRegistryAction,
@@ -28,8 +28,8 @@ function OverlayRoot({ children }: OverlayProviderProps): ReactElement {
28
28
  const current = useRef<OverlayRegistryState>(INITIAL_OVERLAY_REGISTRY);
29
29
  const [state, setState] = useState<OverlayRegistryState>(INITIAL_OVERLAY_REGISTRY);
30
30
 
31
- const present = useCallback((id: string, layer: OverlayLayer) => {
32
- current.current = reduceOverlayRegistry(current.current, { type: "open", id, layer });
31
+ const present = useCallback((id: string, layer: OverlayLayer, isInApp: boolean) => {
32
+ current.current = reduceOverlayRegistry(current.current, { type: "open", id, layer, isInApp });
33
33
  setState(current.current);
34
34
  }, []);
35
35
 
@@ -66,10 +66,12 @@ function OverlayRoot({ children }: OverlayProviderProps): ReactElement {
66
66
  // While a modal overlay is open, the app content is hidden from VoiceOver
67
67
  // and TalkBack. The overlays draw in teleport's host, outside this view in
68
68
  // the native tree, so they stay reachable. An exiting modal no longer hides
69
- // it, so focus can return to the trigger in `onExited`. Where teleport draws
70
- // inline — the Jest mock does — the overlays are inside this view, so it
71
- // stays visible.
72
- const isAppHidden = hasModalOverlay(state) && !isTeleportInline();
69
+ // it, so focus can return to the trigger in `onExited`. A modal drawn
70
+ // inside this view — `isInline`, or a host other than `"root"` — does not
71
+ // hide it, since that would hide the modal too. Where teleport draws inline
72
+ // — the Jest mock does — every overlay is inside this view, so it stays
73
+ // visible.
74
+ const isAppHidden = hidesAppContent(state) && !isTeleportInline();
73
75
  const registry = (
74
76
  <OverlayContext.Provider value={value}>
75
77
  <View
@@ -0,0 +1,27 @@
1
+ import { describe, expect, jest, test } from "@jest/globals";
2
+ import { createElement, Fragment, type ReactElement } from "react";
3
+ import { render } from "../test/render";
4
+ import { Slot } from "./slot";
5
+
6
+ type OptionalPressChildProps = { onPress?: () => void; onReceive: (onPress: (() => void) | undefined) => void };
7
+
8
+ /**
9
+ * A child whose `onPress` is optional, like `Button`. It reports the handler it
10
+ * receives instead of being pressed, because a press in the test renderer walks
11
+ * up to the `Slot`'s own `onPress` prop and passes whether or not the child got it.
12
+ */
13
+ function OptionalPressChild({ onPress, onReceive }: OptionalPressChildProps): ReactElement | null {
14
+ onReceive(onPress);
15
+ return null;
16
+ }
17
+
18
+ describe("Slot", () => {
19
+ test("rejects a fragment child, which cannot receive props", async () => {
20
+ jest.spyOn(console, "error").mockImplementation(() => {});
21
+ const fragment = createElement(Fragment, null, <OptionalPressChild onReceive={() => {}} />);
22
+ await expect(render(<Slot onPress={jest.fn()}>{fragment}</Slot>)).rejects.toThrow(
23
+ "Slot expects a single React element child; text and fragments cannot receive props."
24
+ );
25
+ jest.restoreAllMocks();
26
+ });
27
+ });
package/src/lib/slot.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import { Children, cloneElement, isValidElement, type ReactElement, type ReactNode, type Ref } from "react";
1
+ import { Children, cloneElement, Fragment, isValidElement, type ReactElement, type ReactNode, type Ref } from "react";
2
2
  import { composeRefs } from "./compose-refs";
3
3
  import { mergeProps } from "./merge-props";
4
4
 
@@ -32,7 +32,9 @@ export function Slot({ children, ...slotProps }: SlotProps): ReactElement {
32
32
 
33
33
  const child = Children.only(children);
34
34
 
35
- if (!isValidElement(child)) {
35
+ // A fragment passes `isValidElement` but drops every prop it is given, so the
36
+ // donated handlers would never reach the element inside it.
37
+ if (!isValidElement(child) || child.type === Fragment) {
36
38
  throw new Error("Slot expects a single React element child; text and fragments cannot receive props.");
37
39
  }
38
40