@terreno/ui 0.24.0 → 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 (64) 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/Common.d.ts +16 -0
  7. package/dist/Common.js.map +1 -1
  8. package/dist/CustomSelectField.js +2 -2
  9. package/dist/CustomSelectField.js.map +1 -1
  10. package/dist/FilePickerButton.js +2 -1
  11. package/dist/FilePickerButton.js.map +1 -1
  12. package/dist/PickerSelect.d.ts +10 -2
  13. package/dist/PickerSelect.js +91 -17
  14. package/dist/PickerSelect.js.map +1 -1
  15. package/dist/SelectBadge.js +1 -1
  16. package/dist/SelectBadge.js.map +1 -1
  17. package/dist/SelectField.js +9 -9
  18. package/dist/SelectField.js.map +1 -1
  19. package/dist/WebDropdownMenu.d.ts +36 -5
  20. package/dist/WebDropdownMenu.js +211 -29
  21. package/dist/WebDropdownMenu.js.map +1 -1
  22. package/dist/createWebPortal.d.ts +7 -0
  23. package/dist/createWebPortal.js +3 -0
  24. package/dist/createWebPortal.js.map +1 -0
  25. package/dist/createWebPortal.native.d.ts +7 -0
  26. package/dist/createWebPortal.native.js +2 -0
  27. package/dist/createWebPortal.native.js.map +1 -0
  28. package/dist/fieldElements/FieldHelperText.js +1 -1
  29. package/dist/fieldElements/FieldHelperText.js.map +1 -1
  30. package/package.json +2 -2
  31. package/src/AIRequestExplorer.tsx +6 -1
  32. package/src/ActionSheet.test.tsx +103 -3
  33. package/src/ActionSheet.tsx +4 -0
  34. package/src/Common.ts +19 -0
  35. package/src/CustomSelectField.test.tsx +13 -3
  36. package/src/CustomSelectField.tsx +2 -0
  37. package/src/EmojiSelector.test.tsx +153 -0
  38. package/src/FilePickerButton.tsx +2 -1
  39. package/src/Modal.test.tsx +47 -0
  40. package/src/PickerSelect.test.tsx +253 -14
  41. package/src/PickerSelect.tsx +206 -49
  42. package/src/SelectBadge.tsx +1 -0
  43. package/src/SelectBadge.web.test.tsx +10 -0
  44. package/src/SelectField.tsx +19 -15
  45. package/src/WebDropdownMenu.test.tsx +449 -0
  46. package/src/WebDropdownMenu.tsx +405 -60
  47. package/src/__snapshots__/AddressField.test.tsx.snap +2088 -665
  48. package/src/__snapshots__/CustomSelectField.test.tsx.snap +2118 -1369
  49. package/src/__snapshots__/Field.test.tsx.snap +3787 -1806
  50. package/src/__snapshots__/HeightField.test.tsx.snap +3 -0
  51. package/src/__snapshots__/PickerSelect.test.tsx.snap +7 -7
  52. package/src/__snapshots__/SelectField.test.tsx.snap +1548 -1102
  53. package/src/__snapshots__/Slider.test.tsx.snap +3 -0
  54. package/src/__snapshots__/TextArea.test.tsx.snap +3 -0
  55. package/src/__snapshots__/TextField.test.tsx.snap +3 -0
  56. package/src/__snapshots__/TimezonePicker.test.tsx.snap +2499 -1353
  57. package/src/createWebPortal.native.ts +8 -0
  58. package/src/createWebPortal.test.tsx +13 -0
  59. package/src/createWebPortal.ts +10 -0
  60. package/src/fieldElements/FieldHelperText.tsx +4 -2
  61. package/src/fieldElements/__snapshots__/FieldHelperText.test.tsx.snap +3 -0
  62. package/src/table/TableBadge.test.tsx +19 -11
  63. package/src/table/__snapshots__/TableBadge.test.tsx.snap +226 -175
  64. package/src/types/react-dom.d.ts +5 -0
