@terreno/ui 0.23.1 → 0.25.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 (80) hide show
  1. package/dist/AIRequestExplorer.js +6 -1
  2. package/dist/AIRequestExplorer.js.map +1 -1
  3. package/dist/ActionSheet.d.ts +1 -0
  4. package/dist/ActionSheet.js +3 -0
  5. package/dist/ActionSheet.js.map +1 -1
  6. package/dist/AiSuggestionBox.d.ts +11 -0
  7. package/dist/AiSuggestionBox.js +50 -23
  8. package/dist/AiSuggestionBox.js.map +1 -1
  9. package/dist/Common.d.ts +25 -1
  10. package/dist/Common.js.map +1 -1
  11. package/dist/CustomSelectField.js +2 -2
  12. package/dist/CustomSelectField.js.map +1 -1
  13. package/dist/FilePickerButton.js +2 -1
  14. package/dist/FilePickerButton.js.map +1 -1
  15. package/dist/PickerSelect.d.ts +10 -2
  16. package/dist/PickerSelect.js +91 -17
  17. package/dist/PickerSelect.js.map +1 -1
  18. package/dist/SelectBadge.js +1 -1
  19. package/dist/SelectBadge.js.map +1 -1
  20. package/dist/SelectField.js +9 -9
  21. package/dist/SelectField.js.map +1 -1
  22. package/dist/WebDropdownMenu.d.ts +36 -5
  23. package/dist/WebDropdownMenu.js +211 -29
  24. package/dist/WebDropdownMenu.js.map +1 -1
  25. package/dist/createWebPortal.d.ts +7 -0
  26. package/dist/createWebPortal.js +3 -0
  27. package/dist/createWebPortal.js.map +1 -0
  28. package/dist/createWebPortal.native.d.ts +7 -0
  29. package/dist/createWebPortal.native.js +2 -0
  30. package/dist/createWebPortal.native.js.map +1 -0
  31. package/dist/fieldElements/FieldHelperText.js +1 -1
  32. package/dist/fieldElements/FieldHelperText.js.map +1 -1
  33. package/dist/icons/SparklesIcon.d.ts +7 -0
  34. package/dist/icons/SparklesIcon.js +32 -0
  35. package/dist/icons/SparklesIcon.js.map +1 -0
  36. package/dist/icons/index.d.ts +1 -0
  37. package/dist/icons/index.js +1 -0
  38. package/dist/icons/index.js.map +1 -1
  39. package/package.json +2 -2
  40. package/src/AIRequestExplorer.tsx +6 -1
  41. package/src/ActionSheet.test.tsx +198 -2
  42. package/src/ActionSheet.tsx +4 -0
  43. package/src/AiSuggestionBox.test.tsx +184 -15
  44. package/src/AiSuggestionBox.tsx +72 -55
  45. package/src/Common.ts +28 -1
  46. package/src/CustomSelectField.test.tsx +13 -3
  47. package/src/CustomSelectField.tsx +2 -0
  48. package/src/EmojiSelector.test.tsx +153 -0
  49. package/src/FilePickerButton.tsx +2 -1
  50. package/src/Modal.test.tsx +47 -0
  51. package/src/PickerSelect.test.tsx +253 -14
  52. package/src/PickerSelect.tsx +206 -49
  53. package/src/SelectBadge.tsx +1 -0
  54. package/src/SelectBadge.web.test.tsx +10 -0
  55. package/src/SelectField.tsx +19 -15
  56. package/src/WebDropdownMenu.test.tsx +449 -0
  57. package/src/WebDropdownMenu.tsx +405 -60
  58. package/src/__snapshots__/AddressField.test.tsx.snap +2088 -665
  59. package/src/__snapshots__/AiSuggestionBox.test.tsx.snap +489 -102
  60. package/src/__snapshots__/CustomSelectField.test.tsx.snap +2118 -1369
  61. package/src/__snapshots__/Field.test.tsx.snap +3787 -1806
  62. package/src/__snapshots__/HeightField.test.tsx.snap +3 -0
  63. package/src/__snapshots__/PickerSelect.test.tsx.snap +7 -7
  64. package/src/__snapshots__/SelectField.test.tsx.snap +1548 -1102
  65. package/src/__snapshots__/Slider.test.tsx.snap +3 -0
  66. package/src/__snapshots__/TextArea.test.tsx.snap +3 -0
  67. package/src/__snapshots__/TextField.test.tsx.snap +3 -0
  68. package/src/__snapshots__/TimezonePicker.test.tsx.snap +2499 -1353
  69. package/src/createWebPortal.native.ts +8 -0
  70. package/src/createWebPortal.test.tsx +13 -0
  71. package/src/createWebPortal.ts +10 -0
  72. package/src/fieldElements/FieldHelperText.tsx +4 -2
  73. package/src/fieldElements/__snapshots__/FieldHelperText.test.tsx.snap +3 -0
  74. package/src/icons/SparklesIcon.test.tsx +16 -0
  75. package/src/icons/SparklesIcon.tsx +38 -0
  76. package/src/icons/__snapshots__/SparklesIcon.test.tsx.snap +47 -0
  77. package/src/icons/index.ts +1 -0
  78. package/src/table/TableBadge.test.tsx +19 -11
  79. package/src/table/__snapshots__/TableBadge.test.tsx.snap +226 -175
  80. package/src/types/react-dom.d.ts +5 -0
