The Search component provides a modal dialog with search functionality, keyboard navigation, and support for recent searches.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/mintlify/components/llms.txt
Use this file to discover all available pages before exploring further.
Basic Usage
Search Component
The main search modal component with input, results display, and keyboard navigation.Props
Callback function called when the user types in the search input. Receives the current query string.
Array of search results to display. Each result should match the
SearchResult type.Controls whether the search modal is visible.
Callback function called when the modal should close (ESC key, backdrop click, or result selection).
When
true, displays a loading state instead of results.Placeholder text displayed in the search input.
Array of recent search results to display when the input is empty.
Callback function called when a result is selected. Receives the selected result and the current query.
Additional CSS classes to apply to the modal wrapper.
Custom component to display when no results are found. If not provided, a default empty state is shown.
Custom component to display while loading. If not provided, a default loading spinner is shown.
Position of the modal on screen.
'top' aligns the modal near the top of the viewport, 'center' centers it vertically.Distance from the top of the viewport when
position is 'top'. Accepts any valid CSS value.SearchResult Type
Unique identifier for the search result.
Main title text for the result.
Description or snippet text for the result.
URL or path for the result.
Optional icon to display next to the result.
Optional array of breadcrumb strings displayed above the result header.
SearchButton Component
A styled button that opens the search modal, typically used withSearchProvider.
Props
Whether to display the keyboard shortcut text on the button.
Text to display as the keyboard shortcut.
Additional CSS classes to apply to the button.
Content to display in the button. Defaults to
"Search...".Example
SearchProvider Component
A context provider that manages search state and keyboard shortcuts. Use this for app-wide search functionality.Props
Props to pass to the Search component (excluding
isOpen and onClose which are managed by the provider).Key to use for the keyboard shortcut.
Whether the shortcut requires a modifier key (Cmd/Ctrl). When
false, the key alone will trigger search (unless user is typing in an input).Child components that can access the search context.
Example with Provider
useSearch Hook
Access the search context from any component withinSearchProvider.
Features
Keyboard Navigation
The Search component includes full keyboard support:- ESC - Close the search modal
- Arrow keys - Navigate through results
- Enter - Select the highlighted result
- Cmd/Ctrl + Enter - Select the first result
- Tab - Prevented when results are visible (stays in search input)
- Cmd/Ctrl + K - Global shortcut (when using
SearchProvider)
Recent Searches
Display recent searches when the input is empty:Custom States
Customize the loading and empty states:Modal Position
Control where the modal appears:Source Code References
- Search component: packages/components/src/components/search/search.tsx:113
- SearchButton component: packages/components/src/components/search/button.tsx:11
- SearchProvider component: packages/components/src/components/search/provider.tsx:27
- SearchResult type: packages/components/src/components/search/search.tsx:30