MCPcopy Index your code
hub / github.com/adobe/react-spectrum / SearchMenu

Function SearchMenu

packages/dev/s2-docs/src/SearchMenu.tsx:69–332  ·  view source on GitHub ↗
(props: SearchMenuProps)

Source from the content-addressed store, hash-verified

67}
68
69export function SearchMenu(props: SearchMenuProps) {
70 let {pages, currentPage} = useRouter();
71 let {onClose, overlayId, isSearchOpen} = props;
72
73 const searchRef = useRef<TextFieldRef<HTMLInputElement> | null>(null);
74 const iconFilter = useIconFilter();
75
76 const {
77 selectedLibrary,
78 setSelectedLibrary,
79 orderedLibraries: orderedTabs,
80 searchValue,
81 setSearchValue,
82 sectionTagsForDisplay,
83 selectedTagId,
84 handleTagSelectionChange,
85 filteredIcons,
86 isIconsSelected,
87 selectedItems,
88 selectedSectionName,
89 getPlaceholderText,
90 sections
91 } = useSearchMenuState({
92 pages,
93 currentPage,
94 initialSearchValue: props.initialSearchValue,
95 initialTag: props.initialTag,
96 isOpen: isSearchOpen
97 });
98
99 const filteredColors = useFilteredColors(searchValue);
100
101 // Auto-focus search field when menu opens
102 useEffect(() => {
103 if (isSearchOpen) {
104 const timer = setTimeout(() => {
105 searchRef.current?.focus();
106 }, 0);
107 return () => clearTimeout(timer);
108 }
109 }, [isSearchOpen]);
110
111 const handleTabSelectionChange = useCallback(
112 (key: Key) => {
113 setSelectedLibrary(key as Library);
114 // Focus main search field of the newly selected tab
115 setTimeout(() => {
116 const lib = key as Library;
117 const expectedLabel = `Search ${TAB_DEFS[lib].label}`;
118 if (
119 searchRef.current &&
120 searchRef.current.getInputElement()?.getAttribute('aria-label') === expectedLabel
121 ) {
122 searchRef.current.focus();
123 }
124 }, 10);
125 },
126 [setSelectedLibrary]

Callers

nothing calls this directly

Calls 8

useRouterFunction · 0.90
useIconFilterFunction · 0.90
useSearchMenuStateFunction · 0.90
useFilteredColorsFunction · 0.90
getResourceTagsFunction · 0.90
preloadComponentImagesFunction · 0.90
focusMethod · 0.80
getInputElementMethod · 0.65

Tested by

no test coverage detected