Contextual Search
AI
Search
Input
AI-powered search component with recent search history, smart suggestions, and keyboard shortcut support.
Preview
Default contextual search with AI suggestions and recent history
AI
kRecent
AI suggestions
navigate selectEsc close
Custom Suggestions
Provide custom AI suggestions and recent searches
AI
kRecent
AI suggestions
navigate selectEsc close
Collapsed State
Search bar without expanded suggestions panel
AI
kProps
Component API reference
| Prop | Type | Default | Description |
|---|---|---|---|
placeholder | string | 'Search anything...' | Placeholder text for the search input |
recentSearches | string[] | ['marketing tasks', ...] | Recent search history items |
aiSuggestions | AISuggestion[] | [...] | AI-powered search suggestions with text and reason |
defaultOpen | boolean | true | Initial open state of the suggestions panel |
onSearch | (query: string) => void | — | Callback when a search is submitted |
onRecentClick | (search: string) => void | — | Callback when a recent search is clicked |
onSuggestionClick | (suggestion: AISuggestion) => void | — | Callback when an AI suggestion is clicked |
onClearRecent | () => void | — | Callback to clear all recent searches |
className | string | — | Additional CSS classes |
Usage
Import and implementation example
import { ContextualSearch } from '@/components/ui/contextual-search'import type { AISuggestion } from '@/components/ui/contextual-search'
export default function Example() { const handleSearch = (query: string) => { console.log('Searching for:', query) }
const handleSuggestionClick = (suggestion: AISuggestion) => { console.log('Selected suggestion:', suggestion.text) }
return ( <ContextualSearch placeholder="Search projects..." recentSearches={['sprint planning', 'bug fixes']} aiSuggestions={[ { text: 'Overdue tasks', reason: 'Based on your deadlines' }, ]} onSearch={handleSearch} onSuggestionClick={handleSuggestionClick} /> )}Features
Built-in functionality
- AI suggestions: Smart suggestions with context reasons powered by AI
- Recent searches: Shows and manages recent search history
- Keyboard shortcut: Displays CMD+K shortcut indicator
- Enter to submit: Submit search query by pressing Enter
- Clear history: One-click clear all recent searches
- Auto-expand on focus: Suggestions panel opens when input is focused
Accessibility
Accessibility considerations
ARIA Attributes
Uses semantic form elementsInput is focusable and keyboard navigableKeyboard Navigation
| Key | Action |
|---|---|
| Enter | Submit search query |
| Tab | Navigate between interactive elements |
Notes
- Recent searches and suggestions are clickable buttons
- Clear all action is clearly labeled
- AI badge provides context about suggestion source