@@ -25,7 +25,15 @@
25
25
 
26
26
  import {Picker} from "@react-native-picker/picker";
27
27
  import isEqual from "lodash/isEqual";
28
- import {type ComponentType, type ReactNode, useCallback, useEffect, useMemo, useState} from "react";
28
+ import {
29
+ type ComponentType,
30
+ type ReactNode,
31
+ useCallback,
32
+ useEffect,
33
+ useMemo,
34
+ useRef,
35
+ useState,
36
+ } from "react";
29
37
  import {
30
38
  Keyboard,
31
39
  Modal,
@@ -44,7 +52,12 @@ import {
44
52
 
45
53
  import {Icon} from "./Icon";
46
54
  import {useTheme} from "./Theme";
47
- import {useWebDropdownAnchor, WebDropdownMenu, type WebDropdownMenuOption} from "./WebDropdownMenu";
55
+ import {
56
+ scheduleAfterPaint,
57
+ useWebDropdownAnchor,
58
+ WebDropdownMenu,
59
+ type WebDropdownMenuOption,
60
+ } from "./WebDropdownMenu";
48
61
 
49
62
  export const defaultStyles = StyleSheet.create({
50
63
  chevron: {
@@ -65,7 +78,7 @@ export const defaultStyles = StyleSheet.create({
65
78
  borderRadius: 4,
66
79
  borderWidth: 1,
67
80
  flexDirection: "row",
68
- justifyContent: "center",
81
+ justifyContent: "flex-start",
69
82
  minHeight: 40,
70
83
  width: "100%",
71
84
  },
@@ -78,6 +91,8 @@ export interface PickerSelectItem {
78
91
  key?: string | number;
79
92
  color?: string;
80
93
  inputLabel?: string;
94
+ /** Shown under the label in the web custom dropdown only. */
95
+ helperText?: string;
81
96
  }
82
97
 
83
98
  export interface RNPickerSelectProps {
@@ -112,6 +127,13 @@ export interface RNPickerSelectProps {
112
127
  touchableWrapperProps?: Partial<PressableProps>;
113
128
 
114
129
  InputAccessoryView?: ComponentType<{testID?: string}>;
130
+
131
+ /**
132
+ * When true, options can be filtered as the user types. On web, search happens
133
+ * in the trigger field; on native, search appears in the dropdown menu.
134
+ * @default true
135
+ */
136
+ searchable?: boolean;
115
137
  }
116
138
 
117
139
  export const RNPickerSelect = ({
@@ -136,8 +158,11 @@ export const RNPickerSelect = ({
136
158
  touchableWrapperProps,
137
159
 
138
160
  InputAccessoryView,
161
+ searchable = true,
139
162
  }: RNPickerSelectProps) => {
140
163
  const [showPicker, setShowPicker] = useState<boolean>(false);
164
+ const [webSearchQuery, setWebSearchQuery] = useState("");
165
+ const webSearchInputRef = useRef<TextInput>(null);
141
166
  const [animationType, setAnimationType] = useState<ModalProps["animationType"]>(undefined);
142
167
  const [orientation, setOrientation] = useState<"portrait" | "landscape">("portrait");
143
168
  const [doneDepressed, setDoneDepressed] = useState<boolean>(false);
@@ -155,13 +180,22 @@ export const RNPickerSelect = ({
155
180
  // On web, blur the active element before the picker modal opens to prevent
156
181
  // "aria-hidden on a focused element" warnings from React Native Web.
157
182
  useEffect(() => {
158
- if (showPicker && Platform.OS === "web") {
183
+ if (showPicker && Platform.OS === "web" && !searchable) {
159
184
  const active = document.activeElement;
160
185
  if (active instanceof HTMLElement) {
161
186
  active.blur();
162
187
  }
163
188
  }
164
- }, [showPicker]);
189
+ }, [showPicker, searchable]);
190
+
191
+ // Keep the trigger input focused after the menu opens so typing works on web.
192
+ useEffect(() => {
193
+ if (showPicker && searchable && Platform.OS === "web") {
194
+ scheduleAfterPaint(() => {
195
+ webSearchInputRef.current?.focus();
196
+ });
197
+ }
198
+ }, [searchable, showPicker]);
165
199
 
166
200
  const options = useMemo(() => {
167
201
  if (isEqual(placeholder, {})) {
@@ -491,6 +525,9 @@ export const RNPickerSelect = ({
491
525
  );
492
526
  };
493
527
 
528
+ // On Android, use Spinner dropdown mode instead of the default dialog. Dialog
529
+ // mode with many items becomes a near-fullscreen modal where the dimmed scrim
530
+ // often does not receive outside taps to dismiss without selecting a value.
494
531
  const renderAndroidHeadless = () => {
495
532
  // `View` and `Pressable` accept disjoint prop sets; the fork swaps between them to work
496
533
  // around an Android touchable bug, so we cast to a structural component type that accepts
@@ -511,6 +548,7 @@ export const RNPickerSelect = ({
511
548
  {renderTextInputOrChildren()}
512
549
  <Picker
513
550
  enabled={!disabled}
551
+ mode="dropdown"
514
552
  onValueChange={onValueChangeEvent}
515
553
  selectedValue={selectedItem?.value}
516
554
  style={[
@@ -551,6 +589,7 @@ export const RNPickerSelect = ({
551
589
  <Picker
552
590
  dropdownIconColor={theme.text.primary}
553
591
  enabled={!disabled}
592
+ mode="dropdown"
554
593
  onValueChange={onValueChangeEvent}
555
594
  selectedValue={selectedItem?.value}
556
595
  style={[{color: theme.text.primary, width: "100%"}]}
@@ -566,20 +605,30 @@ export const RNPickerSelect = ({
566
605
  // styling to each browser (Safari in particular looks very different from
567
606
  // Chrome/Firefox). Instead, we render a styled trigger + popup menu so the
568
607
  // dropdown looks identical across browsers and matches the Terreno design.
569
- const openWebMenu = (): void => {
570
- if (disabled) {
571
- return;
572
- }
573
- measureWebAnchor(() => {
574
- setShowPicker(true);
575
- if (onOpen) {
576
- onOpen();
608
+ const openWebMenu = useCallback(
609
+ (initialSearchQuery = ""): void => {
610
+ if (disabled) {
611
+ return;
577
612
  }
578
- });
579
- };
613
+ measureWebAnchor(() => {
614
+ setWebSearchQuery(initialSearchQuery);
615
+ setShowPicker(true);
616
+ if (searchable && Platform.OS === "web") {
617
+ scheduleAfterPaint(() => {
618
+ webSearchInputRef.current?.focus();
619
+ });
620
+ }
621
+ if (onOpen) {
622
+ onOpen();
623
+ }
624
+ });
625
+ },
626
+ [disabled, measureWebAnchor, onOpen, searchable]
627
+ );
580
628
 
581
629
  const closeWebMenu = (): void => {
582
630
  setShowPicker(false);
631
+ setWebSearchQuery("");
583
632
  if (onClose) {
584
633
  onClose();
585
634
  }
@@ -601,6 +650,7 @@ export const RNPickerSelect = ({
601
650
  }
602
651
  menuOptions.push({
603
652
  color: item.color,
653
+ helperText: item.helperText,
604
654
  key: item.key,
605
655
  label: item.label,
606
656
  value: String(item.value ?? ""),
@@ -610,10 +660,67 @@ export const RNPickerSelect = ({
610
660
  return {menuOptions, originalIndexes};
611
661
  }, [options]);
612
662
 
613
- const renderWeb = () => {
663
+ const {filteredWebMenuOptions, filteredWebMenuOptionIndexes} = useMemo<{
664
+ filteredWebMenuOptions: WebDropdownMenuOption[];
665
+ filteredWebMenuOptionIndexes: number[];
666
+ }>(() => {
667
+ const normalizedQuery = webSearchQuery.trim().toLowerCase();
668
+ if (!searchable || normalizedQuery.length === 0) {
669
+ return {
670
+ filteredWebMenuOptionIndexes: webMenuOptionIndexes,
671
+ filteredWebMenuOptions: webMenuOptions,
672
+ };
673
+ }
674
+
675
+ const filteredWebMenuOptions: WebDropdownMenuOption[] = [];
676
+ const filteredWebMenuOptionIndexes: number[] = [];
677
+ for (let i = 0; i < webMenuOptions.length; i++) {
678
+ const item = webMenuOptions[i];
679
+ const matchesLabel = item.label.toLowerCase().includes(normalizedQuery);
680
+ const matchesHelper = item.helperText?.toLowerCase().includes(normalizedQuery) ?? false;
681
+ if (matchesLabel || matchesHelper) {
682
+ filteredWebMenuOptions.push(item);
683
+ filteredWebMenuOptionIndexes.push(webMenuOptionIndexes[i] ?? i);
684
+ }
685
+ }
686
+ return {filteredWebMenuOptionIndexes, filteredWebMenuOptions};
687
+ }, [searchable, webMenuOptionIndexes, webMenuOptions, webSearchQuery]);
688
+
689
+ const handleWebSearchChange = useCallback(
690
+ (text: string): void => {
691
+ if (!showPicker && !disabled) {
692
+ openWebMenu(text);
693
+ return;
694
+ }
695
+ setWebSearchQuery(text);
696
+ },
697
+ [disabled, openWebMenu, showPicker]
698
+ );
699
+
700
+ const handleWebSearchFocus = useCallback((): void => {
701
+ if (!disabled && !showPicker) {
702
+ openWebMenu();
703
+ }
704
+ }, [disabled, openWebMenu, showPicker]);
705
+
706
+ const renderCustomDropdown = () => {
707
+ const searchInTrigger = searchable && Platform.OS === "web";
614
708
  const displayLabel = selectedItem?.inputLabel ?? selectedItem?.label ?? "";
615
709
  const selectedOriginalIdx = getSelectedItem(itemKey, value).idx;
616
- const webSelectedIndex = webMenuOptionIndexes.indexOf(selectedOriginalIdx);
710
+ const menuOptions = searchInTrigger ? filteredWebMenuOptions : webMenuOptions;
711
+ const menuOptionIndexes = searchInTrigger ? filteredWebMenuOptionIndexes : webMenuOptionIndexes;
712
+ const menuSelectedIndex = menuOptionIndexes.indexOf(selectedOriginalIdx);
713
+ const triggerTextStyle = {
714
+ color: disabled ? theme.text.secondaryLight : theme.text.primary,
715
+ flex: 1,
716
+ fontFamily: "text" as const,
717
+ fontSize: 16,
718
+ paddingLeft: 0,
719
+ paddingRight: 8,
720
+ paddingVertical: 0,
721
+ ...(Platform.OS === "web" ? {outline: "none" as const} : {}),
722
+ };
723
+
617
724
  return (
618
725
  <View
619
726
  ref={webTriggerRef}
@@ -628,42 +735,85 @@ export const RNPickerSelect = ({
628
735
  },
629
736
  ]}
630
737
  >
631
- <Pressable
632
- aria-role="button"
633
- disabled={disabled}
634
- onPress={openWebMenu}
635
- style={{
636
- alignItems: "center",
637
- flexDirection: "row",
638
- minHeight: 40,
639
- paddingHorizontal: 8,
640
- width: "100%",
641
- }}
642
- testID="web_picker"
643
- {...touchableWrapperProps}
644
- >
645
- <Text
646
- numberOfLines={disabled ? undefined : 1}
738
+ {searchInTrigger ? (
739
+ <View
647
740
  style={{
648
- color: disabled ? theme.text.secondaryLight : theme.text.primary,
649
- flex: 1,
650
- paddingRight: 8,
741
+ alignItems: "center",
742
+ flexDirection: "row",
743
+ justifyContent: "space-between",
744
+ minHeight: 40,
745
+ paddingHorizontal: 8,
746
+ width: "100%",
651
747
  }}
652
- testID="text_input"
748
+ testID="web_picker"
653
749
  >
654
- {displayLabel}
655
- </Text>
656
- <Icon
657
- color={disabled ? "secondaryLight" : "primary"}
658
- iconName={showPicker ? "angle-up" : "angle-down"}
659
- size="sm"
660
- />
661
- </Pressable>
750
+ <TextInput
751
+ {...textInputProps}
752
+ editable={!disabled}
753
+ onChangeText={handleWebSearchChange}
754
+ onFocus={handleWebSearchFocus}
755
+ placeholder={showPicker ? "Search..." : undefined}
756
+ placeholderTextColor={theme.text.secondaryLight}
757
+ ref={webSearchInputRef}
758
+ style={triggerTextStyle}
759
+ testID="text_input"
760
+ value={showPicker ? webSearchQuery : displayLabel}
761
+ />
762
+ <Pressable
763
+ aria-role="button"
764
+ disabled={disabled}
765
+ onPress={showPicker ? closeWebMenu : () => openWebMenu()}
766
+ {...touchableWrapperProps}
767
+ >
768
+ <Icon
769
+ color={disabled ? "secondaryLight" : "primary"}
770
+ iconName={showPicker ? "angle-up" : "angle-down"}
771
+ size="sm"
772
+ />
773
+ </Pressable>
774
+ </View>
775
+ ) : (
776
+ <Pressable
777
+ aria-role="button"
778
+ disabled={disabled}
779
+ onPress={() => openWebMenu()}
780
+ style={{
781
+ alignItems: "center",
782
+ flexDirection: "row",
783
+ justifyContent: "space-between",
784
+ minHeight: 40,
785
+ paddingHorizontal: 8,
786
+ width: "100%",
787
+ }}
788
+ testID="web_picker"
789
+ {...touchableWrapperProps}
790
+ >
791
+ <Text
792
+ numberOfLines={disabled ? undefined : 1}
793
+ style={{
794
+ color: disabled ? theme.text.secondaryLight : theme.text.primary,
795
+ flex: 1,
796
+ fontFamily: "text",
797
+ fontSize: 16,
798
+ paddingRight: 8,
799
+ }}
800
+ testID="text_input"
801
+ >
802
+ {displayLabel}
803
+ </Text>
804
+ <Icon
805
+ color={disabled ? "secondaryLight" : "primary"}
806
+ iconName={showPicker ? "angle-up" : "angle-down"}
807
+ size="sm"
808
+ />
809
+ </Pressable>
810
+ )}
662
811
  <WebDropdownMenu
663
812
  anchor={webAnchor}
813
+ keepTriggerFocus={searchInTrigger}
664
814
  onClose={closeWebMenu}
665
815
  onSelect={(_val, idx) => {
666
- const originalIndex = webMenuOptionIndexes[idx] ?? idx;
816
+ const originalIndex = menuOptionIndexes[idx] ?? idx;
667
817
  // Pass the original (non-stringified) value through so lodash
668
818
  // `isEqual` matching in `getSelectedItem` works for number /
669
819
  // object values.
@@ -671,8 +821,11 @@ export const RNPickerSelect = ({
671
821
  onValueChangeEvent(originalValue, originalIndex);
672
822
  closeWebMenu();
673
823
  }}
674
- options={webMenuOptions}
675
- selectedIndex={webSelectedIndex >= 0 ? webSelectedIndex : undefined}
824
+ options={menuOptions}
825
+ presentation={Platform.OS === "android" ? "centered" : "anchored"}
826
+ searchable={searchable && !searchInTrigger}
827
+ selectedIndex={menuSelectedIndex >= 0 ? menuSelectedIndex : undefined}
828
+ showEmptyStateWhenNoOptions={searchInTrigger && webSearchQuery.trim().length > 0}
676
829
  testIDPrefix="web_dropdown"
677
830
  visible={showPicker}
678
831
  />
@@ -681,12 +834,16 @@ export const RNPickerSelect = ({
681
834
  };
682
835
 
683
836
  const render = () => {
837
+ if (searchable) {
838
+ return renderCustomDropdown();
839
+ }
840
+
684
841
  if (Platform.OS === "ios") {
685
842
  return renderIOS();
686
843
  }
687
844
 
688
845
  if (Platform.OS === "web") {
689
- return renderWeb();
846
+ return renderCustomDropdown();
690
847
  }
691
848
 
692
849
  if (children || !useNativeAndroidPickerStyle) {
@@ -232,6 +232,7 @@ export const SelectBadge = ({
232
232
  onSelect={(val) => handleOnChange(val)}
233
233
  options={webMenuOptions}
234
234
  optionTextStyle={{fontFamily: "text", fontSize: 12}}
235
+ searchable={false}
235
236
  selectedValue={value}
236
237
  testIDPrefix="web_badge"
237
238
  visible={showPicker}
@@ -63,6 +63,16 @@ describe("SelectBadge (web)", () => {
63
63
  expect(getByTestId("web_badge_modal").props.visible).toBe(false);
64
64
  });
65
65
 
66
+ it("does not render a search input in the badge dropdown", () => {
67
+ const {getByLabelText, queryByTestId} = renderWithTheme(
68
+ <SelectBadge onChange={() => {}} options={options} value="a" />
69
+ );
70
+ act(() => {
71
+ fireEvent.press(getByLabelText("Open select badge options"));
72
+ });
73
+ expect(queryByTestId("web_badge_search")).toBeNull();
74
+ });
75
+
66
76
  it("does not open the dropdown when disabled", () => {
67
77
  const {getByLabelText, getByTestId} = renderWithTheme(
68
78
  <SelectBadge disabled onChange={() => {}} options={options} value="a" />
@@ -13,6 +13,7 @@ export const SelectField: FC<SelectFieldProps> = ({
13
13
  options,
14
14
  requireValue = false,
15
15
  placeholder = "Please select an option.",
16
+ searchable = true,
16
17
  title,
17
18
  value,
18
19
  onChange,
@@ -23,23 +24,26 @@ export const SelectField: FC<SelectFieldProps> = ({
23
24
  const fieldTestIDs = resolveFieldTestIDsFromProps({testID, testIDs});
24
25
 
25
26
  return (
26
- <View style={{width: "100%"}}>
27
+ <View style={{minWidth: 0, width: "100%"}}>
27
28
  {Boolean(title) && <FieldTitle testID={fieldTestIDs.label} text={title!} />}
28
29
  {Boolean(errorText) && <FieldError testID={fieldTestIDs.error} text={errorText!} />}
29
- <RNPickerSelect
30
- disabled={disabled}
31
- items={options}
32
- onValueChange={(v) => {
33
- if (v === undefined || v === null || v === "") {
34
- onChange("");
35
- } else {
36
- onChange(String(v));
37
- }
38
- }}
39
- placeholder={!requireValue ? clearOption : {}}
40
- textInputProps={{testID: fieldTestIDs.input}}
41
- value={value ?? ""}
42
- />
30
+ <View style={{alignSelf: "stretch", minWidth: 0, width: "100%"}}>
31
+ <RNPickerSelect
32
+ disabled={disabled}
33
+ items={options}
34
+ onValueChange={(v) => {
35
+ if (v === undefined || v === null || v === "") {
36
+ onChange("");
37
+ } else {
38
+ onChange(String(v));
39
+ }
40
+ }}
41
+ placeholder={!requireValue ? clearOption : {}}
42
+ searchable={searchable}
43
+ textInputProps={{testID: fieldTestIDs.input}}
44
+ value={value ?? ""}
45
+ />
46
+ </View>
43
47
  {Boolean(helperText) && <FieldHelperText testID={fieldTestIDs.helper} text={helperText!} />}
44
48
  </View>
45
49
  );