@terreno/ui 0.26.0 → 0.28.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.
- package/dist/ActionSheet.js.map +1 -1
- package/dist/Box.js +2 -0
- package/dist/Box.js.map +1 -1
- package/dist/Common.d.ts +8 -7
- package/dist/Common.js.map +1 -1
- package/dist/ConsentNavigator.js.map +1 -1
- package/dist/CustomSelectField.js +2 -2
- package/dist/CustomSelectField.js.map +1 -1
- package/dist/DateTimeField.js +1 -0
- package/dist/DateTimeField.js.map +1 -1
- package/dist/EmailField.js +1 -1
- package/dist/EmailField.js.map +1 -1
- package/dist/Modal.js +7 -2
- package/dist/Modal.js.map +1 -1
- package/dist/Page.js +1 -0
- package/dist/Page.js.map +1 -1
- package/dist/PickerSelect.d.ts +4 -5
- package/dist/PickerSelect.js +4 -3
- package/dist/PickerSelect.js.map +1 -1
- package/dist/SelectBadge.js +1 -1
- package/dist/SelectBadge.js.map +1 -1
- package/dist/SelectField.js +3 -3
- package/dist/SelectField.js.map +1 -1
- package/dist/SplitPage.js +3 -0
- package/dist/SplitPage.js.map +1 -1
- package/dist/SplitPage.native.js +2 -0
- package/dist/SplitPage.native.js.map +1 -1
- package/dist/TapToEdit.js +1 -0
- package/dist/TapToEdit.js.map +1 -1
- package/dist/ToastNotifications.js.map +1 -1
- package/dist/Unifier.js.map +1 -1
- package/dist/WebDropdownMenu.d.ts +7 -8
- package/dist/WebDropdownMenu.js +4 -3
- package/dist/WebDropdownMenu.js.map +1 -1
- package/dist/useSubmitConsent.d.ts +1 -1
- package/dist/useSubmitConsent.js +1 -1
- package/dist/useSubmitConsent.js.map +1 -1
- package/package.json +2 -2
- package/src/ActionSheet.test.tsx +1 -0
- package/src/ActionSheet.tsx +2 -0
- package/src/Box.test.tsx +56 -0
- package/src/Box.tsx +4 -0
- package/src/Button.test.tsx +34 -0
- package/src/Common.ts +31 -7
- package/src/ConsentNavigator.test.tsx +1 -0
- package/src/ConsentNavigator.tsx +1 -0
- package/src/CustomSelectField.test.tsx +3 -8
- package/src/CustomSelectField.tsx +2 -2
- package/src/DataTable.test.tsx +1 -0
- package/src/DateTimeField.test.tsx +1 -0
- package/src/DateTimeField.tsx +1 -0
- package/src/EmailField.tsx +1 -1
- package/src/Modal.test.tsx +261 -66
- package/src/Modal.tsx +7 -2
- package/src/ModalSheet.test.tsx +7 -6
- package/src/Page.tsx +1 -0
- package/src/PickerSelect.test.tsx +23 -18
- package/src/PickerSelect.tsx +6 -6
- package/src/SelectBadge.test.tsx +1 -2
- package/src/SelectBadge.tsx +1 -1
- package/src/SelectField.tsx +2 -2
- package/src/SplitPage.native.tsx +2 -0
- package/src/SplitPage.test.tsx +6 -4
- package/src/SplitPage.tsx +3 -0
- package/src/TapToEdit.test.tsx +1 -0
- package/src/TapToEdit.tsx +2 -0
- package/src/Text.test.tsx +29 -0
- package/src/TextField.test.tsx +57 -1
- package/src/ToastNotifications.test.tsx +1 -0
- package/src/ToastNotifications.tsx +1 -0
- package/src/Tooltip.test.tsx +1 -1
- package/src/Unifier.ts +1 -0
- package/src/UpgradeRequiredScreen.test.tsx +40 -0
- package/src/UserInactivity.test.tsx +44 -1
- package/src/WebDropdownMenu.test.tsx +14 -19
- package/src/WebDropdownMenu.tsx +8 -8
- package/src/__snapshots__/DataTable.test.tsx.snap +0 -148
- package/src/__snapshots__/InfoModalIcon.test.tsx.snap +255 -1088
- package/src/__snapshots__/Modal.test.tsx.snap +950 -1108
- package/src/bunSetup.ts +24 -0
- package/src/types/react-native-swiper-flatlist.d.ts +1 -0
- package/src/useSubmitConsent.test.ts +2 -1
- package/src/useSubmitConsent.ts +2 -2
package/src/Modal.test.tsx
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import {afterEach, describe, expect, it, mock} from "bun:test";
|
|
1
|
+
import {afterEach, beforeEach, describe, expect, it, mock, spyOn} from "bun:test";
|
|
2
2
|
import {fireEvent} from "@testing-library/react-native";
|
|
3
|
+
import {assert} from "chai";
|
|
4
|
+
// Import Platform the same way the source modules do (ESM named import) so the web blur effect
|
|
5
|
+
// (which reads Platform.OS directly in Modal.tsx) observes the value the test sets.
|
|
6
|
+
import {Platform as ImportedPlatform} from "react-native";
|
|
7
|
+
import {Gesture} from "react-native-gesture-handler";
|
|
3
8
|
|
|
4
|
-
import {isMobileDevice} from "./MediaQuery";
|
|
5
9
|
import {Modal} from "./Modal";
|
|
6
10
|
import {Text} from "./Text";
|
|
7
11
|
import {renderWithTheme} from "./test-utils";
|
|
12
|
+
import * as Utilities from "./Utilities";
|
|
8
13
|
|
|
9
14
|
// Minimal shape of a test instance returned by UNSAFE_getAllByType that we rely on here.
|
|
10
15
|
interface PressableTestInstance {
|
|
@@ -16,7 +21,135 @@ interface PressableTestInstance {
|
|
|
16
21
|
};
|
|
17
22
|
}
|
|
18
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Finds the web-only translucent backdrop Pressable in a rendered Modal tree.
|
|
26
|
+
*
|
|
27
|
+
* The web branch renders a full-screen Pressable whose style sets a semi-transparent
|
|
28
|
+
* `rgba(...)` backgroundColor; the native ActionSheet branch has no such element. Tests use
|
|
29
|
+
* its presence/absence to assert which presentation branch rendered.
|
|
30
|
+
*
|
|
31
|
+
* @param pressables - All Pressable test instances found in the rendered tree.
|
|
32
|
+
* @returns The backdrop Pressable if present, otherwise undefined.
|
|
33
|
+
*/
|
|
34
|
+
const findBackdropPressable = (
|
|
35
|
+
pressables: PressableTestInstance[]
|
|
36
|
+
): PressableTestInstance | undefined => {
|
|
37
|
+
return pressables.find((node) => {
|
|
38
|
+
const style = node.props.style;
|
|
39
|
+
if (Array.isArray(style)) {
|
|
40
|
+
return style.some((s) => s?.backgroundColor?.includes?.("rgba"));
|
|
41
|
+
}
|
|
42
|
+
return style?.backgroundColor?.includes?.("rgba");
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Collects every reachable react-native `Platform` mock object.
|
|
48
|
+
*
|
|
49
|
+
* `Platform.OS` is read through `import {Platform} from "react-native"` in more than one source
|
|
50
|
+
* module (`Modal.tsx` directly, and `Utilities.tsx#isNative`). Depending on module resolution
|
|
51
|
+
* those bindings can map to either the top-level react-native mock or the internal
|
|
52
|
+
* `Libraries/Utilities/Platform` mock, and CI has shown them diverging (mutating one left the
|
|
53
|
+
* other untouched). Gathering all of them lets a single setter drive the platform branch
|
|
54
|
+
* deterministically regardless of which object a given module captured.
|
|
55
|
+
*/
|
|
56
|
+
const collectPlatformObjects = (): {OS: string}[] => {
|
|
57
|
+
const objects: {OS: string}[] = [];
|
|
58
|
+
const push = (candidate: unknown): void => {
|
|
59
|
+
if (
|
|
60
|
+
candidate &&
|
|
61
|
+
typeof candidate === "object" &&
|
|
62
|
+
"OS" in (candidate as Record<string, unknown>) &&
|
|
63
|
+
!objects.includes(candidate as {OS: string})
|
|
64
|
+
) {
|
|
65
|
+
objects.push(candidate as {OS: string});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
// The ESM binding the source files use must come first.
|
|
69
|
+
push(ImportedPlatform);
|
|
70
|
+
const rn = require("react-native") as {Platform?: unknown; default?: {Platform?: unknown}};
|
|
71
|
+
push(rn.Platform);
|
|
72
|
+
push(rn.default?.Platform);
|
|
73
|
+
try {
|
|
74
|
+
// Only the module's `default` object is mutable; the namespace's own `OS` binding is a
|
|
75
|
+
// readonly ES module export and must not be pushed.
|
|
76
|
+
const libPlatform = require("react-native/Libraries/Utilities/Platform") as {
|
|
77
|
+
default?: unknown;
|
|
78
|
+
};
|
|
79
|
+
push(libPlatform.default);
|
|
80
|
+
} catch {
|
|
81
|
+
// The internal Platform module may not be resolvable; the top-level mock still covers it.
|
|
82
|
+
}
|
|
83
|
+
return objects;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const platformObjects = collectPlatformObjects();
|
|
87
|
+
const originalPlatformOS = platformObjects.map((platform) => platform.OS);
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Sets `Platform.OS` on every reachable Platform mock so both `Modal` and `isNative` observe it.
|
|
91
|
+
*
|
|
92
|
+
* @param os - The platform value to apply (e.g. "web", "ios", "android").
|
|
93
|
+
*/
|
|
94
|
+
const setPlatformOS = (os: string): void => {
|
|
95
|
+
for (const platform of platformObjects) {
|
|
96
|
+
try {
|
|
97
|
+
platform.OS = os;
|
|
98
|
+
} catch {
|
|
99
|
+
// Skip any binding that is not writable; other bindings still drive the branch.
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Restores `Platform.OS` on every reachable Platform mock to the value captured at load time.
|
|
106
|
+
*/
|
|
107
|
+
const restorePlatformOS = (): void => {
|
|
108
|
+
platformObjects.forEach((platform, index) => {
|
|
109
|
+
try {
|
|
110
|
+
platform.OS = originalPlatformOS[index] ?? "ios";
|
|
111
|
+
} catch {
|
|
112
|
+
// Skip any binding that is not writable.
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
let isNativeSpy: ReturnType<typeof spyOn> | undefined;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Forces `isNative()` to a fixed value so the Modal's platform branch is deterministic.
|
|
121
|
+
*
|
|
122
|
+
* Spying on the `Utilities.isNative` export drives the exact live binding `Modal.tsx` calls,
|
|
123
|
+
* which is reliable across environments (unlike mutating react-native's Platform.OS, whose mock
|
|
124
|
+
* object identity can diverge per module on CI).
|
|
125
|
+
*
|
|
126
|
+
* @param value - true to render the native ActionSheet branch, false for the web dialog branch.
|
|
127
|
+
*/
|
|
128
|
+
const forceIsNative = (value: boolean): void => {
|
|
129
|
+
isNativeSpy = spyOn(Utilities, "isNative").mockReturnValue(value);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Restores the real `isNative()` implementation after a forced value.
|
|
134
|
+
*/
|
|
135
|
+
const restoreIsNative = (): void => {
|
|
136
|
+
isNativeSpy?.mockRestore();
|
|
137
|
+
isNativeSpy = undefined;
|
|
138
|
+
};
|
|
139
|
+
|
|
19
140
|
describe("Modal", () => {
|
|
141
|
+
// These tests exercise the default native (ActionSheet) presentation; pin the platform and
|
|
142
|
+
// force isNative() so the branch is deterministic and not left to ambient Platform.OS state.
|
|
143
|
+
beforeEach(() => {
|
|
144
|
+
setPlatformOS("ios");
|
|
145
|
+
forceIsNative(true);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
afterEach(() => {
|
|
149
|
+
restorePlatformOS();
|
|
150
|
+
restoreIsNative();
|
|
151
|
+
});
|
|
152
|
+
|
|
20
153
|
it("renders correctly when visible", () => {
|
|
21
154
|
const {toJSON} = renderWithTheme(
|
|
22
155
|
<Modal onDismiss={() => {}} title="Test Modal" visible>
|
|
@@ -302,6 +435,44 @@ describe("Modal", () => {
|
|
|
302
435
|
|
|
303
436
|
expect(handleSecondary).toHaveBeenCalled();
|
|
304
437
|
});
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
describe("Modal web platform", () => {
|
|
441
|
+
const globalScope = globalThis as {document?: unknown; HTMLElement?: unknown};
|
|
442
|
+
const originalDocument = globalScope.document;
|
|
443
|
+
const originalHTMLElement = globalScope.HTMLElement;
|
|
444
|
+
|
|
445
|
+
class FakeHTMLElement {
|
|
446
|
+
blur = mock(() => {});
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// The web branch runs a blur useEffect that reads `document.activeElement` and checks
|
|
450
|
+
// `instanceof HTMLElement`, so every web test needs Platform.OS === "web" (across every
|
|
451
|
+
// Platform binding, see setPlatformOS) plus a document and HTMLElement stub before rendering.
|
|
452
|
+
beforeEach(() => {
|
|
453
|
+
setPlatformOS("web");
|
|
454
|
+
forceIsNative(false);
|
|
455
|
+
globalScope.HTMLElement = FakeHTMLElement;
|
|
456
|
+
globalScope.document = {activeElement: null};
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
afterEach(() => {
|
|
460
|
+
restorePlatformOS();
|
|
461
|
+
restoreIsNative();
|
|
462
|
+
globalScope.document = originalDocument;
|
|
463
|
+
globalScope.HTMLElement = originalHTMLElement;
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
it("renders the web RNModal backdrop on web", () => {
|
|
467
|
+
const {UNSAFE_getAllByType} = renderWithTheme(
|
|
468
|
+
<Modal onDismiss={() => {}} title="Web Modal" visible>
|
|
469
|
+
<Text>Content</Text>
|
|
470
|
+
</Modal>
|
|
471
|
+
);
|
|
472
|
+
const {Pressable} = require("react-native");
|
|
473
|
+
const pressables: PressableTestInstance[] = UNSAFE_getAllByType(Pressable);
|
|
474
|
+
expect(findBackdropPressable(pressables)).toBeTruthy();
|
|
475
|
+
});
|
|
305
476
|
|
|
306
477
|
it("dismisses when the backdrop is pressed and persistOnBackgroundClick is false", () => {
|
|
307
478
|
const handleDismiss = mock(() => {});
|
|
@@ -313,13 +484,7 @@ describe("Modal", () => {
|
|
|
313
484
|
// Find the backdrop Pressable (first Pressable in tree with a style that includes backgroundColor).
|
|
314
485
|
const {Pressable} = require("react-native");
|
|
315
486
|
const pressables: PressableTestInstance[] = UNSAFE_getAllByType(Pressable);
|
|
316
|
-
const backdrop = pressables
|
|
317
|
-
const style = node.props.style;
|
|
318
|
-
if (Array.isArray(style)) {
|
|
319
|
-
return style.some((s) => s?.backgroundColor?.includes?.("rgba"));
|
|
320
|
-
}
|
|
321
|
-
return style?.backgroundColor?.includes?.("rgba");
|
|
322
|
-
});
|
|
487
|
+
const backdrop = findBackdropPressable(pressables);
|
|
323
488
|
expect(backdrop).toBeTruthy();
|
|
324
489
|
backdrop?.props.onPress?.();
|
|
325
490
|
expect(handleDismiss).toHaveBeenCalled();
|
|
@@ -355,28 +520,8 @@ describe("Modal", () => {
|
|
|
355
520
|
inner?.props.onPress?.({stopPropagation});
|
|
356
521
|
expect(stopPropagation).not.toHaveBeenCalled();
|
|
357
522
|
});
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
describe("Modal web platform", () => {
|
|
361
|
-
const RN = require("react-native") as {Platform: {OS: string}};
|
|
362
|
-
const originalOS = RN.Platform.OS;
|
|
363
|
-
const globalScope = globalThis as {document?: unknown; HTMLElement?: unknown};
|
|
364
|
-
const originalDocument = globalScope.document;
|
|
365
|
-
const originalHTMLElement = globalScope.HTMLElement;
|
|
366
|
-
|
|
367
|
-
class FakeHTMLElement {
|
|
368
|
-
blur = mock(() => {});
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
afterEach(() => {
|
|
372
|
-
RN.Platform.OS = originalOS;
|
|
373
|
-
globalScope.document = originalDocument;
|
|
374
|
-
globalScope.HTMLElement = originalHTMLElement;
|
|
375
|
-
});
|
|
376
523
|
|
|
377
524
|
it("blurs the focused element when opened on web", () => {
|
|
378
|
-
RN.Platform.OS = "web";
|
|
379
|
-
globalScope.HTMLElement = FakeHTMLElement;
|
|
380
525
|
const active = new FakeHTMLElement();
|
|
381
526
|
globalScope.document = {activeElement: active};
|
|
382
527
|
|
|
@@ -390,8 +535,6 @@ describe("Modal web platform", () => {
|
|
|
390
535
|
});
|
|
391
536
|
|
|
392
537
|
it("does not blur when the active element is not an HTMLElement", () => {
|
|
393
|
-
RN.Platform.OS = "web";
|
|
394
|
-
globalScope.HTMLElement = FakeHTMLElement;
|
|
395
538
|
globalScope.document = {activeElement: {}};
|
|
396
539
|
|
|
397
540
|
const {toJSON} = renderWithTheme(
|
|
@@ -404,46 +547,98 @@ describe("Modal web platform", () => {
|
|
|
404
547
|
});
|
|
405
548
|
});
|
|
406
549
|
|
|
407
|
-
|
|
550
|
+
// The Modal selects its presentation via isNative() (Platform.OS in ios/android), NOT screen
|
|
551
|
+
// size, so these run the native branch explicitly for each native platform. Android is the
|
|
552
|
+
// platform where the original tablet bug occurred, so it must be covered directly rather than
|
|
553
|
+
// relying on the default "ios" test platform.
|
|
554
|
+
describe("Modal native presentation", () => {
|
|
408
555
|
afterEach(() => {
|
|
409
|
-
(
|
|
410
|
-
|
|
556
|
+
restorePlatformOS();
|
|
557
|
+
restoreIsNative();
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
for (const platform of ["ios", "android"] as const) {
|
|
561
|
+
it(`uses the ActionSheet (no web backdrop) on ${platform}`, () => {
|
|
562
|
+
setPlatformOS(platform);
|
|
563
|
+
forceIsNative(true);
|
|
564
|
+
const {UNSAFE_getAllByType, getByText} = renderWithTheme(
|
|
565
|
+
<Modal
|
|
566
|
+
onDismiss={() => {}}
|
|
567
|
+
primaryButtonOnClick={() => {}}
|
|
568
|
+
primaryButtonText="Save"
|
|
569
|
+
title="Native Modal"
|
|
570
|
+
visible
|
|
571
|
+
>
|
|
572
|
+
<Text>Native Content</Text>
|
|
573
|
+
</Modal>
|
|
574
|
+
);
|
|
575
|
+
// Content mounts via the ActionSheet branch...
|
|
576
|
+
expect(getByText("Native Modal")).toBeTruthy();
|
|
577
|
+
// ...and the web-only translucent backdrop Pressable must NOT be present.
|
|
578
|
+
const {Pressable} = require("react-native");
|
|
579
|
+
const pressables: PressableTestInstance[] = UNSAFE_getAllByType(Pressable);
|
|
580
|
+
expect(findBackdropPressable(pressables)).toBeUndefined();
|
|
581
|
+
});
|
|
411
582
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
<
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
583
|
+
it(`renders nothing when not visible on ${platform}`, () => {
|
|
584
|
+
setPlatformOS(platform);
|
|
585
|
+
forceIsNative(true);
|
|
586
|
+
const {queryByText} = renderWithTheme(
|
|
587
|
+
<Modal onDismiss={() => {}} title="Hidden Native Modal" visible={false}>
|
|
588
|
+
<Text>Native Content</Text>
|
|
589
|
+
</Modal>
|
|
590
|
+
);
|
|
591
|
+
// The ActionSheet stays closed (mock tracks setModalVisible), so no content is shown.
|
|
592
|
+
expect(queryByText("Hidden Native Modal")).toBeNull();
|
|
593
|
+
expect(queryByText("Native Content")).toBeNull();
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
interface CapturedGesture {
|
|
599
|
+
onEnd: {mock: {calls: [(event: {translationY: number}) => void][]}};
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
describe("Modal drag-to-close gesture", () => {
|
|
603
|
+
// The drag handle only renders in the native ActionSheet branch, so force native.
|
|
604
|
+
beforeEach(() => {
|
|
605
|
+
setPlatformOS("ios");
|
|
606
|
+
forceIsNative(true);
|
|
420
607
|
});
|
|
421
608
|
|
|
422
|
-
|
|
423
|
-
(
|
|
424
|
-
|
|
425
|
-
<Modal
|
|
426
|
-
onDismiss={() => {}}
|
|
427
|
-
primaryButtonOnClick={() => {}}
|
|
428
|
-
primaryButtonText="Save"
|
|
429
|
-
secondaryButtonOnClick={() => {}}
|
|
430
|
-
secondaryButtonText="Cancel"
|
|
431
|
-
title="Mobile Actions"
|
|
432
|
-
visible
|
|
433
|
-
>
|
|
434
|
-
<Text>Content</Text>
|
|
435
|
-
</Modal>
|
|
436
|
-
);
|
|
437
|
-
expect(toJSON()).toBeTruthy();
|
|
609
|
+
afterEach(() => {
|
|
610
|
+
restorePlatformOS();
|
|
611
|
+
restoreIsNative();
|
|
438
612
|
});
|
|
439
613
|
|
|
440
|
-
it("
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
614
|
+
it("dismisses only when dragged down past the threshold", () => {
|
|
615
|
+
const handleDismiss = mock(() => {});
|
|
616
|
+
let capturedGesture: CapturedGesture | undefined;
|
|
617
|
+
const originalPan = Gesture.Pan;
|
|
618
|
+
(Gesture as {Pan: () => unknown}).Pan = () => {
|
|
619
|
+
capturedGesture = originalPan() as unknown as CapturedGesture;
|
|
620
|
+
return capturedGesture;
|
|
621
|
+
};
|
|
622
|
+
|
|
623
|
+
try {
|
|
624
|
+
renderWithTheme(
|
|
625
|
+
<Modal onDismiss={handleDismiss} title="Draggable" visible>
|
|
626
|
+
<Text>Body</Text>
|
|
627
|
+
</Modal>
|
|
628
|
+
);
|
|
629
|
+
|
|
630
|
+
const onEnd = capturedGesture?.onEnd.mock.calls[0][0];
|
|
631
|
+
assert.isDefined(onEnd);
|
|
632
|
+
|
|
633
|
+
// A small drag stays below the threshold and should not dismiss.
|
|
634
|
+
onEnd?.({translationY: 5});
|
|
635
|
+
assert.lengthOf(handleDismiss.mock.calls, 0);
|
|
636
|
+
|
|
637
|
+
// A drag past the threshold dismisses via runOnJS(handleDismiss).
|
|
638
|
+
onEnd?.({translationY: 40});
|
|
639
|
+
assert.lengthOf(handleDismiss.mock.calls, 1);
|
|
640
|
+
} finally {
|
|
641
|
+
(Gesture as {Pan: () => unknown}).Pan = originalPan;
|
|
642
|
+
}
|
|
448
643
|
});
|
|
449
644
|
});
|
package/src/Modal.tsx
CHANGED
|
@@ -15,7 +15,6 @@ import {Button} from "./Button";
|
|
|
15
15
|
import type {ModalProps, TerrenoTheme} from "./Common";
|
|
16
16
|
import {Heading} from "./Heading";
|
|
17
17
|
import {Icon} from "./Icon";
|
|
18
|
-
import {isMobileDevice} from "./MediaQuery";
|
|
19
18
|
import {Text} from "./Text";
|
|
20
19
|
import {useTheme} from "./Theme";
|
|
21
20
|
import {resolveModalTestIDsFromProps, toTestProps} from "./testing/resolveTestId";
|
|
@@ -247,7 +246,13 @@ export const Modal: FC<ModalProps> = ({
|
|
|
247
246
|
}
|
|
248
247
|
}, [visible]);
|
|
249
248
|
|
|
250
|
-
|
|
249
|
+
// Choose the presentation by platform, not by screen size. The web branch below relies on DOM
|
|
250
|
+
// semantics (nested Pressables using `e.stopPropagation()` and a `cursor` style) that native
|
|
251
|
+
// platforms do not implement, so it must only run on web. Keying this off screen size instead
|
|
252
|
+
// sent native *tablets* (width >= "sm") down the web branch: on Android the nested Pressables
|
|
253
|
+
// fight over the touch responder, producing repeated press animations and a Confirm button that
|
|
254
|
+
// never fires. All native devices (phones and tablets) use the ActionSheet presentation.
|
|
255
|
+
const isMobile = isNative();
|
|
251
256
|
const sizePx = getModalSize(size);
|
|
252
257
|
|
|
253
258
|
const modalContentProps = {
|
package/src/ModalSheet.test.tsx
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
2
1
|
import {describe, expect, it, mock} from "bun:test";
|
|
3
2
|
import {forwardRef, useRef} from "react";
|
|
4
3
|
import {Text, View} from "react-native";
|
|
@@ -8,11 +7,13 @@ import {renderWithTheme} from "./test-utils";
|
|
|
8
7
|
|
|
9
8
|
// Mock react-native-modalize
|
|
10
9
|
mock.module("react-native-modalize", () => ({
|
|
11
|
-
Modalize: forwardRef
|
|
12
|
-
|
|
13
|
-
{
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
Modalize: forwardRef<React.ElementRef<typeof View>, {children: React.ReactNode}>(
|
|
11
|
+
({children}, ref) => (
|
|
12
|
+
<View ref={ref} testID="modalize">
|
|
13
|
+
{children}
|
|
14
|
+
</View>
|
|
15
|
+
)
|
|
16
|
+
),
|
|
16
17
|
}));
|
|
17
18
|
|
|
18
19
|
describe("ModalSheet", () => {
|
package/src/Page.tsx
CHANGED
|
@@ -12,6 +12,7 @@ import {Spinner} from "./Spinner";
|
|
|
12
12
|
import {Text} from "./Text";
|
|
13
13
|
|
|
14
14
|
export class Page extends React.Component<PageProps, {}> {
|
|
15
|
+
// noExplicitAny: ActionSheet class is defined in ActionSheet.tsx which imports from Common.ts indirectly; using its type here would create a circular dependency
|
|
15
16
|
// biome-ignore lint/suspicious/noExplicitAny: ActionSheet class is defined in ActionSheet.tsx which imports from Common.ts indirectly; using its type here would create a circular dependency
|
|
16
17
|
actionSheetRef: React.RefObject<any> = React.createRef();
|
|
17
18
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// noExplicitAny: test mock typing
|
|
1
2
|
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
2
3
|
import {describe, expect, it, mock} from "bun:test";
|
|
3
4
|
import {act, fireEvent} from "@testing-library/react-native";
|
|
@@ -10,6 +11,7 @@ import {renderWithTheme} from "./test-utils";
|
|
|
10
11
|
|
|
11
12
|
describe("PickerSelect", () => {
|
|
12
13
|
const defaultProps = {
|
|
14
|
+
disableSearch: true,
|
|
13
15
|
items: [
|
|
14
16
|
{label: "Option 1", value: "1"},
|
|
15
17
|
{label: "Option 2", value: "2"},
|
|
@@ -17,7 +19,6 @@ describe("PickerSelect", () => {
|
|
|
17
19
|
],
|
|
18
20
|
onValueChange: () => {},
|
|
19
21
|
placeholder: {label: "Select an option", value: ""},
|
|
20
|
-
searchable: false,
|
|
21
22
|
};
|
|
22
23
|
|
|
23
24
|
it("renders correctly with default props", () => {
|
|
@@ -170,7 +171,7 @@ describe("PickerSelect", () => {
|
|
|
170
171
|
let hadDocument = false;
|
|
171
172
|
let savedDocument: any;
|
|
172
173
|
|
|
173
|
-
const
|
|
174
|
+
const searchEnabledWebProps = {...defaultProps, disableSearch: false};
|
|
174
175
|
|
|
175
176
|
const ensureDocument = () => {
|
|
176
177
|
hadDocument = "document" in globalThis;
|
|
@@ -227,7 +228,7 @@ describe("PickerSelect", () => {
|
|
|
227
228
|
PlatformModule.OS = "web";
|
|
228
229
|
const onOpen = mock(() => {});
|
|
229
230
|
const {getByTestId} = renderWithTheme(
|
|
230
|
-
<RNPickerSelect {...
|
|
231
|
+
<RNPickerSelect {...searchEnabledWebProps} onOpen={onOpen} value="1" />
|
|
231
232
|
);
|
|
232
233
|
await openSearchableWebPicker(getByTestId);
|
|
233
234
|
expect(onOpen).toHaveBeenCalled();
|
|
@@ -237,14 +238,14 @@ describe("PickerSelect", () => {
|
|
|
237
238
|
}
|
|
238
239
|
});
|
|
239
240
|
|
|
240
|
-
it("opens web menu on press when
|
|
241
|
+
it("opens web menu on press when disableSearch is true", async () => {
|
|
241
242
|
ensureDocument();
|
|
242
243
|
savedOS = PlatformModule.OS;
|
|
243
244
|
try {
|
|
244
245
|
PlatformModule.OS = "web";
|
|
245
246
|
const onOpen = mock(() => {});
|
|
246
247
|
const {getByTestId} = renderWithTheme(
|
|
247
|
-
<RNPickerSelect {...defaultProps} onOpen={onOpen}
|
|
248
|
+
<RNPickerSelect {...defaultProps} disableSearch onOpen={onOpen} value="1" />
|
|
248
249
|
);
|
|
249
250
|
await act(async () => {
|
|
250
251
|
fireEvent.press(getByTestId("web_picker"));
|
|
@@ -263,7 +264,7 @@ describe("PickerSelect", () => {
|
|
|
263
264
|
PlatformModule.OS = "web";
|
|
264
265
|
const onOpen = mock(() => {});
|
|
265
266
|
const {getByTestId} = renderWithTheme(
|
|
266
|
-
<RNPickerSelect {...
|
|
267
|
+
<RNPickerSelect {...searchEnabledWebProps} disabled onOpen={onOpen} />
|
|
267
268
|
);
|
|
268
269
|
await act(async () => {
|
|
269
270
|
fireEvent(getByTestId("text_input"), "focus");
|
|
@@ -283,7 +284,7 @@ describe("PickerSelect", () => {
|
|
|
283
284
|
const onClose = mock(() => {});
|
|
284
285
|
const onOpen = mock(() => {});
|
|
285
286
|
const {getByTestId} = renderWithTheme(
|
|
286
|
-
<RNPickerSelect {...
|
|
287
|
+
<RNPickerSelect {...searchEnabledWebProps} onClose={onClose} onOpen={onOpen} value="1" />
|
|
287
288
|
);
|
|
288
289
|
await openSearchableWebPicker(getByTestId);
|
|
289
290
|
expect(onOpen).toHaveBeenCalled();
|
|
@@ -303,7 +304,7 @@ describe("PickerSelect", () => {
|
|
|
303
304
|
try {
|
|
304
305
|
PlatformModule.OS = "web";
|
|
305
306
|
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
306
|
-
<RNPickerSelect {...
|
|
307
|
+
<RNPickerSelect {...searchEnabledWebProps} value="1" />
|
|
307
308
|
);
|
|
308
309
|
await openSearchableWebPicker(getByTestId);
|
|
309
310
|
const input = getByTestId("text_input");
|
|
@@ -326,7 +327,9 @@ describe("PickerSelect", () => {
|
|
|
326
327
|
savedOS = PlatformModule.OS;
|
|
327
328
|
try {
|
|
328
329
|
PlatformModule.OS = "web";
|
|
329
|
-
const {getByTestId} = renderWithTheme(
|
|
330
|
+
const {getByTestId} = renderWithTheme(
|
|
331
|
+
<RNPickerSelect {...searchEnabledWebProps} value="1" />
|
|
332
|
+
);
|
|
330
333
|
await openSearchableWebPicker(getByTestId);
|
|
331
334
|
const input = getByTestId("text_input");
|
|
332
335
|
await act(async () => {
|
|
@@ -353,7 +356,7 @@ describe("PickerSelect", () => {
|
|
|
353
356
|
try {
|
|
354
357
|
PlatformModule.OS = "web";
|
|
355
358
|
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
356
|
-
<RNPickerSelect {...
|
|
359
|
+
<RNPickerSelect {...searchEnabledWebProps} value="1" />
|
|
357
360
|
);
|
|
358
361
|
const input = getByTestId("text_input");
|
|
359
362
|
await act(async () => {
|
|
@@ -378,7 +381,7 @@ describe("PickerSelect", () => {
|
|
|
378
381
|
{label: "Melon", value: "m"},
|
|
379
382
|
];
|
|
380
383
|
const props = {
|
|
381
|
-
...
|
|
384
|
+
...searchEnabledWebProps,
|
|
382
385
|
items: itemsWithHelper,
|
|
383
386
|
placeholder: {label: "Select", value: ""},
|
|
384
387
|
};
|
|
@@ -402,7 +405,9 @@ describe("PickerSelect", () => {
|
|
|
402
405
|
savedOS = PlatformModule.OS;
|
|
403
406
|
try {
|
|
404
407
|
PlatformModule.OS = "web";
|
|
405
|
-
const {getByTestId} = renderWithTheme(
|
|
408
|
+
const {getByTestId} = renderWithTheme(
|
|
409
|
+
<RNPickerSelect {...searchEnabledWebProps} value="1" />
|
|
410
|
+
);
|
|
406
411
|
await openSearchableWebPicker(getByTestId);
|
|
407
412
|
await act(async () => {
|
|
408
413
|
fireEvent.changeText(getByTestId("text_input"), "zzz");
|
|
@@ -468,7 +473,7 @@ describe("PickerSelect", () => {
|
|
|
468
473
|
PlatformModule.OS = "web";
|
|
469
474
|
const mockOnValueChange = mock(() => {});
|
|
470
475
|
const {getByTestId, queryByTestId, rerender} = renderWithTheme(
|
|
471
|
-
<RNPickerSelect {...
|
|
476
|
+
<RNPickerSelect {...searchEnabledWebProps} onValueChange={mockOnValueChange} value="1" />
|
|
472
477
|
);
|
|
473
478
|
await openSearchableWebPicker(getByTestId);
|
|
474
479
|
await act(async () => {
|
|
@@ -477,7 +482,7 @@ describe("PickerSelect", () => {
|
|
|
477
482
|
expect(mockOnValueChange).toHaveBeenCalledWith("2", 2);
|
|
478
483
|
expect(queryByTestId("web_dropdown_backdrop")).toBeNull();
|
|
479
484
|
rerender(
|
|
480
|
-
<RNPickerSelect {...
|
|
485
|
+
<RNPickerSelect {...searchEnabledWebProps} onValueChange={mockOnValueChange} value="2" />
|
|
481
486
|
);
|
|
482
487
|
expect(getByTestId("text_input").props.value).toBe("Option 2");
|
|
483
488
|
} finally {
|
|
@@ -493,7 +498,7 @@ describe("PickerSelect", () => {
|
|
|
493
498
|
PlatformModule.OS = "web";
|
|
494
499
|
const mockOnValueChange = mock(() => {});
|
|
495
500
|
const {getByTestId} = renderWithTheme(
|
|
496
|
-
<RNPickerSelect {...
|
|
501
|
+
<RNPickerSelect {...searchEnabledWebProps} onValueChange={mockOnValueChange} value="1" />
|
|
497
502
|
);
|
|
498
503
|
await openSearchableWebPicker(getByTestId);
|
|
499
504
|
await act(async () => {
|
|
@@ -592,8 +597,8 @@ describe("PickerSelect", () => {
|
|
|
592
597
|
const {getByTestId} = renderWithTheme(
|
|
593
598
|
<RNPickerSelect
|
|
594
599
|
{...defaultProps}
|
|
600
|
+
disableSearch
|
|
595
601
|
onValueChange={mockOnValueChange}
|
|
596
|
-
searchable={false}
|
|
597
602
|
value="1"
|
|
598
603
|
/>
|
|
599
604
|
);
|
|
@@ -618,7 +623,7 @@ describe("PickerSelect", () => {
|
|
|
618
623
|
PlatformModule.OS = "android";
|
|
619
624
|
const onOpen = mock(() => {});
|
|
620
625
|
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
621
|
-
<RNPickerSelect {...defaultProps} onOpen={onOpen}
|
|
626
|
+
<RNPickerSelect {...defaultProps} disableSearch={false} onOpen={onOpen} value="2" />
|
|
622
627
|
);
|
|
623
628
|
expect(queryByTestId("android_picker")).toBeNull();
|
|
624
629
|
await act(async () => {
|
|
@@ -646,8 +651,8 @@ describe("PickerSelect", () => {
|
|
|
646
651
|
const {getByTestId} = renderWithTheme(
|
|
647
652
|
<RNPickerSelect
|
|
648
653
|
{...defaultProps}
|
|
654
|
+
disableSearch={false}
|
|
649
655
|
onValueChange={mockOnValueChange}
|
|
650
|
-
searchable
|
|
651
656
|
value="1"
|
|
652
657
|
/>
|
|
653
658
|
);
|
package/src/PickerSelect.tsx
CHANGED
|
@@ -129,11 +129,10 @@ export interface RNPickerSelectProps {
|
|
|
129
129
|
InputAccessoryView?: ComponentType<{testID?: string}>;
|
|
130
130
|
|
|
131
131
|
/**
|
|
132
|
-
* When true,
|
|
133
|
-
*
|
|
134
|
-
* @default true
|
|
132
|
+
* When true, hides the type-to-filter search UI. Search is enabled by default.
|
|
133
|
+
* @default false
|
|
135
134
|
*/
|
|
136
|
-
|
|
135
|
+
disableSearch?: boolean;
|
|
137
136
|
}
|
|
138
137
|
|
|
139
138
|
export const RNPickerSelect = ({
|
|
@@ -158,8 +157,9 @@ export const RNPickerSelect = ({
|
|
|
158
157
|
touchableWrapperProps,
|
|
159
158
|
|
|
160
159
|
InputAccessoryView,
|
|
161
|
-
|
|
160
|
+
disableSearch = false,
|
|
162
161
|
}: RNPickerSelectProps) => {
|
|
162
|
+
const searchable = !disableSearch;
|
|
163
163
|
const [showPicker, setShowPicker] = useState<boolean>(false);
|
|
164
164
|
const [webSearchQuery, setWebSearchQuery] = useState("");
|
|
165
165
|
const webSearchInputRef = useRef<TextInput>(null);
|
|
@@ -810,6 +810,7 @@ export const RNPickerSelect = ({
|
|
|
810
810
|
)}
|
|
811
811
|
<WebDropdownMenu
|
|
812
812
|
anchor={webAnchor}
|
|
813
|
+
disableSearch={disableSearch || searchInTrigger}
|
|
813
814
|
keepTriggerFocus={searchInTrigger}
|
|
814
815
|
onClose={closeWebMenu}
|
|
815
816
|
onSelect={(_val, idx) => {
|
|
@@ -823,7 +824,6 @@ export const RNPickerSelect = ({
|
|
|
823
824
|
}}
|
|
824
825
|
options={menuOptions}
|
|
825
826
|
presentation={Platform.OS === "android" ? "centered" : "anchored"}
|
|
826
|
-
searchable={searchable && !searchInTrigger}
|
|
827
827
|
selectedIndex={menuSelectedIndex >= 0 ? menuSelectedIndex : undefined}
|
|
828
828
|
showEmptyStateWhenNoOptions={searchInTrigger && webSearchQuery.trim().length > 0}
|
|
829
829
|
testIDPrefix="web_dropdown"
|
package/src/SelectBadge.test.tsx
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
2
1
|
import {describe, expect, it, mock} from "bun:test";
|
|
3
2
|
import {act, fireEvent} from "@testing-library/react-native";
|
|
4
3
|
|
|
@@ -28,7 +27,7 @@ describe("SelectBadge", () => {
|
|
|
28
27
|
|
|
29
28
|
it("displays placeholder when no value", () => {
|
|
30
29
|
const {getByText} = renderWithTheme(
|
|
31
|
-
<SelectBadge onChange={() => {}} options={defaultOptions} value={undefined
|
|
30
|
+
<SelectBadge onChange={() => {}} options={defaultOptions} value={undefined} />
|
|
32
31
|
);
|
|
33
32
|
expect(getByText("---")).toBeTruthy();
|
|
34
33
|
});
|