@ankhorage/zora 28.5.2 → 28.6.0

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 (77) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +5 -1
  3. package/dist/capabilities/index.js +73 -3
  4. package/dist/capabilities/index.js.map +3 -3
  5. package/dist/features/carousel/Carousel.d.ts.map +1 -1
  6. package/dist/features/carousel/Carousel.js +85 -8
  7. package/dist/features/carousel/Carousel.js.map +1 -1
  8. package/dist/features/form/select/adapters/inbound/Select.native.d.ts.map +1 -1
  9. package/dist/features/form/select/adapters/inbound/Select.native.js +71 -8
  10. package/dist/features/form/select/adapters/inbound/Select.native.js.map +1 -1
  11. package/dist/features/form/select/adapters/inbound/Select.web.d.ts.map +1 -1
  12. package/dist/features/form/select/adapters/inbound/Select.web.js +5 -3
  13. package/dist/features/form/select/adapters/inbound/Select.web.js.map +1 -1
  14. package/dist/features/form/select/composition/SelectSearchInput.d.ts +10 -0
  15. package/dist/features/form/select/composition/SelectSearchInput.d.ts.map +1 -0
  16. package/dist/features/form/select/composition/SelectSearchInput.js +11 -0
  17. package/dist/features/form/select/composition/SelectSearchInput.js.map +1 -0
  18. package/dist/features/form/select/composition/getVisibleSelectOptions.d.ts +4 -0
  19. package/dist/features/form/select/composition/getVisibleSelectOptions.d.ts.map +1 -0
  20. package/dist/features/form/select/composition/getVisibleSelectOptions.js +8 -0
  21. package/dist/features/form/select/composition/getVisibleSelectOptions.js.map +1 -0
  22. package/dist/features/form/select/composition/useSelectController.d.ts +3 -0
  23. package/dist/features/form/select/composition/useSelectController.d.ts.map +1 -1
  24. package/dist/features/form/select/composition/useSelectController.js +11 -2
  25. package/dist/features/form/select/composition/useSelectController.js.map +1 -1
  26. package/dist/features/form/select/selectMeta.d.ts +99 -1
  27. package/dist/features/form/select/selectMeta.d.ts.map +1 -1
  28. package/dist/features/form/select/selectMeta.js +71 -1
  29. package/dist/features/form/select/selectMeta.js.map +1 -1
  30. package/dist/features/registry/bindableComponentMeta.d.ts +79 -1
  31. package/dist/features/registry/bindableComponentMeta.d.ts.map +1 -1
  32. package/dist/features/registry/bindableComponentMeta.js +59 -1
  33. package/dist/features/registry/bindableComponentMeta.js.map +1 -1
  34. package/dist/types/select.d.ts +10 -0
  35. package/dist/types/select.d.ts.map +1 -1
  36. package/dist/types/select.js.map +1 -1
  37. package/package.json +29 -3
  38. package/src/features/carousel/Carousel.test.ts +243 -7
  39. package/src/features/carousel/Carousel.tsx +135 -26
  40. package/src/features/form/select/adapters/inbound/Select.native.test.tsx +322 -0
  41. package/src/features/form/select/adapters/inbound/Select.native.tsx +135 -13
  42. package/src/features/form/select/adapters/inbound/Select.web.tsx +6 -3
  43. package/src/features/form/select/composition/SelectSearchInput.tsx +33 -0
  44. package/src/features/form/select/composition/getVisibleSelectOptions.test.ts +22 -0
  45. package/src/features/form/select/composition/getVisibleSelectOptions.ts +13 -0
  46. package/src/features/form/select/composition/useSelectController.ts +25 -2
  47. package/src/features/form/select/public.test.ts +31 -1
  48. package/src/features/form/select/selectMeta.ts +71 -1
  49. package/src/features/registry/bindableComponentMeta.test.ts +6 -0
  50. package/src/features/registry/bindableComponentMeta.ts +59 -1
  51. package/src/features/registry/featureManifest.test.ts +10 -0
  52. package/src/types/select.ts +10 -0
  53. package/web-dist/chunks/{Accordion-sj1n06dw.js → Accordion-9dk62zn9.js} +84 -24
  54. package/web-dist/chunks/Accordion-ar8qe05j.js +53 -0
  55. package/web-dist/chunks/{Accordion-ge7cjtwy.js → Accordion-mpb070cf.js} +3 -3
  56. package/web-dist/chunks/{Accordion-554f42yj.js → Accordion-sj30964p.js} +4 -4
  57. package/web-dist/chunks/{Accordion-2bygfpwg.js → Accordion-xhxv2v0g.js} +62 -2
  58. package/web-dist/chunks/{RichTextClient-70qt7037.js → RichTextClient-7qqj2dpw.js} +3 -4
  59. package/web-dist/components/auth-screen/AuthScreen.js +2 -3
  60. package/web-dist/components/carousel/Carousel.js +97 -24
  61. package/web-dist/components/color-hue-scale/ColorHueScale.js +4 -3
  62. package/web-dist/components/color-picker/ColorPicker.js +4 -3
  63. package/web-dist/components/color-tone/ColorTone.js +4 -3
  64. package/web-dist/components/color-wheel/ColorWheel.js +4 -3
  65. package/web-dist/components/forgot-password-form/ForgotPasswordForm.js +2 -3
  66. package/web-dist/components/o-auth-provider-button/OAuthProviderButton.js +2 -3
  67. package/web-dist/components/o-auth-provider-list/OAuthProviderList.js +2 -3
  68. package/web-dist/components/otp-form/OtpForm.js +2 -3
  69. package/web-dist/components/rich-text/RichText.js +2 -2
  70. package/web-dist/components/search-input/SearchInput.js +5 -52
  71. package/web-dist/components/select/Select.js +3 -1
  72. package/web-dist/components/select/Select.types-0.d.ts +10 -0
  73. package/web-dist/components/sign-in-form/SignInForm.js +2 -3
  74. package/web-dist/components/sign-up-form/SignUpForm.js +2 -3
  75. package/web-dist/components/text-input/TextInput.js +4 -5
  76. package/web-dist/manifest.json +39 -41
  77. package/web-dist/chunks/Accordion-49d0frg7.js +0 -66
