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

Function SearchMenuTrigger

packages/dev/s2-docs/src/SearchMenuTrigger.tsx:58–325  ·  view source on GitHub ↗
({
  onOpen,
  onClose,
  isSearchOpen,
  overlayId,
  staticColor,
  ...props
}: SearchMenuTriggerProps)

Source from the content-addressed store, hash-verified

56});
57
58export default function SearchMenuTrigger({
59 onOpen,
60 onClose,
61 isSearchOpen,
62 overlayId,
63 staticColor,
64 ...props
65}: SearchMenuTriggerProps) {
66 let {currentPage} = useRouter();
67 let {colorScheme} = useSettings();
68 let [initialSearchValue, setInitialSearchValue] = useState('');
69 let open = useCallback(
70 (value: string) => {
71 setInitialSearchValue(value);
72 onOpen();
73 },
74 [onOpen]
75 );
76
77 useEffect(() => {
78 preloadSearchMenu();
79 }, []);
80
81 // Type to search handler
82 let onKeyDown = useCallback(
83 (e: React.KeyboardEvent<HTMLButtonElement>) => {
84 // Ignore modifier keys, navigation keys, Enter, Escape, etc.
85 if (e.key.length === 1 && !e.metaKey && !e.ctrlKey && !e.altKey && e.key !== ' ') {
86 e.preventDefault();
87 open(e.key);
88 }
89
90 if (e.key === 'ArrowDown') {
91 e.preventDefault();
92 open('');
93 }
94 },
95 [open]
96 );
97
98 useEffect(() => {
99 let isMac = /Mac/.test(navigator.platform);
100 const isTextInputLike = (el: Element | null): boolean => {
101 if (!el) {
102 return false;
103 }
104 let h = el as HTMLElement;
105 return (
106 h.isContentEditable || !!el.closest('input, textarea, [contenteditable], [role="textbox"]')
107 );
108 };
109
110 const handleKeyDown = (e: KeyboardEvent) => {
111 if (e.isComposing) {
112 // avoid intercepting IME input
113 return;
114 }
115

Callers

nothing calls this directly

Calls 11

useRouterFunction · 0.90
useSettingsFunction · 0.90
lightDarkFunction · 0.90
fontRelativeFunction · 0.90
getLibraryLabelFunction · 0.90
getLibraryFromPageFunction · 0.90
preloadSearchMenuFunction · 0.85
addEventListenerMethod · 0.80
removeEventListenerMethod · 0.80
focusMethod · 0.80
openFunction · 0.50

Tested by

no test coverage detected