@@ -1,8 +1,10 @@
1
1
  import {type FC, useCallback, useEffect, useState} from "react";
2
2
  import {Pressable, View} from "react-native";
3
3
 
4
+ import {Button} from "./Button";
4
5
  import type {AiSuggestionProps} from "./Common";
5
6
  import {Icon} from "./Icon";
7
+ import {SparklesIcon} from "./icons";
6
8
  import {Text} from "./Text";
7
9
  import {useTheme} from "./Theme";
8
10
 
@@ -10,6 +12,17 @@ export interface AiSuggestionBoxProps extends AiSuggestionProps {
10
12
  testID?: string;
11
13
  }
12
14
 
15
+ /**
16
+ * Inline AI suggestion box rendered inside TextField/TextArea via the `aiSuggestion` prop.
17
+ *
18
+ * Expansion is derived from the persisted `status` (`ready` expands; `hidden` and `added`
19
+ * condense into the collapsed header row), but an explicit user Show/Hide toggle always
20
+ * wins — including while a hide/show mutation is still in flight — so a quick
21
+ * Hide-then-Show never snaps back to collapsed when the earlier hide's refetch lands.
22
+ * Hide/Show on a non-`added` suggestion also invoke `onHide`/`onShow` so consumers can
23
+ * persist the choice; toggling an `added` suggestion is purely local so the acceptance
24
+ * record is never reset. "Add to note" stays available after a first add for re-adds.
25
+ */
13
26
  export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
14
27
  status,
15
28
  text,
@@ -23,15 +36,26 @@ export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
23
36
  testID,
24
37
  }) => {
25
38
  const {theme} = useTheme();
26
- const [expanded, setExpanded] = useState(true);
27
-
28
- // Re-expand when a new suggestion arrives or is added
39
+ // The user's last explicit Show/Hide choice. While set, it overrides the
40
+ // status-derived default so in-flight hide/show mutations can't undo a newer click.
41
+ const [expandedIntent, setExpandedIntent] = useState<boolean | null>(null);
42
+
43
+ // Reconcile the local intent with persisted status transitions. Accepting a suggestion
44
+ // (`added`) always condenses the box, and once the persisted status agrees with the
45
+ // user's intent the override is dropped so later transitions (e.g. a regenerated
46
+ // suggestion flipping back to `ready`) use their status defaults. An intent that
47
+ // disagrees with the incoming status is kept — that status is a stale in-flight
48
+ // hide/show landing after a newer click, and must not undo it.
29
49
  useEffect(() => {
30
- if (status === "ready" || status === "added") {
31
- setExpanded(true);
32
- }
50
+ setExpandedIntent((current) => {
51
+ if (current === null || status === "added") {
52
+ return null;
53
+ }
54
+ return current === (status === "ready") ? null : current;
55
+ });
33
56
  }, [status]);
34
57
 
58
+ const expanded = expandedIntent ?? status === "ready";
35
59
  const isAdded = status === "added";
36
60
 
37
61
  const backgroundColor = isAdded
@@ -68,14 +92,24 @@ export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
68
92
  : "AI-generated note (hidden)";
69
93
 
70
94
  const handleHide = useCallback(() => {
71
- setExpanded(false);
72
- onHide?.();
73
- }, [onHide]);
95
+ setExpandedIntent(false);
96
+ // Persist the hide for any non-`added` suggestion — even when the status still reads
97
+ // `hidden` locally (an un-hide may be in flight). Hiding an `added` suggestion is a
98
+ // purely local collapse so the acceptance record stays intact.
99
+ if (status !== "added") {
100
+ onHide?.();
101
+ }
102
+ }, [status, onHide]);
74
103
 