@@ -48,6 +48,12 @@ export function Carousel({
48
48
  }: CarouselProps) {
49
49
  const { theme } = useZoraTheme();
50
50
  const [width, setWidth] = React.useState(0);
51
+ const initialIndex = normalizeSlideIndex(index ?? defaultIndex ?? 0, slides.length);
52
+ const initialSlide = slides.at(initialIndex);
53
+ const [mountedSlideKeys, setMountedSlideKeys] = React.useState<ReadonlySet<string>>(() =>
54
+ initialSlide ? new Set([initialSlide.key]) : new Set(),
55
+ );
56
+ const [readySlideKeys, setReadySlideKeys] = React.useState<ReadonlySet<string>>(() => new Set());
51
57
  const {
52
58
  activeIndex,
53
59
  controlledWithoutHandler,
@@ -68,6 +74,47 @@ export function Carousel({
68
74
  reducedMotion,
69
75
  });
70
76
 
77
+ const activeSlide = slides.at(activeIndex);
78
+ const nextIndex = getNextSlideIndex(activeIndex, slides.length, enabledLoop);
79
+ const nextSlide = nextIndex === undefined ? undefined : slides.at(nextIndex);
80
+ const activeSlideKey = activeSlide?.key;
81
+ const nextSlideKey = nextSlide?.key;
82
+ const mountedKeys = ensureMountedSlide(
83
+ ensureMountedSlide(mountedSlideKeys, activeSlideKey),
84
+ getPreloadedSlideKey(activeSlideKey, nextSlideKey, readySlideKeys),
85
+ );
86
+
87
+ const markSlideLoaded = React.useCallback(
88
+ (slideKey: string) => {
89
+ setReadySlideKeys((current) => ensureMountedSlide(current, slideKey));
90
+ if (slideKey === activeSlideKey) {
91
+ setMountedSlideKeys((current) => ensureMountedSlide(current, nextSlideKey));
92
+ }
93
+ },
94
+ [activeSlideKey, nextSlideKey],
95
+ );
96
+
97
+ const completeTransition = React.useCallback(
98
+ (completedSlideKey: string) => {
99
+ if (!activeSlideKey || completedSlideKey !== activeSlideKey) return;
100
+ const transitionRetentionKeys = [activeSlideKey, nextSlideKey].filter(
101
+ (slideKey): slideKey is string => slideKey !== undefined,
102
+ );
103
+ setMountedSlideKeys(
104
+ (current) =>
105
+ new Set(
106
+ transitionRetentionKeys.filter(
107
+ (slideKey) =>
108
+ slideKey === activeSlideKey ||
109
+ current.has(slideKey) ||
110
+ readySlideKeys.has(activeSlideKey),
111
+ ),
112
+ ),
113
+ );
114
+ },
115
+ [activeSlideKey, nextSlideKey, readySlideKeys],
116
+ );
117
+
71
118
  if (slides.length === 0) return null;
72
119
 
73
120
  const canPrevious = enabledLoop || activeIndex > 0;
@@ -81,26 +128,32 @@ export function Carousel({
81
128
  testID={testID}
82
129
  style={[{ position: 'relative', overflow: 'hidden', width: '100%', height: '100%' }, style]}
83
130
  >
84
- {slides.map((slide, slideIndex) => (
85
- <CarouselLayer
86
- key={slide.key}
87
- active={activeIndex === slideIndex}
88
- animate={slides.length > 1}
89
- animateOnMount={animateOnMount}
90
- direction={direction}
91
- enterDurationMs={enterDurationMs}
92
- exitDurationMs={exitDurationMs}
93
- imageStyle={imageStyle}
94
- initialScale={initialScale}
95
- reducedMotion={shouldReduceMotion}
96
- renderImage={renderImage}
97
- resizeMode={resizeMode}
98
- slide={slide}
99
- slideIndex={slideIndex}
100
- transition={transition}
101
- width={width}
102
- />
103
- ))}
131
+ {slides.flatMap((slide, slideIndex) =>
132
+ mountedKeys.has(slide.key)
133
+ ? [
134
+ <CarouselLayer
135
+ key={slide.key}
136
+ active={activeIndex === slideIndex}
137
+ animate={slides.length > 1}
138
+ animateOnMount={animateOnMount || activeIndex !== initialIndex}
139
+ direction={direction}
140
+ enterDurationMs={enterDurationMs}
141
+ exitDurationMs={exitDurationMs}
142
+ imageStyle={imageStyle}
143
+ initialScale={initialScale}
144
+ onImageLoad={() => markSlideLoaded(slide.key)}
145
+ onTransitionComplete={completeTransition}
146
+ reducedMotion={shouldReduceMotion}
147
+ renderImage={renderImage}
148
+ resizeMode={resizeMode}
149
+ slide={slide}
150
+ slideIndex={slideIndex}
151
+ transition={transition}
152
+ width={width}
153
+ />,
154
+ ]
155
+ : [],
156
+ )}
104
157
  <CarouselControls
105
158
  activeIndex={activeIndex}
106
159
  canNext={canNext}
@@ -145,6 +198,8 @@ interface CarouselLayerProps {
145
198
  readonly exitDurationMs?: CarouselProps['exitDurationMs'];
146
199
  readonly imageStyle: CarouselProps['imageStyle'];
147
200
  readonly initialScale?: CarouselProps['initialScale'];
201
+ readonly onImageLoad: () => void;
202
+ readonly onTransitionComplete: (slideKey: string) => void;
148
203
  readonly renderImage: CarouselProps['renderImage'];
149
204
  readonly resizeMode: CarouselProps['resizeMode'];
150
205
  readonly slide: CarouselSlide;
@@ -169,6 +224,8 @@ function CarouselLayer({
169
224
  enterDurationMs = 1200,
170
225
  exitDurationMs = 800,
171
226
  initialScale = 1.06,
227
+ onImageLoad,
228
+ onTransitionComplete,
172
229
  reducedMotion,
173
230
  renderImage,
174
231
  resizeMode,
@@ -182,6 +239,11 @@ function CarouselLayer({
182
239
  );
183
240
  const [offset] = React.useState(() => new Animated.Value(0));
184
241
  const hasMounted = React.useRef(false);
242
+ const widthRef = React.useRef(width);
243
+
244
+ React.useEffect(() => {
245
+ widthRef.current = width;
246
+ }, [width]);
185
247
 
186
248
  React.useEffect(() => {
187
249
  const firstRender = !hasMounted.current;
@@ -194,17 +256,18 @@ function CarouselLayer({
194
256
  opacity.setValue(active ? 1 : 0);
195
257
  scale.setValue(1);
196
258
  offset.setValue(0);
259
+ if (active) onTransitionComplete(slide.key);
197
260
  return;
198
261
  }
199
262
  if (transition === 'slide') {
200
263
  scale.setValue(1);
201
264
  if (active) {
202
- offset.setValue(direction * width);
265
+ offset.setValue(direction * widthRef.current);
203
266
  opacity.setValue(1);
204
267
  }
205
268
  Animated.parallel([
206
269
  Animated.timing(offset, {
207
- toValue: active ? 0 : -direction * width,
270
+ toValue: active ? 0 : -direction * widthRef.current,
208
271
  duration: Math.max(0, active ? enterDurationMs : exitDurationMs),
209
272
  easing: Easing.bezier(0.4, 0, 0.2, 1),
210
273
  useNativeDriver: true,
@@ -215,7 +278,9 @@ function CarouselLayer({
215
278
  easing: Easing.linear,
216
279
  useNativeDriver: true,
217
280
  }),
218
- ]).start();
281
+ ]).start(({ finished }) => {
282
+ if (active && finished) onTransitionComplete(slide.key);
283
+ });
219
284
  } else if (active) {
220
285
  opacity.setValue(0);
221
286
  scale.setValue(initialScale);
@@ -232,7 +297,9 @@ function CarouselLayer({
232
297
  easing: Easing.bezier(0.4, 0, 0.2, 1),
233
298
  useNativeDriver: true,
234
299
  }),
235
- ]).start();
300
+ ]).start(({ finished }) => {
301
+ if (finished) onTransitionComplete(slide.key);
302
+ });
236
303
  } else {
237
304
  Animated.timing(opacity, {
238
305
  toValue: 0,
@@ -259,7 +326,8 @@ function CarouselLayer({
259
326
  reducedMotion,
260
327
  scale,
261
328
  transition,
262
- width,
329
+ onTransitionComplete,
330
+ slide.key,
263
331
  ]);
264
332
 
265
333
  return (
@@ -271,7 +339,7 @@ function CarouselLayer({
271
339
  >
272
340
  {slide.source !== undefined ? (
273
341
  renderImage ? (
274
- renderImage(slide, slideIndex)
342
+ renderCarouselImage(renderImage(slide, slideIndex), onImageLoad)
275
343
  ) : (
276
344
  <Image
277
345
  accessibilityLabel={slide.alt}
@@ -279,6 +347,7 @@ function CarouselLayer({
279
347
  resizeMode={resizeMode}
280
348
  source={typeof slide.source === 'string' ? { uri: slide.source } : slide.source}
281
349
  style={[StyleSheet.absoluteFill, imageStyle]}
350
+ onLoad={onImageLoad}
282
351
  />
283
352
  )
284
353
  ) : null}
@@ -287,6 +356,46 @@ function CarouselLayer({
287
356
  );
288
357
  }
289
358
 
359
+ /*** Retain consumer image behavior while observing readiness for adjacent-slide preloading. */
360
+ function renderCarouselImage(image: React.ReactNode, onImageLoad: () => void): React.ReactNode {
361
+ if (!React.isValidElement<{ onLoad?: (event: unknown) => void }>(image)) return image;
362
+ const existingOnLoad = image.props.onLoad;
363
+ return React.cloneElement(image, {
364
+ onLoad: (event: unknown) => {
365
+ existingOnLoad?.(event);
366
+ onImageLoad();
367
+ },
368
+ });
369
+ }
370
+
371
+ /*** Return an immutable mounted-key set containing one requested slide. */
372
+ function ensureMountedSlide(mountedSlideKeys: ReadonlySet<string>, slideKey: string | undefined) {
373
+ if (!slideKey || mountedSlideKeys.has(slideKey)) return mountedSlideKeys;
374
+ return new Set([...mountedSlideKeys, slideKey]);
375
+ }
376
+
377
+ /*** Return the next slide key only after the active slide image is ready. */
378
+ function getPreloadedSlideKey(
379
+ activeSlideKey: string | undefined,
380
+ nextSlideKey: string | undefined,
381
+ readySlideKeys: ReadonlySet<string>,
382
+ ) {
383
+ if (!activeSlideKey || !readySlideKeys.has(activeSlideKey)) return undefined;
384
+ return nextSlideKey;
385
+ }
386
+
387
+ /*** Resolve the slide to preload without wrapping when looping is disabled. */
388
+ function getNextSlideIndex(index: number, length: number, loop: boolean): number | undefined {
389
+ if (length < 2 || (!loop && index === length - 1)) return undefined;
390
+ return (index + 1) % length;
391
+ }
392
+
393
+ /*** Clamp the initial server-rendered slide to the available slide collection. */
394
+ function normalizeSlideIndex(index: number, length: number): number {
395
+ if (length === 0) return 0;
396
+ return Math.min(Math.max(Math.trunc(index), 0), length - 1);
397
+ }
398
+
290
399
  interface CarouselNavigationProps {
291
400
  readonly activeIndex: number;
292
401
  readonly navigate: (index: number, direction: 1 | -1) => void;
@@ -0,0 +1,322 @@
1
+ import { afterAll, expect, mock, test } from 'bun:test';
2
+ import { Window } from 'happy-dom';
3
+ import React, { act } from 'react';
4
+ import { createRoot } from 'react-dom/client';
5
+
6
+ const browser = new Window();
7
+ const globals = ['window', 'document', 'Node', 'navigator', 'IS_REACT_ACT_ENVIRONMENT'] as const;
8
+ const previousGlobals = globals.map(
9
+ (key) => [key, Object.getOwnPropertyDescriptor(globalThis, key)] as const,
10
+ );
11
+ Object.assign(globalThis, {
12
+ IS_REACT_ACT_ENVIRONMENT: true,
13
+ Node: browser.Node,
14
+ document: browser.document,
15
+ navigator: browser.navigator,
16
+ window: browser,
17
+ });
18
+
19
+ let renderSheetContent: React.Dispatch<React.SetStateAction<React.ReactNode>> | undefined;
20
+ let activeSheet:
21
+ | {
22
+ readonly content: React.ReactNode;
23
+ readonly onDismiss?: () => void;
24
+ }
25
+ | undefined;
26
+ const dismissCalls: number[] = [];
27
+
28
+ /*** Replaces the active request as another shared BottomSheet consumer would. */
29
+ function replaceSheet(content: React.ReactNode) {
30
+ activeSheet = { content };
31
+ renderSheetContent?.(content);
32
+ }
33
+
34
+ /*** Dismisses the active request through the canonical BottomSheet controller. */
35
+ function dismissSheet() {
36
+ const sheet = activeSheet;
37
+ activeSheet = undefined;
38
+ renderSheetContent?.(null);
39
+ sheet?.onDismiss?.();
40
+ }
41
+
42
+ const bottomSheetController = {
43
+ dismiss: () => {
44
+ dismissCalls.push(1);
45
+ dismissSheet();
46
+ },
47
+ present: ({ content, onDismiss }: { content: React.ReactNode; onDismiss?: () => void }) => {
48
+ activeSheet = { content, onDismiss };
49
+ renderSheetContent?.(content);
50
+ },
51
+ };
52
+
53
+ await mock.module('react-native', () => ({
54
+ StyleSheet: { create: <T,>(styles: T) => styles },
55
+ }));
56
+ await mock.module('../../../../bottom-sheet/public', () => ({
57
+ BottomSheetFlatList: ({
58
+ data,
59
+ ListHeaderComponent,
60
+ renderItem,
61
+ }: {
62
+ data: readonly { label: string; value: string }[];
63
+ ListHeaderComponent: React.ReactNode;
64
+ renderItem: (info: { item: { label: string; value: string } }) => React.ReactNode;
65
+ }) => (
66
+ <div data-testid="select-sheet">
67
+ {ListHeaderComponent}
68
+ {data.map((item) => (
69
+ <React.Fragment key={item.value}>{renderItem({ item })}</React.Fragment>
70
+ ))}
71
+ </div>
72
+ ),
73
+ useBottomSheet: () => bottomSheetController,
74
+ }));
75
+ await mock.module('../../../../theme/adapters/inbound/withZoraThemeScope', () => ({
76
+ withZoraThemeScope: <P,>(Component: React.ComponentType<P>) => Component,
77
+ }));
78
+ await mock.module('../../composition/SelectField', () => ({
79
+ SelectField: ({ children }: { children: React.ReactNode }) => <>{children}</>,
80
+ }));
81
+ await mock.module('../../composition/SelectOptionRow', () => ({
82
+ SelectOptionRow: ({
83
+ onSelect,
84
+ option,
85
+ }: {
86
+ onSelect: (value: string) => void;
87
+ option: { label: string; value: string };
88
+ }) => <button onClick={() => onSelect(option.value)}>{option.label}</button>,
89
+ }));
90
+ await mock.module('../../composition/SelectSearchInput', () => ({
91
+ SelectSearchInput: ({
92
+ onSearchChange,
93
+ props,
94
+ searchValue,
95
+ }: {
96
+ onSearchChange: (value: string) => void;
97
+ props: { searchable?: boolean };
98
+ searchValue: string;
99
+ }) =>
100
+ props.searchable ? (
101
+ <input
102
+ aria-label="Search options"
103
+ onInput={(event) => onSearchChange(event.currentTarget.value)}
104
+ value={searchValue}
105
+ />
106
+ ) : null,
107
+ }));
108
+ await mock.module('../../composition/SelectTrigger', () => ({
109
+ SelectTrigger: ({ onPress }: { onPress: () => void }) => <button onClick={onPress}>Open</button>,
110
+ }));
111
+
112
+ const { Select } = await import('./Select.native');
113
+
114
+ afterAll(() => {
115
+ browser.close();
116
+ for (const [key, descriptor] of previousGlobals) {
117
+ if (descriptor) Object.defineProperty(globalThis, key, descriptor);
118
+ else Reflect.deleteProperty(globalThis, key);
119
+ }
120
+ });
121
+
122
+ /*** Mounts Select beside the shared sheet content owned by the canonical controller. */
123
+ function mount(strict = false) {
124
+ const host = document.createElement('div');
125
+ document.body.append(host);
126
+ const root = createRoot(host);
127
+
128
+ function SheetHost({ children }: { children: React.ReactNode }) {
129
+ const [content, setContent] = React.useState<React.ReactNode>(null);
130
+ renderSheetContent = setContent;
131
+ return (
132
+ <>
133
+ {children}
134
+ {content}
135
+ </>
136
+ );
137
+ }
138
+
139
+ return {
140
+ host,
141
+ render: (element: React.ReactNode) =>
142
+ act(() =>
143
+ Promise.resolve().then(() =>
144
+ root.render(
145
+ strict ? (
146
+ <React.StrictMode>
147
+ <SheetHost>{element}</SheetHost>
148
+ </React.StrictMode>
149
+ ) : (
150
+ <SheetHost>{element}</SheetHost>
151
+ ),
152
+ ),
153
+ ),
154
+ ),
155
+ unmount: () => act(() => Promise.resolve().then(() => root.unmount())),
156
+ };
157
+ }
158
+
159
+ test('keeps an open native sheet reactive to search, options, and current selection callbacks', async () => {
160
+ const mounted = mount();
161
+ const initialSelection: string[] = [];
162
+ const currentSelection: string[] = [];
163
+ dismissCalls.length = 0;
164
+ activeSheet = undefined;
165
+
166
+ try {
167
+ await mounted.render(
168
+ <Select
169
+ onValueChange={(value) => initialSelection.push(value)}
170
+ options={[
171
+ { label: 'Alpha', value: 'alpha' },
172
+ { label: 'Beta', value: 'beta' },
173
+ ]}
174
+ searchable
175
+ />,
176
+ );
177
+ await act(() => Promise.resolve().then(() => mounted.host.querySelector('button')?.click()));
178
+
179
+ const search = mounted.host.querySelector<HTMLInputElement>('[aria-label="Search options"]');
180
+ if (!search) throw new Error('Missing native Select search input');
181
+ search.value = 'beta';
182
+ await act(() =>
183
+ Promise.resolve().then(() =>
184
+ search.dispatchEvent(new browser.Event('input', { bubbles: true })),
185
+ ),
186
+ );
187
+ expect(mounted.host.textContent).toContain('Beta');
188
+ expect(mounted.host.textContent).not.toContain('Alpha');
189
+
190
+ await mounted.render(
191
+ <Select
192
+ onValueChange={(value) => currentSelection.push(value)}
193
+ options={[
194
+ { label: 'Beta', value: 'beta' },
195
+ { label: 'Gamma', value: 'gamma' },
196
+ ]}
197
+ searchable
198
+ searchValue="gamma"
199
+ />,
200
+ );
201
+
202
+ const controlledSearch = mounted.host.querySelector<HTMLInputElement>(
203
+ '[aria-label="Search options"]',
204
+ );
205
+ const gamma = [...mounted.host.querySelectorAll('button')].find(
206
+ (button) => button.textContent === 'Gamma',
207
+ );
208
+ expect(controlledSearch?.value).toBe('gamma');
209
+ expect(mounted.host.textContent).toContain('Gamma');
210
+ expect(mounted.host.textContent).not.toContain('Beta');
211
+ await act(() => Promise.resolve().then(() => gamma?.click()));
212
+
213
+ expect(initialSelection).toEqual([]);
214
+ expect(currentSelection).toEqual(['gamma']);
215
+ expect(dismissCalls).toHaveLength(1);
216
+ expect(mounted.host.querySelector('[data-testid="select-sheet"]')).toBeNull();
217
+ } finally {
218
+ await mounted.unmount();
219
+ mounted.host.remove();
220
+ }
221
+ });
222
+
223
+ test('releases native sheet ownership when its Select unmounts or another sheet replaces it', async () => {
224
+ const mounted = mount();
225
+ dismissCalls.length = 0;
226
+ activeSheet = undefined;
227
+
228
+ try {
229
+ await mounted.render(<Select options={[{ label: 'Alpha', value: 'alpha' }]} searchable />);
230
+ await act(() => Promise.resolve().then(() => mounted.host.querySelector('button')?.click()));
231
+ expect(mounted.host.querySelector('[data-testid="select-sheet"]')).not.toBeNull();
232
+
233
+ await mounted.unmount();
234
+ expect(dismissCalls).toHaveLength(1);
235
+ expect(activeSheet).toBeUndefined();
236
+ } finally {
237
+ mounted.host.remove();
238
+ }
239
+
240
+ const replacement = mount();
241
+ dismissCalls.length = 0;
242
+ activeSheet = undefined;
243
+
244
+ try {
245
+ await replacement.render(<Select options={[{ label: 'Alpha', value: 'alpha' }]} searchable />);
246
+ await act(() =>
247
+ Promise.resolve().then(() => replacement.host.querySelector('button')?.click()),
248
+ );
249
+ await act(() => Promise.resolve().then(() => replaceSheet(<div data-testid="other-sheet" />)));
250
+
251
+ await replacement.render(<Select options={[{ label: 'Beta', value: 'beta' }]} searchable />);
252
+ expect(replacement.host.querySelector('[data-testid="other-sheet"]')).not.toBeNull();
253
+ expect(replacement.host.querySelector('[data-testid="select-sheet"]')).toBeNull();
254
+
255
+ await replacement.unmount();
256
+ expect(dismissCalls).toHaveLength(0);
257
+ expect(replacement.host.querySelector('[data-testid="other-sheet"]')).toBeNull();
258
+ } finally {
259
+ replacement.host.remove();
260
+ }
261
+ });
262
+
263
+ test('does not reclaim a native sheet after external dismissal', async () => {
264
+ const mounted = mount();
265
+ dismissCalls.length = 0;
266
+ activeSheet = undefined;
267
+
268
+ try {
269
+ await mounted.render(<Select options={[{ label: 'Alpha', value: 'alpha' }]} searchable />);
270
+ await act(() => Promise.resolve().then(() => mounted.host.querySelector('button')?.click()));
271
+ await act(() => Promise.resolve().then(() => dismissSheet()));
272
+
273
+ await mounted.render(<Select options={[{ label: 'Beta', value: 'beta' }]} searchable />);
274
+ expect(mounted.host.querySelector('[data-testid="select-sheet"]')).toBeNull();
275
+ expect(dismissCalls).toHaveLength(0);
276
+ } finally {
277
+ await mounted.unmount();
278
+ mounted.host.remove();
279
+ }
280
+ });
281
+
282
+ test('keeps its active native sheet through StrictMode effect cleanup and setup', async () => {
283
+ const mounted = mount(true);
284
+ dismissCalls.length = 0;
285
+ activeSheet = undefined;
286
+
287
+ try {
288
+ await mounted.render(<Select options={[{ label: 'Alpha', value: 'alpha' }]} searchable />);
289
+ await act(() => Promise.resolve().then(() => mounted.host.querySelector('button')?.click()));
290
+
291
+ expect(mounted.host.querySelector('[data-testid="select-sheet"]')).not.toBeNull();
292
+ expect(dismissCalls).toHaveLength(0);
293
+ } finally {
294
+ await mounted.unmount();
295
+ mounted.host.remove();
296
+ }
297
+ });
298
+
299
+ test('does not reclaim a replacement sheet when its previous Select receives updated props', async () => {
300
+ const mounted = mount();
301
+ dismissCalls.length = 0;
302
+ activeSheet = undefined;
303
+
304
+ try {
305
+ await mounted.render(<Select options={[{ label: 'Alpha', value: 'alpha' }]} searchable />);
306
+ await act(() => Promise.resolve().then(() => mounted.host.querySelector('button')?.click()));
307
+
308
+ await act(() =>
309
+ Promise.resolve().then(() => {
310
+ replaceSheet(<div data-testid="other-sheet" />);
311
+ return mounted.render(<Select options={[{ label: 'Beta', value: 'beta' }]} searchable />);
312
+ }),
313
+ );
314
+
315
+ expect(mounted.host.querySelector('[data-testid="other-sheet"]')).not.toBeNull();
316
+ expect(mounted.host.querySelector('[data-testid="select-sheet"]')).toBeNull();
317
+ expect(dismissCalls).toHaveLength(0);
318
+ } finally {
319
+ await mounted.unmount();
320
+ mounted.host.remove();
321
+ }
322
+ });