Contextual Search

Contextual Search

AI
Search
Input

AI-powered search component with recent search history, smart suggestions, and keyboard shortcut support.

Built With

2 components

This block uses the following UI components from the design system:

Preview

Default contextual search with AI suggestions and recent history

AI
k
Recent
AI suggestions
navigate selectEsc close

Custom Suggestions

Provide custom AI suggestions and recent searches

AI
k
Recent
AI suggestions
navigate selectEsc close

Collapsed State

Search bar without expanded suggestions panel

AI
k

Props

Component API reference

PropTypeDefaultDescription
placeholderstring'Search anything...'Placeholder text for the search input
recentSearchesstring[]['marketing tasks', ...]Recent search history items
aiSuggestionsAISuggestion[][...]AI-powered search suggestions with text and reason
defaultOpenbooleantrueInitial 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
classNamestring—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 navigable

Keyboard Navigation

KeyAction
EnterSubmit search query
TabNavigate between interactive elements

Notes

  • Recent searches and suggestions are clickable buttons
  • Clear all action is clearly labeled
  • AI badge provides context about suggestion source

Related Components