75
104
  const handleShow = useCallback(() => {
76
- setExpanded(true);
77
- onShow?.();
78
- }, [onShow]);
105
+ setExpandedIntent(true);
106
+ // Persist the un-hide for any non-`added` suggestion — even when the status still
107
+ // reads `ready` locally (a hide may be in flight, and this Show must override it).
108
+ // Expanding an `added` suggestion must not reset its status.
109
+ if (status !== "added") {
110
+ onShow?.();
111
+ }
112
+ }, [status, onShow]);
79
113
 
80
114
  const handleThumbsUp = useCallback(() => {
81
115
  if (!onFeedback) {
@@ -106,7 +140,7 @@ export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
106
140
  <Icon
107
141
  color={feedback === "like" ? "secondaryDark" : "secondaryLight"}
108
142
  iconName="thumbs-up"
109
- size="xs"
143
+ size="md"
110
144
  type={feedback === "like" ? "solid" : "regular"}
111
145
  />
112
146
  </Pressable>
@@ -120,7 +154,7 @@ export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
120
154
  <Icon
121
155
  color={feedback === "dislike" ? "secondaryDark" : "secondaryLight"}
122
156
  iconName="thumbs-down"
123
- size="xs"
157
+ size="md"
124
158
  type={feedback === "dislike" ? "solid" : "regular"}
125
159
  />
126
160
  </Pressable>
@@ -131,7 +165,7 @@ export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
131
165
  return (
132
166
  <View style={containerStyle} testID={testID}>
133
167
  <View style={{alignItems: "center", flexDirection: "row", gap: 4, width: "100%"}}>
134
- <Icon color="secondaryDark" iconName="wand-magic-sparkles" size="xs" />
168
+ <SparklesIcon fill={theme.text.secondaryDark} />
135
169
  <View style={{flex: 1}}>
136
170
  <Text color="secondaryDark" size="sm">
137
171
  {headingText}
@@ -146,24 +180,20 @@ export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
146
180
  return (
147
181
  <View style={{...containerStyle, flexDirection: "column"}} testID={testID}>
148
182
  <View style={{alignItems: "center", flexDirection: "row", gap: 4, width: "100%"}}>
149
- <Icon color="secondaryDark" iconName="wand-magic-sparkles" size="xs" />
183
+ <SparklesIcon fill={theme.text.secondaryDark} />
150
184
  <View style={{flex: 1}}>
151
185
  <Text color="secondaryDark" size="sm">
152
186
  {headingText}
153
187
  </Text>
154
188
  </View>
155
189
  <View style={{alignItems: "center", flexDirection: "row", gap: 4}}>
156
- <Pressable
157
- accessibilityLabel="Show suggestion"
158
- accessibilityRole="button"
159
- onPress={handleShow}
160
- style={{height: 28, justifyContent: "center", paddingHorizontal: 16}}
190
+ <Button
191
+ onClick={handleShow}
192
+ size="sm"
161
193
  testID={testID ? `${testID}-show` : undefined}
162
- >
163
- <Text bold color="secondaryDark" size="sm">
164
- Show
165
- </Text>
166
- </Pressable>
194
+ text="Show"
195
+ variant="ghost"
196
+ />
167
197
  {renderFeedback()}
168
198
  </View>
169
199
  </View>
@@ -174,7 +204,7 @@ export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
174
204
  return (
175
205
  <View style={{...containerStyle, alignItems: "flex-end"}} testID={testID}>
176
206
  <View style={{alignItems: "center", flexDirection: "row", gap: 4, width: "100%"}}>
177
- <Icon color="secondaryDark" iconName="wand-magic-sparkles" size="xs" />
207
+ <SparklesIcon fill={theme.text.secondaryDark} />
178
208
  <View style={{flex: 1}}>
179
209
  <Text color="secondaryDark" size="sm">
180
210
  {headingText}
@@ -198,35 +228,22 @@ export const AiSuggestionBox: FC<AiSuggestionBoxProps> = ({
198
228
  width: "100%",
199
229
  }}
200
230
  >
201
- <Pressable
202
- accessibilityLabel="Hide suggestion"
203
- accessibilityRole="button"
204
- onPress={handleHide}
205
- style={{height: 28, justifyContent: "center", paddingHorizontal: 16}}
231
+ <Button
232
+ onClick={handleHide}
233
+ size="sm"
206
234
  testID={testID ? `${testID}-hide` : undefined}
207
- >
208
- <Text bold color="secondaryDark" size="sm">
209
- Hide
210
- </Text>
211
- </Pressable>
212
- <Pressable
213
- accessibilityLabel="Add to note"
214
- accessibilityRole="button"
215
- onPress={onAdd}
216
- style={{
217
- alignItems: "center",
218
- backgroundColor: theme.surface.secondaryDark,
219
- borderRadius: 360,
220
- height: 28,
221
- justifyContent: "center",
222
- paddingHorizontal: 16,
223
- }}
224
- testID={testID ? `${testID}-add` : undefined}
225
- >
226
- <Text bold color="inverted" size="sm">
227
- Add to note
228
- </Text>
229
- </Pressable>
235
+ text="Hide"
236
+ variant="ghost"
237
+ />
238
+ {Boolean(onAdd) && (
239
+ <Button
240
+ onClick={onAdd!}
241
+ size="sm"
242
+ testID={testID ? `${testID}-add` : undefined}
243
+ text="Add to note"
244
+ variant="secondary"
245
+ />
246
+ )}
230
247
  </View>
231
248
  </View>
232
249
  );
package/src/Common.ts CHANGED
@@ -762,10 +762,18 @@ export interface ErrorTextProps {
762
762
  }
763
763
 
764
764
  export interface AiSuggestionProps {
765
- status: "not-started" | "generating" | "ready" | "added";
765
+ /**
766
+ * Persisted suggestion state. `ready` renders expanded; `hidden` and `added` render
767
+ * condensed into the collapsed header row (re-expandable with "Show") so a hidden or
768
+ * accepted suggestion never disappears entirely.
769
+ */
770
+ status: "not-started" | "generating" | "ready" | "added" | "hidden";
766
771
  text?: string;
772
+ /** Adds the suggestion text to the note. Stays available after adding for re-adds. */
767
773
  onAdd?: () => void;
774
+ /** Persists a hide. Called for any non-`added` status when the user presses "Hide". */
768
775
  onHide?: () => void;
776
+ /** Persists an un-hide. Called for any non-`added` status when the user presses "Show". */
769
777
  onShow?: () => void;
770
778
  onFeedback?: (feedback: "like" | "dislike" | null) => void;
771
779
  feedback?: "like" | "dislike" | null;
@@ -1780,6 +1788,12 @@ export interface CustomSelectFieldProps extends WithTestID {
1780
1788
  * The title of the custom select field.
1781
1789
  */
1782
1790
  title?: string;
1791
+
1792
+ /**
1793
+ * When true, options can be filtered as the user types. See `SelectFieldProps.searchable`.
1794
+ * @default true
1795
+ */
1796
+ searchable?: boolean;
1783
1797
  }
1784
1798
 
1785
1799
  export interface DateTimeActionSheetProps {
@@ -2770,6 +2784,11 @@ export interface FieldOption {
2770
2784
  */
2771
2785
  label: string;
2772
2786
 
2787
+ /**
2788
+ * Optional secondary line shown under the label in custom web dropdown menus.
2789
+ */
2790
+ helperText?: string;
2791
+
2773
2792
  /**
2774
2793
  * The key of the option. Useful for uniquely identifying the option.
2775
2794
  */
@@ -2817,6 +2836,14 @@ export interface SelectFieldPropsBase extends WithTestID {
2817
2836
  */
2818
2837
  placeholder?: string;
2819
2838
 
2839
+ /**
2840
+ * When true, options can be filtered as the user types. On web, search happens
2841
+ * in the trigger field; on native, search appears in the dropdown menu and
2842
+ * Android uses a centered modal similar to the platform picker.
2843
+ * @default true
2844
+ */
2845
+ searchable?: boolean;
2846
+
2820
2847
  /**
2821
2848
  * The title of the select field.
2822
2849
  */
@@ -87,7 +87,12 @@ describe("CustomSelectField", () => {
87
87
  it("shows custom input when 'custom' is selected from dropdown", async () => {
88
88
  const onChange = mock(() => {});
89
89
  const {getByTestId, queryByPlaceholderText} = renderWithTheme(
90
- <CustomSelectField onChange={onChange} options={defaultOptions} value="a" />
90
+ <CustomSelectField
91
+ onChange={onChange}
92
+ options={defaultOptions}
93
+ searchable={false}
94
+ value="a"
95
+ />
91
96
  );
92
97
 
93
98
  const picker = getByTestId("ios_picker");
@@ -106,7 +111,12 @@ describe("CustomSelectField", () => {
106
111
  const onChange = mock(() => {});
107
112
  // Start with a custom value so custom input is already shown
108
113
  const {getByTestId, queryByPlaceholderText} = renderWithTheme(
109
- <CustomSelectField onChange={onChange} options={defaultOptions} value="my-custom-value" />
114
+ <CustomSelectField
115
+ onChange={onChange}
116
+ options={defaultOptions}
117
+ searchable={false}
118
+ value="my-custom-value"
119
+ />
110
120
  );
111
121
 
112
122
  // Custom input should be visible because value is not in options
@@ -124,7 +134,7 @@ describe("CustomSelectField", () => {
124
134
  it("calls onChange with selected value for a regular option", async () => {
125
135
  const onChange = mock(() => {});
126
136
  const {getByTestId} = renderWithTheme(
127
- <CustomSelectField onChange={onChange} options={defaultOptions} value="" />
137
+ <CustomSelectField onChange={onChange} options={defaultOptions} searchable={false} value="" />
128
138
  );
129
139
 
130
140
  const picker = getByTestId("ios_picker");
@@ -18,6 +18,7 @@ export const CustomSelectField: FC<CustomSelectFieldProps> = ({
18
18
  helperText,
19
19
  testID,
20
20
  testIDs,
21
+ searchable,
21
22
  }) => {
22
23
  const [currentValue, setCurrentValue] = useState(value);
23
24
  const [showCustomInput, setShowCustomInput] = useState(false);
@@ -90,6 +91,7 @@ export const CustomSelectField: FC<CustomSelectFieldProps> = ({
90
91
  onChange={handleCustomSelectListChange}
91
92
  options={[...options, {label: "Custom", value: "custom"}]}
92
93
  placeholder={placeholder}
94
+ searchable={searchable}
93
95
  testID={fieldTestIDs.input}
94
96
  testIDs={testIDs}
95
97
  title={title}
@@ -1,9 +1,18 @@
1
1
  import {describe, expect, it, mock} from "bun:test";
2
+ import AsyncStorage from "@react-native-async-storage/async-storage";
2
3
  import {act, fireEvent} from "@testing-library/react-native";
3
4
 
4
5
  import EmojiSelector, {Categories, charFromEmojiObject} from "./EmojiSelector";
5
6
  import {renderWithTheme} from "./test-utils";
6
7
 
8
+ interface StoredEmoji {
9
+ category: string;
10
+ count?: number;
11
+ short_names: string[];
12
+ sort_order: number;
13
+ unified: string;
14
+ }
15
+
7
16
  interface LayoutEvent {
8
17
  nativeEvent: {layout: {height: number; width: number; x: number; y: number}};
9
18
  }
@@ -290,6 +299,150 @@ describe("EmojiSelector", () => {
290
299
  expect(onEmojiSelected).toHaveBeenCalled();
291
300
  });
292
301
 
302
+ it("loads persisted history on mount when showHistory is enabled", async () => {
303
+ const stored: StoredEmoji[] = [
304
+ {
305
+ category: "Smileys & Emotion",
306
+ count: 3,
307
+ short_names: ["smiley"],
308
+ sort_order: 1,
309
+ unified: "1F603",
310
+ },
311
+ ];
312
+ const getItemMock = mock(async () => JSON.stringify(stored));
313
+ const originalGetItem = AsyncStorage.getItem;
314
+ AsyncStorage.getItem = getItemMock as unknown as typeof AsyncStorage.getItem;
315
+ try {
316
+ const {toJSON} = renderWithTheme(
317
+ <EmojiSelector
318
+ category={Categories.history}
319
+ columns={6}
320
+ onEmojiSelected={mock(() => {})}
321
+ placeholder="Search"
322
+ showHistory
323
+ showSearchBar
324
+ showSectionTitles
325
+ showTabs
326
+ theme="#007AFF"
327
+ />
328
+ );
329
+ await act(async () => {
330
+ await new Promise((resolve) => setTimeout(resolve, 0));
331
+ });
332
+ expect(getItemMock).toHaveBeenCalled();
333
+ expect(toJSON()).toBeTruthy();
334
+ } finally {
335
+ AsyncStorage.getItem = originalGetItem;
336
+ }
337
+ });
338
+
339
+ it("prepends a newly selected emoji to existing stored history", async () => {
340
+ const onEmojiSelected = mock(() => {});
341
+ const existing: StoredEmoji[] = [
342
+ {
343
+ category: "Smileys & Emotion",
344
+ count: 9,
345
+ short_names: ["unrelated"],
346
+ sort_order: 999,
347
+ unified: "0000-DECOY",
348
+ },
349
+ ];
350
+ const getItemMock = mock(async () => JSON.stringify(existing));
351
+ const setItemMock = mock(async () => undefined);
352
+ const originalGetItem = AsyncStorage.getItem;
353
+ const originalSetItem = AsyncStorage.setItem;
354
+ AsyncStorage.getItem = getItemMock as unknown as typeof AsyncStorage.getItem;
355
+ AsyncStorage.setItem = setItemMock as unknown as typeof AsyncStorage.setItem;
356
+ try {
357
+ const {root, UNSAFE_getAllByType} = renderWithTheme(
358
+ <EmojiSelector
359
+ category={Categories.emotion}
360
+ columns={6}
361
+ onEmojiSelected={onEmojiSelected}
362
+ placeholder="Search"
363
+ showHistory
364
+ showSearchBar={false}
365
+ showSectionTitles
366
+ showTabs={false}
367
+ theme="#007AFF"
368
+ />
369
+ );
370
+ await act(async () => {
371
+ (root as LayoutRoot).props.onLayout?.({
372
+ nativeEvent: {layout: {height: 600, width: 360, x: 0, y: 0}},
373
+ });
374
+ });
375
+ const {FlatList} = require("react-native");
376
+ const [list] = UNSAFE_getAllByType(FlatList);
377
+ const first = (list.props.data ?? [])[0];
378
+ const cell = list.props.renderItem({index: 0, item: first});
379
+ (cell.props as RenderItemCell["props"]).onPress?.();
380
+ await act(async () => {
381
+ await new Promise((resolve) => setTimeout(resolve, 20));
382
+ });
383
+ expect(onEmojiSelected).toHaveBeenCalled();
384
+ expect(setItemMock).toHaveBeenCalled();
385
+ const [, storedValue] = setItemMock.mock.calls[setItemMock.mock.calls.length - 1];
386
+ const parsed = JSON.parse(storedValue as string) as StoredEmoji[];
387
+ // Existing decoy is retained and the freshly selected emoji is prepended.
388
+ expect(parsed.length).toBe(2);
389
+ expect(parsed[1].unified).toBe("0000-DECOY");
390
+ } finally {
391
+ AsyncStorage.getItem = originalGetItem;
392
+ AsyncStorage.setItem = originalSetItem;
393
+ }
394
+ });
395
+
396
+ it("keeps stored history unchanged when the selected emoji already exists", async () => {
397
+ const onEmojiSelected = mock(() => {});
398
+ const originalGetItem = AsyncStorage.getItem;
399
+ const originalSetItem = AsyncStorage.setItem;
400
+ const setItemMock = mock(async () => undefined);
401
+ AsyncStorage.setItem = setItemMock as unknown as typeof AsyncStorage.setItem;
402
+ try {
403
+ const {root, UNSAFE_getAllByType} = renderWithTheme(
404
+ <EmojiSelector
405
+ category={Categories.emotion}
406
+ columns={6}
407
+ onEmojiSelected={onEmojiSelected}
408
+ placeholder="Search"
409
+ showHistory
410
+ showSearchBar={false}
411
+ showSectionTitles
412
+ showTabs={false}
413
+ theme="#007AFF"
414
+ />
415
+ );
416
+ await act(async () => {
417
+ (root as LayoutRoot).props.onLayout?.({
418
+ nativeEvent: {layout: {height: 600, width: 360, x: 0, y: 0}},
419
+ });
420
+ });
421
+ const {FlatList} = require("react-native");
422
+ const [list] = UNSAFE_getAllByType(FlatList);
423
+ const first = (list.props.data ?? [])[0];
424
+ // Seed stored history so it already contains the emoji about to be selected.
425
+ const alreadyStored: StoredEmoji[] = [{...first.emoji, count: 5}];
426
+ AsyncStorage.getItem = mock(async () =>
427
+ JSON.stringify(alreadyStored)
428
+ ) as unknown as typeof AsyncStorage.getItem;
429
+ const cell = list.props.renderItem({index: 0, item: first});
430
+ (cell.props as RenderItemCell["props"]).onPress?.();
431
+ await act(async () => {
432
+ await new Promise((resolve) => setTimeout(resolve, 20));
433
+ });
434
+ expect(onEmojiSelected).toHaveBeenCalled();
435
+ const [, storedValue] = setItemMock.mock.calls[setItemMock.mock.calls.length - 1];
436
+ const parsed = JSON.parse(storedValue as string) as StoredEmoji[];
437
+ // History is left untouched (no duplicate appended) since the emoji is present.
438
+ expect(parsed.length).toBe(1);
439
+ expect(parsed[0].unified).toBe(first.emoji.unified);
440
+ } finally {
441
+ AsyncStorage.getItem = originalGetItem;
442
+ AsyncStorage.setItem = originalSetItem;
443
+ }
444
+ });
445
+
293
446
  it("filters the emoji list when a search query is entered", async () => {
294
447
  const {getByPlaceholderText, UNSAFE_getAllByType, root} = renderWithTheme(
295
448
  <EmojiSelector
@@ -1,3 +1,4 @@
1
+ import {DateTime} from "luxon";
1
2
  import React, {useCallback, useState} from "react";
2
3
 
3
4
  import {Box} from "./Box";
@@ -38,7 +39,7 @@ export const FilePickerButton = ({
38
39
  if (!result.canceled && result.assets.length > 0) {
39
40
  const files: SelectedFile[] = result.assets.map((asset) => ({
40
41
  mimeType: asset.mimeType ?? "image/jpeg",
41
- name: asset.fileName ?? `image-${Date.now()}.jpg`,
42
+ name: asset.fileName ?? `image-${DateTime.now().toMillis()}.jpg`,
42
43
  uri: asset.uri,
43
44
  }));
44
45
  onFilesSelected(files);
@@ -357,6 +357,53 @@ describe("Modal", () => {
357
357
  });
358
358
  });
359
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
+
377
+ it("blurs the focused element when opened on web", () => {
378
+ RN.Platform.OS = "web";
379
+ globalScope.HTMLElement = FakeHTMLElement;
380
+ const active = new FakeHTMLElement();
381
+ globalScope.document = {activeElement: active};
382
+
383
+ renderWithTheme(
384
+ <Modal onDismiss={() => {}} title="Web Modal" visible>
385
+ <Text>Content</Text>
386
+ </Modal>
387
+ );
388
+
389
+ expect(active.blur).toHaveBeenCalled();
390
+ });
391
+
392
+ it("does not blur when the active element is not an HTMLElement", () => {
393
+ RN.Platform.OS = "web";
394
+ globalScope.HTMLElement = FakeHTMLElement;
395
+ globalScope.document = {activeElement: {}};
396
+
397
+ const {toJSON} = renderWithTheme(
398
+ <Modal onDismiss={() => {}} title="Web Modal" visible>
399
+ <Text>Content</Text>
400
+ </Modal>
401
+ );
402
+
403
+ expect(toJSON()).toBeTruthy();
404
+ });
405
+ });
406
+
360
407
  describe("Modal mobile branch", () => {
361
408
  afterEach(() => {
362
409
  (isMobileDevice as ReturnType<typeof mock>).mockImplementation(() => false);