@terreno/ui 0.14.1 → 0.15.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 +15 -27
- package/dist/ActionSheet.js.map +1 -1
- package/dist/Badge.js +1 -0
- package/dist/Badge.js.map +1 -1
- package/dist/Banner.d.ts +8 -0
- package/dist/Banner.js +2 -2
- package/dist/Banner.js.map +1 -1
- package/dist/MarkdownView.js +20 -7
- package/dist/MarkdownView.js.map +1 -1
- package/dist/PickerSelect.js +6 -2
- package/dist/PickerSelect.js.map +1 -1
- package/dist/Signature.d.ts +8 -1
- package/dist/Signature.js +93 -18
- package/dist/Signature.js.map +1 -1
- package/dist/Signature.native.d.ts +15 -0
- package/dist/Signature.native.js +116 -21
- package/dist/Signature.native.js.map +1 -1
- package/dist/TapToEdit.js +1 -1
- package/dist/TapToEdit.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/useConsentHistory.d.ts +6 -1
- package/dist/useConsentHistory.js +2 -1
- package/dist/useConsentHistory.js.map +1 -1
- package/package.json +2 -4
- package/src/ActionSheet.test.tsx +554 -0
- package/src/ActionSheet.tsx +24 -37
- package/src/Badge.test.tsx +7 -0
- package/src/Badge.tsx +1 -0
- package/src/Banner.test.tsx +58 -3
- package/src/Banner.tsx +3 -3
- package/src/DataTable.test.tsx +176 -1
- package/src/DateTimeField.test.tsx +942 -2
- package/src/Field.test.tsx +23 -0
- package/src/HeightActionSheet.test.tsx +1 -1
- package/src/HeightField.test.tsx +35 -0
- package/src/HeightFieldDesktop.test.tsx +19 -0
- package/src/MarkdownView.test.tsx +28 -0
- package/src/MarkdownView.tsx +69 -7
- package/src/MobileAddressAutoComplete.test.tsx +6 -2
- package/src/PickerSelect.test.tsx +265 -0
- package/src/PickerSelect.tsx +24 -8
- package/src/Signature.native.tsx +147 -30
- package/src/Signature.test.tsx +2 -49
- package/src/Signature.tsx +128 -22
- package/src/SignatureField.test.tsx +0 -9
- package/src/SplitPage.test.tsx +299 -43
- package/src/TapToEdit.test.tsx +46 -0
- package/src/TapToEdit.tsx +1 -1
- package/src/ToastNotifications.test.tsx +748 -1
- package/src/Tooltip.test.tsx +707 -1
- package/src/WebAddressAutocomplete.test.tsx +99 -0
- package/src/WebDropdownMenu.test.tsx +28 -2
- package/src/__snapshots__/Banner.test.tsx.snap +125 -0
- package/src/__snapshots__/CustomSelectField.test.tsx.snap +5 -4
- package/src/__snapshots__/DataTable.test.tsx.snap +366 -0
- package/src/__snapshots__/Field.test.tsx.snap +377 -0
- package/src/__snapshots__/MarkdownView.test.tsx.snap +284 -74
- package/src/__snapshots__/PickerSelect.test.tsx.snap +5 -4
- package/src/__snapshots__/SegmentedControl.test.tsx.snap +9 -0
- package/src/__snapshots__/SelectField.test.tsx.snap +5 -4
- package/src/__snapshots__/Signature.test.tsx.snap +13 -3
- package/src/__snapshots__/SignatureField.test.tsx.snap +10 -3
- package/src/__snapshots__/SplitPage.test.tsx.snap +698 -46
- package/src/bunSetup.ts +0 -19
- package/src/index.tsx +1 -1
- package/src/login/LoginScreen.test.tsx +12 -0
- package/src/useConsentHistory.test.ts +20 -13
- package/src/useConsentHistory.ts +7 -2
package/src/Field.test.tsx
CHANGED
|
@@ -125,4 +125,27 @@ describe("Field", () => {
|
|
|
125
125
|
);
|
|
126
126
|
expect(toJSON()).toMatchSnapshot();
|
|
127
127
|
});
|
|
128
|
+
|
|
129
|
+
it("renders customSelect field", () => {
|
|
130
|
+
const {toJSON} = renderWithTheme(
|
|
131
|
+
<Field
|
|
132
|
+
label="Custom"
|
|
133
|
+
onChange={() => {}}
|
|
134
|
+
options={[
|
|
135
|
+
{label: "Option A", value: "a"},
|
|
136
|
+
{label: "Option B", value: "b"},
|
|
137
|
+
]}
|
|
138
|
+
type="customSelect"
|
|
139
|
+
value="a"
|
|
140
|
+
/>
|
|
141
|
+
);
|
|
142
|
+
expect(toJSON()).toMatchSnapshot();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("renders signature field", () => {
|
|
146
|
+
const {toJSON} = renderWithTheme(
|
|
147
|
+
<Field label="Sign here" onChange={() => {}} type="signature" value="" />
|
|
148
|
+
);
|
|
149
|
+
expect(toJSON()).toMatchSnapshot();
|
|
150
|
+
});
|
|
128
151
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {describe, expect, it, mock} from "bun:test";
|
|
2
2
|
import {act, render} from "@testing-library/react-native";
|
|
3
|
-
import {createRef} from "react";
|
|
3
|
+
import React, {createRef} from "react";
|
|
4
4
|
|
|
5
5
|
import type {ActionSheet} from "./ActionSheet";
|
|
6
6
|
import {Button} from "./Button";
|
package/src/HeightField.test.tsx
CHANGED
|
@@ -208,6 +208,41 @@ describe("HeightField", () => {
|
|
|
208
208
|
});
|
|
209
209
|
});
|
|
210
210
|
|
|
211
|
+
describe("HeightField - HeightSegment callbacks", () => {
|
|
212
|
+
it("exercises HeightSegment onChangeText for feet and inches when rendered", () => {
|
|
213
|
+
const RN = require("react-native") as {Platform: {OS: string}};
|
|
214
|
+
const origOS = RN.Platform.OS;
|
|
215
|
+
RN.Platform.OS = "web";
|
|
216
|
+
try {
|
|
217
|
+
const onChange = mock(() => {});
|
|
218
|
+
const {root} = renderWithTheme(<HeightField onChange={onChange} title="Height" value="70" />);
|
|
219
|
+
const ftInputs = root.findAll(
|
|
220
|
+
(n) => n.props["aria-label"] === "ft input" && n.props.onChangeText
|
|
221
|
+
);
|
|
222
|
+
const inInputs = root.findAll(
|
|
223
|
+
(n) => n.props["aria-label"] === "in input" && n.props.onChangeText
|
|
224
|
+
);
|
|
225
|
+
if (ftInputs.length === 0) {
|
|
226
|
+
console.warn(
|
|
227
|
+
"Platform.OS override to 'web' did not take effect; skipping HeightSegment assertions"
|
|
228
|
+
);
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
expect(inInputs.length).toBeGreaterThan(0);
|
|
232
|
+
|
|
233
|
+
// Exercise the callbacks to cover HeightSegment.handleChange
|
|
234
|
+
ftInputs[0].props.onChangeText("6");
|
|
235
|
+
expect(onChange).toHaveBeenCalled();
|
|
236
|
+
|
|
237
|
+
inInputs[0].props.onChangeText("3");
|
|
238
|
+
ftInputs[0].props.onChangeText("abc");
|
|
239
|
+
ftInputs[0].props.onChangeText("");
|
|
240
|
+
} finally {
|
|
241
|
+
RN.Platform.OS = origOS;
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
|
|
211
246
|
describe("HeightField - Android platform", () => {
|
|
212
247
|
// Toggle Platform.OS to "android" to exercise the Android rendering branch
|
|
213
248
|
// that uses SelectField pickers instead of the Pressable+ActionSheet path.
|
|
@@ -126,6 +126,25 @@ describe("HeightField (desktop/web path)", () => {
|
|
|
126
126
|
expect(mockOnChange).not.toHaveBeenCalled();
|
|
127
127
|
});
|
|
128
128
|
|
|
129
|
+
it("tracks focused segment when inputs are focused", () => {
|
|
130
|
+
const {getAllByLabelText, toJSON} = renderWithTheme(
|
|
131
|
+
<HeightField onChange={mockOnChange} value="70" />
|
|
132
|
+
);
|
|
133
|
+
const feetInput = getAllByLabelText("ft input")[0];
|
|
134
|
+
const inchesInput = getAllByLabelText("in input")[0];
|
|
135
|
+
|
|
136
|
+
fireEvent(feetInput, "focus");
|
|
137
|
+
const snapshotFeetFocused = toJSON();
|
|
138
|
+
fireEvent(feetInput, "blur");
|
|
139
|
+
|
|
140
|
+
fireEvent(inchesInput, "focus");
|
|
141
|
+
const snapshotInchesFocused = toJSON();
|
|
142
|
+
fireEvent(inchesInput, "blur");
|
|
143
|
+
|
|
144
|
+
expect(snapshotFeetFocused).toBeTruthy();
|
|
145
|
+
expect(snapshotInchesFocused).toBeTruthy();
|
|
146
|
+
});
|
|
147
|
+
|
|
129
148
|
it("does not call onChange with values exceeding max feet", () => {
|
|
130
149
|
const {getAllByLabelText} = renderWithTheme(
|
|
131
150
|
<HeightField max={95} onChange={mockOnChange} value="" />
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {describe, expect, it} from "bun:test";
|
|
2
|
+
import assert from "node:assert";
|
|
2
3
|
|
|
3
4
|
import {MarkdownView} from "./MarkdownView";
|
|
4
5
|
import {renderWithTheme} from "./test-utils";
|
|
@@ -38,6 +39,33 @@ describe("MarkdownView", () => {
|
|
|
38
39
|
expect(toJSON()).toMatchSnapshot();
|
|
39
40
|
});
|
|
40
41
|
|
|
42
|
+
it("keeps long consent ordered list markers on one line", () => {
|
|
43
|
+
const longConsentList = Array.from({length: 17}, (_, index) => {
|
|
44
|
+
return `${index + 1}. This consent item has enough text to wrap on narrow mobile screens.`;
|
|
45
|
+
}).join("\n");
|
|
46
|
+
const {toJSON} = renderWithTheme(<MarkdownView>{longConsentList}</MarkdownView>);
|
|
47
|
+
const serialized = JSON.stringify(toJSON());
|
|
48
|
+
|
|
49
|
+
assert.ok(serialized.includes('"minWidth":32'));
|
|
50
|
+
assert.ok(serialized.includes('"flexShrink":0'));
|
|
51
|
+
assert.ok(serialized.includes('"textAlign":"right"'));
|
|
52
|
+
assert.ok(serialized.includes("17"));
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("uses explicit markdown paragraph line height for wrapped mobile text", () => {
|
|
56
|
+
const {toJSON} = renderWithTheme(
|
|
57
|
+
<MarkdownView>
|
|
58
|
+
{
|
|
59
|
+
"This consent paragraph is intentionally long so it wraps across multiple lines on Android and keeps its measured height."
|
|
60
|
+
}
|
|
61
|
+
</MarkdownView>
|
|
62
|
+
);
|
|
63
|
+
const serialized = JSON.stringify(toJSON());
|
|
64
|
+
|
|
65
|
+
assert.ok(serialized.includes('"fontSize":14'));
|
|
66
|
+
assert.ok(serialized.includes('"lineHeight":20'));
|
|
67
|
+
});
|
|
68
|
+
|
|
41
69
|
it("renders code blocks", () => {
|
|
42
70
|
const {toJSON} = renderWithTheme(<MarkdownView>{"```\ncode block\n```"}</MarkdownView>);
|
|
43
71
|
expect(toJSON()).toMatchSnapshot();
|
package/src/MarkdownView.tsx
CHANGED
|
@@ -49,11 +49,29 @@ export const MarkdownView: React.FC<{children: React.ReactNode; inverted?: boole
|
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
const monoFont = isWeb ? "monospace" : Platform.select({android: "monospace", ios: "Menlo"});
|
|
52
|
+
const textFontSize = isWeb ? 16 : 14;
|
|
53
|
+
const textLineHeight = isWeb ? 24 : 20;
|
|
54
|
+
const markdownTextStyle = {
|
|
55
|
+
fontFamily: "text-regular",
|
|
56
|
+
fontSize: textFontSize,
|
|
57
|
+
lineHeight: textLineHeight,
|
|
58
|
+
...color,
|
|
59
|
+
};
|
|
52
60
|
|
|
53
61
|
return (
|
|
54
62
|
<Markdown
|
|
55
63
|
style={{
|
|
56
|
-
body: {
|
|
64
|
+
body: {width: "100%", ...markdownTextStyle},
|
|
65
|
+
bullet_list: {width: "100%"},
|
|
66
|
+
bullet_list_content: {flex: 1, flexShrink: 1, minWidth: 0},
|
|
67
|
+
bullet_list_icon: {
|
|
68
|
+
flexShrink: 0,
|
|
69
|
+
marginLeft: 0,
|
|
70
|
+
marginRight: 8,
|
|
71
|
+
minWidth: 16,
|
|
72
|
+
textAlign: "center",
|
|
73
|
+
...markdownTextStyle,
|
|
74
|
+
},
|
|
57
75
|
code_block: {
|
|
58
76
|
backgroundColor: theme.surface.neutralLight,
|
|
59
77
|
borderColor: theme.border.default,
|
|
@@ -85,13 +103,57 @@ export const MarkdownView: React.FC<{children: React.ReactNode; inverted?: boole
|
|
|
85
103
|
padding: 8,
|
|
86
104
|
...color,
|
|
87
105
|
},
|
|
88
|
-
heading1: {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
106
|
+
heading1: {
|
|
107
|
+
fontFamily: "heading-bold",
|
|
108
|
+
fontSize: sizes.xl,
|
|
109
|
+
lineHeight: sizes.xl * 1.25,
|
|
110
|
+
...color,
|
|
111
|
+
},
|
|
112
|
+
heading2: {
|
|
113
|
+
fontFamily: "heading-bold",
|
|
114
|
+
fontSize: sizes.lg,
|
|
115
|
+
lineHeight: sizes.lg * 1.25,
|
|
116
|
+
...color,
|
|
117
|
+
},
|
|
118
|
+
heading3: {
|
|
119
|
+
fontFamily: "heading-bold",
|
|
120
|
+
fontSize: sizes.md,
|
|
121
|
+
lineHeight: sizes.md * 1.25,
|
|
122
|
+
...color,
|
|
123
|
+
},
|
|
124
|
+
heading4: {
|
|
125
|
+
fontFamily: "heading-semibold",
|
|
126
|
+
fontSize: sizes.sm,
|
|
127
|
+
lineHeight: sizes.sm * 1.25,
|
|
128
|
+
...color,
|
|
129
|
+
},
|
|
92
130
|
// h5/h6 map to small as well for consistency, slightly smaller visually handled by weight
|
|
93
|
-
heading5: {
|
|
94
|
-
|
|
131
|
+
heading5: {
|
|
132
|
+
fontFamily: "heading-semibold",
|
|
133
|
+
fontSize: sizes.sm,
|
|
134
|
+
lineHeight: sizes.sm * 1.25,
|
|
135
|
+
...color,
|
|
136
|
+
},
|
|
137
|
+
heading6: {
|
|
138
|
+
fontFamily: "heading-semibold",
|
|
139
|
+
fontSize: sizes.sm,
|
|
140
|
+
lineHeight: sizes.sm * 1.25,
|
|
141
|
+
...color,
|
|
142
|
+
},
|
|
143
|
+
list_item: {alignItems: "flex-start", flexDirection: "row", width: "100%"},
|
|
144
|
+
ordered_list: {width: "100%"},
|
|
145
|
+
ordered_list_content: {flex: 1, flexShrink: 1, minWidth: 0},
|
|
146
|
+
ordered_list_icon: {
|
|
147
|
+
flexShrink: 0,
|
|
148
|
+
marginLeft: 0,
|
|
149
|
+
marginRight: 8,
|
|
150
|
+
minWidth: 32,
|
|
151
|
+
textAlign: "right",
|
|
152
|
+
...markdownTextStyle,
|
|
153
|
+
},
|
|
154
|
+
paragraph: {flexShrink: 1, width: "100%", ...markdownTextStyle},
|
|
155
|
+
text: color,
|
|
156
|
+
textgroup: {flexShrink: 1, minWidth: 0},
|
|
95
157
|
}}
|
|
96
158
|
>
|
|
97
159
|
{children}
|
|
@@ -160,7 +160,7 @@ describe("MobileAddressAutocomplete", () => {
|
|
|
160
160
|
|
|
161
161
|
it("falls back to the TextField and propagates its onChange without an API key", () => {
|
|
162
162
|
const handleAddressChange = mock(() => {});
|
|
163
|
-
const {
|
|
163
|
+
const {root} = renderWithTheme(
|
|
164
164
|
<MobileAddressAutocomplete
|
|
165
165
|
handleAddressChange={handleAddressChange}
|
|
166
166
|
handleAutoCompleteChange={() => {}}
|
|
@@ -168,7 +168,11 @@ describe("MobileAddressAutocomplete", () => {
|
|
|
168
168
|
testID="mobile-fallback"
|
|
169
169
|
/>
|
|
170
170
|
);
|
|
171
|
-
|
|
171
|
+
// Find the TextField component with nativeID="address1" and trigger its onChange callback
|
|
172
|
+
const textFields = root.findAll((n) => n.props.nativeID === "address1" && n.props.onChangeText);
|
|
173
|
+
expect(textFields.length).toBeGreaterThan(0);
|
|
174
|
+
textFields[0].props.onChangeText("123 Main St");
|
|
175
|
+
expect(handleAddressChange).toHaveBeenCalledWith("123 Main St");
|
|
172
176
|
});
|
|
173
177
|
|
|
174
178
|
it("wrapping TouchableOpacity clears focus when pressed", () => {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
1
2
|
import {describe, expect, it, mock} from "bun:test";
|
|
2
3
|
import {act, fireEvent} from "@testing-library/react-native";
|
|
3
4
|
|
|
@@ -160,6 +161,270 @@ describe("PickerSelect", () => {
|
|
|
160
161
|
expect(toJSON()).toBeTruthy();
|
|
161
162
|
});
|
|
162
163
|
|
|
164
|
+
describe("web rendering (Platform.OS === 'web')", () => {
|
|
165
|
+
const PlatformModule = require("react-native").Platform;
|
|
166
|
+
let savedOS: any;
|
|
167
|
+
|
|
168
|
+
let hadDocument = false;
|
|
169
|
+
let savedDocument: any;
|
|
170
|
+
|
|
171
|
+
const ensureDocument = () => {
|
|
172
|
+
hadDocument = "document" in globalThis;
|
|
173
|
+
savedDocument = (globalThis as any).document;
|
|
174
|
+
if (typeof (globalThis as any).HTMLElement === "undefined") {
|
|
175
|
+
(globalThis as any).HTMLElement = class HTMLElement {};
|
|
176
|
+
}
|
|
177
|
+
const el = new (globalThis as any).HTMLElement();
|
|
178
|
+
el.blur = () => {};
|
|
179
|
+
(globalThis as any).document = {activeElement: el};
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const restoreDocument = () => {
|
|
183
|
+
if (hadDocument) {
|
|
184
|
+
(globalThis as any).document = savedDocument;
|
|
185
|
+
} else {
|
|
186
|
+
delete (globalThis as any).document;
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
it("renders web dropdown with display label", () => {
|
|
191
|
+
ensureDocument();
|
|
192
|
+
savedOS = PlatformModule.OS;
|
|
193
|
+
try {
|
|
194
|
+
PlatformModule.OS = "web";
|
|
195
|
+
const {getByTestId} = renderWithTheme(<RNPickerSelect {...defaultProps} value="2" />);
|
|
196
|
+
expect(getByTestId("text_input")).toBeTruthy();
|
|
197
|
+
} finally {
|
|
198
|
+
PlatformModule.OS = savedOS;
|
|
199
|
+
restoreDocument();
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("renders web dropdown and opens on press", async () => {
|
|
204
|
+
ensureDocument();
|
|
205
|
+
savedOS = PlatformModule.OS;
|
|
206
|
+
try {
|
|
207
|
+
PlatformModule.OS = "web";
|
|
208
|
+
const onOpen = mock(() => {});
|
|
209
|
+
const {getByTestId} = renderWithTheme(
|
|
210
|
+
<RNPickerSelect {...defaultProps} onOpen={onOpen} value="1" />
|
|
211
|
+
);
|
|
212
|
+
await act(async () => {
|
|
213
|
+
fireEvent.press(getByTestId("web_picker"));
|
|
214
|
+
});
|
|
215
|
+
expect(onOpen).toHaveBeenCalled();
|
|
216
|
+
} finally {
|
|
217
|
+
PlatformModule.OS = savedOS;
|
|
218
|
+
restoreDocument();
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it("does not open web menu when disabled", async () => {
|
|
223
|
+
ensureDocument();
|
|
224
|
+
savedOS = PlatformModule.OS;
|
|
225
|
+
try {
|
|
226
|
+
PlatformModule.OS = "web";
|
|
227
|
+
const onOpen = mock(() => {});
|
|
228
|
+
const {getByTestId} = renderWithTheme(
|
|
229
|
+
<RNPickerSelect {...defaultProps} disabled onOpen={onOpen} />
|
|
230
|
+
);
|
|
231
|
+
await act(async () => {
|
|
232
|
+
fireEvent.press(getByTestId("web_picker"));
|
|
233
|
+
});
|
|
234
|
+
expect(onOpen).not.toHaveBeenCalled();
|
|
235
|
+
} finally {
|
|
236
|
+
PlatformModule.OS = savedOS;
|
|
237
|
+
restoreDocument();
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("calls onClose when closing web menu", async () => {
|
|
242
|
+
ensureDocument();
|
|
243
|
+
savedOS = PlatformModule.OS;
|
|
244
|
+
try {
|
|
245
|
+
PlatformModule.OS = "web";
|
|
246
|
+
const onClose = mock(() => {});
|
|
247
|
+
const onOpen = mock(() => {});
|
|
248
|
+
const {getByTestId} = renderWithTheme(
|
|
249
|
+
<RNPickerSelect {...defaultProps} onClose={onClose} onOpen={onOpen} value="1" />
|
|
250
|
+
);
|
|
251
|
+
await act(async () => {
|
|
252
|
+
fireEvent.press(getByTestId("web_picker"));
|
|
253
|
+
});
|
|
254
|
+
expect(onOpen).toHaveBeenCalled();
|
|
255
|
+
await act(async () => {
|
|
256
|
+
fireEvent.press(getByTestId("web_dropdown_backdrop"));
|
|
257
|
+
});
|
|
258
|
+
expect(onClose).toHaveBeenCalled();
|
|
259
|
+
} finally {
|
|
260
|
+
PlatformModule.OS = savedOS;
|
|
261
|
+
restoreDocument();
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it("renders disabled web dropdown with correct styling", () => {
|
|
266
|
+
ensureDocument();
|
|
267
|
+
savedOS = PlatformModule.OS;
|
|
268
|
+
try {
|
|
269
|
+
PlatformModule.OS = "web";
|
|
270
|
+
const {getByTestId} = renderWithTheme(<RNPickerSelect {...defaultProps} disabled />);
|
|
271
|
+
expect(getByTestId("web_picker")).toBeTruthy();
|
|
272
|
+
} finally {
|
|
273
|
+
PlatformModule.OS = savedOS;
|
|
274
|
+
restoreDocument();
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it("renders web dropdown with inputLabel when available", () => {
|
|
279
|
+
ensureDocument();
|
|
280
|
+
savedOS = PlatformModule.OS;
|
|
281
|
+
try {
|
|
282
|
+
PlatformModule.OS = "web";
|
|
283
|
+
const items = [
|
|
284
|
+
{inputLabel: "Opt 1 short", label: "Option 1 long", value: "1"},
|
|
285
|
+
{label: "Option 2", value: "2"},
|
|
286
|
+
];
|
|
287
|
+
const {getByTestId} = renderWithTheme(
|
|
288
|
+
<RNPickerSelect {...defaultProps} items={items} value="1" />
|
|
289
|
+
);
|
|
290
|
+
expect(getByTestId("text_input")).toBeTruthy();
|
|
291
|
+
} finally {
|
|
292
|
+
PlatformModule.OS = savedOS;
|
|
293
|
+
restoreDocument();
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it("renders web dropdown with no placeholder (empty object)", () => {
|
|
298
|
+
ensureDocument();
|
|
299
|
+
savedOS = PlatformModule.OS;
|
|
300
|
+
try {
|
|
301
|
+
PlatformModule.OS = "web";
|
|
302
|
+
const {getByTestId} = renderWithTheme(
|
|
303
|
+
<RNPickerSelect {...defaultProps} placeholder={{}} value="1" />
|
|
304
|
+
);
|
|
305
|
+
expect(getByTestId("web_picker")).toBeTruthy();
|
|
306
|
+
} finally {
|
|
307
|
+
PlatformModule.OS = savedOS;
|
|
308
|
+
restoreDocument();
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
it("calls onValueChange when a web dropdown option is selected", async () => {
|
|
313
|
+
ensureDocument();
|
|
314
|
+
savedOS = PlatformModule.OS;
|
|
315
|
+
try {
|
|
316
|
+
PlatformModule.OS = "web";
|
|
317
|
+
const mockOnValueChange = mock(() => {});
|
|
318
|
+
const {getByTestId} = renderWithTheme(
|
|
319
|
+
<RNPickerSelect {...defaultProps} onValueChange={mockOnValueChange} value="1" />
|
|
320
|
+
);
|
|
321
|
+
await act(async () => {
|
|
322
|
+
fireEvent.press(getByTestId("web_picker"));
|
|
323
|
+
});
|
|
324
|
+
await act(async () => {
|
|
325
|
+
fireEvent.press(getByTestId("web_dropdown_option_2"));
|
|
326
|
+
});
|
|
327
|
+
expect(mockOnValueChange).toHaveBeenCalledWith("2", 2);
|
|
328
|
+
} finally {
|
|
329
|
+
PlatformModule.OS = savedOS;
|
|
330
|
+
restoreDocument();
|
|
331
|
+
}
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
describe("android rendering", () => {
|
|
336
|
+
const PlatformModule = require("react-native").Platform;
|
|
337
|
+
let savedOS: any;
|
|
338
|
+
|
|
339
|
+
it("renders android headless when useNativeAndroidPickerStyle is false", () => {
|
|
340
|
+
savedOS = PlatformModule.OS;
|
|
341
|
+
try {
|
|
342
|
+
PlatformModule.OS = "android";
|
|
343
|
+
const {getByTestId} = renderWithTheme(
|
|
344
|
+
<RNPickerSelect {...defaultProps} useNativeAndroidPickerStyle={false} value="1" />
|
|
345
|
+
);
|
|
346
|
+
expect(getByTestId("android_touchable_wrapper")).toBeTruthy();
|
|
347
|
+
} finally {
|
|
348
|
+
PlatformModule.OS = savedOS;
|
|
349
|
+
}
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it("renders android headless with fixAndroidTouchableBug", () => {
|
|
353
|
+
savedOS = PlatformModule.OS;
|
|
354
|
+
try {
|
|
355
|
+
PlatformModule.OS = "android";
|
|
356
|
+
const {getByTestId} = renderWithTheme(
|
|
357
|
+
<RNPickerSelect
|
|
358
|
+
{...defaultProps}
|
|
359
|
+
fixAndroidTouchableBug
|
|
360
|
+
useNativeAndroidPickerStyle={false}
|
|
361
|
+
value="1"
|
|
362
|
+
/>
|
|
363
|
+
);
|
|
364
|
+
expect(getByTestId("android_touchable_wrapper")).toBeTruthy();
|
|
365
|
+
} finally {
|
|
366
|
+
PlatformModule.OS = savedOS;
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it("renders android headless with children", () => {
|
|
371
|
+
savedOS = PlatformModule.OS;
|
|
372
|
+
try {
|
|
373
|
+
PlatformModule.OS = "android";
|
|
374
|
+
const {getByTestId} = renderWithTheme(
|
|
375
|
+
<RNPickerSelect {...defaultProps} value="1">
|
|
376
|
+
<>Custom child</>
|
|
377
|
+
</RNPickerSelect>
|
|
378
|
+
);
|
|
379
|
+
expect(getByTestId("android_touchable_wrapper")).toBeTruthy();
|
|
380
|
+
} finally {
|
|
381
|
+
PlatformModule.OS = savedOS;
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
it("renders native android picker style", () => {
|
|
386
|
+
savedOS = PlatformModule.OS;
|
|
387
|
+
try {
|
|
388
|
+
PlatformModule.OS = "android";
|
|
389
|
+
const {getByTestId} = renderWithTheme(<RNPickerSelect {...defaultProps} value="1" />);
|
|
390
|
+
expect(getByTestId("android_picker")).toBeTruthy();
|
|
391
|
+
} finally {
|
|
392
|
+
PlatformModule.OS = savedOS;
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
it("renders native android picker disabled", () => {
|
|
397
|
+
savedOS = PlatformModule.OS;
|
|
398
|
+
try {
|
|
399
|
+
PlatformModule.OS = "android";
|
|
400
|
+
const {getByTestId} = renderWithTheme(
|
|
401
|
+
<RNPickerSelect {...defaultProps} disabled value="1" />
|
|
402
|
+
);
|
|
403
|
+
expect(getByTestId("android_picker")).toBeTruthy();
|
|
404
|
+
} finally {
|
|
405
|
+
PlatformModule.OS = savedOS;
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
it("calls onValueChange on android native picker change", async () => {
|
|
410
|
+
savedOS = PlatformModule.OS;
|
|
411
|
+
try {
|
|
412
|
+
PlatformModule.OS = "android";
|
|
413
|
+
const mockOnValueChange = mock(() => {});
|
|
414
|
+
const {getByTestId} = renderWithTheme(
|
|
415
|
+
<RNPickerSelect {...defaultProps} onValueChange={mockOnValueChange} value="1" />
|
|
416
|
+
);
|
|
417
|
+
const picker = getByTestId("android_picker");
|
|
418
|
+
await act(async () => {
|
|
419
|
+
picker.props.onValueChange?.("2", 1);
|
|
420
|
+
});
|
|
421
|
+
expect(mockOnValueChange).toHaveBeenCalledWith("2", 1);
|
|
422
|
+
} finally {
|
|
423
|
+
PlatformModule.OS = savedOS;
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
});
|
|
427
|
+
|
|
163
428
|
describe("interactions on iOS", () => {
|
|
164
429
|
it("fires onOpen when the iOS wrapper is pressed and onClose when Done is pressed", async () => {
|
|
165
430
|
const onOpen = mock(() => {});
|
package/src/PickerSelect.tsx
CHANGED
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
Text,
|
|
39
39
|
TextInput,
|
|
40
40
|
type TextInputProps,
|
|
41
|
+
type TextProps,
|
|
41
42
|
TouchableOpacity,
|
|
42
43
|
View,
|
|
43
44
|
} from "react-native";
|
|
@@ -388,6 +389,7 @@ export const RNPickerSelect = ({
|
|
|
388
389
|
return <View style={{pointerEvents: "box-only"}}>{children}</View>;
|
|
389
390
|
}
|
|
390
391
|
|
|
392
|
+
const textProps = textInputProps as Partial<TextProps> | undefined;
|
|
391
393
|
return (
|
|
392
394
|
<View
|
|
393
395
|
style={{
|
|
@@ -397,13 +399,27 @@ export const RNPickerSelect = ({
|
|
|
397
399
|
width: "100%",
|
|
398
400
|
}}
|
|
399
401
|
>
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
402
|
+
{disabled ? (
|
|
403
|
+
<Text
|
|
404
|
+
{...textProps}
|
|
405
|
+
style={
|
|
406
|
+
textProps?.style
|
|
407
|
+
? [{color: theme.text.secondaryLight, flex: 1}, textProps.style]
|
|
408
|
+
: {color: theme.text.secondaryLight, flex: 1}
|
|
409
|
+
}
|
|
410
|
+
testID={textInputProps?.testID ?? "text_input"}
|
|
411
|
+
>
|
|
412
|
+
{selectedItem?.inputLabel ? selectedItem?.inputLabel : selectedItem?.label}
|
|
413
|
+
</Text>
|
|
414
|
+
) : (
|
|
415
|
+
<TextInput
|
|
416
|
+
readOnly
|
|
417
|
+
style={{color: theme.text.primary}}
|
|
418
|
+
testID="text_input"
|
|
419
|
+
value={selectedItem?.inputLabel ? selectedItem?.inputLabel : selectedItem?.label}
|
|
420
|
+
{...textInputProps}
|
|
421
|
+
/>
|
|
422
|
+
)}
|
|
407
423
|
{renderIcon()}
|
|
408
424
|
</View>
|
|
409
425
|
);
|
|
@@ -629,7 +645,7 @@ export const RNPickerSelect = ({
|
|
|
629
645
|
{...touchableWrapperProps}
|
|
630
646
|
>
|
|
631
647
|
<Text
|
|
632
|
-
numberOfLines={1}
|
|
648
|
+
numberOfLines={disabled ? undefined : 1}
|
|
633
649
|
style={{
|
|
634
650
|
color: disabled ? theme.text.secondaryLight : theme.text.primary,
|
|
635
651
|
flex: 1,
|