Search Bar
v1.0.0
Input
A powerful search component with keyboard shortcuts, suggestions, and multiple variants
Dependencies
framer-motion
lucide-react
@/components/ui/input
@/components/ui/button
@/components/ui/badge
@/lib/utils
Installation
Add this component to your project
CLI Installation
npx shadcn@latest add https://ui.authmate.xyz/registry/search-bar.jsonManual Installation
// 1. Install dependencies
npm install framer-motion lucide-react
// 2. Make sure you have these shadcn components installed:
npx shadcn@latest add input button badge
// 3. Copy the component code to components/ui/search-bar.tsx
// 4. Add global keyboard event listener to your root layout (optional for global shortcuts):
// In your app/layout.tsx or _app.tsx:
useEffect(() => {
const handleKeyDown = (e: KeyboardEvent) => {
if ((e.metaKey || e.ctrlKey) && e.key === 'k') {
e.preventDefault()
// Focus your search bar
document.querySelector('[data-search-bar]')?.focus()
}
}
document.addEventListener('keydown', handleKeyDown)
return () => document.removeEventListener('keydown', handleKeyDown)
}, [])
// 5. Usage example:
import { SearchBar } from "@/components/ui/search-bar"
import { useState } from "react"
export default function MySearchComponent() {
const [searchValue, setSearchValue] = useState("")
const suggestions = [
{
id: "1",
title: "Dashboard",
description: "Go to dashboard",
category: "Navigation"
},
{
id: "2",
title: "Settings",
description: "Open settings",
category: "Configuration"
}
]
return (
<div className="w-full max-w-md mx-auto">
<SearchBar
placeholder="Search or press Cmd+K..."
value={searchValue}
onChange={setSearchValue}
suggestions={suggestions}
onSearch={(query) => {
console.log("Searching for:", query)
// Perform your search logic here
}}
onSelect={(suggestion) => {
console.log("Selected:", suggestion)
// Handle suggestion selection
}}
shortcutKey="k" // Cmd+K or Ctrl+K to focus
variant="default"
showSuggestions={true}
/>
</div>
)
}Props
Component properties and their types
placeholderstring
default: Search...
Placeholder text for the search input
valuestring
default: undefined
Controlled value of the search input
onChange(value: string) => void
default: undefined
Callback fired when the input value changes
onSearch(value: string) => void
default: undefined
Callback fired when search is submitted
onSelect(suggestion: SearchSuggestion) => void
default: undefined
Callback fired when a suggestion is selected
suggestionsSearchSuggestion[]
default: []
Array of search suggestions to display
showSuggestionsboolean
default: true
Whether to show the suggestions dropdown
showShortcutsboolean
default: true
Whether to enable keyboard shortcuts
shortcutKeystring
default: k
Key to use for the focus shortcut (Cmd/Ctrl + key)
variantdefault | command | floating
default: default
Visual variant of the search bar
sizesm | md | lg
default: md
Size of the search bar
disabledboolean
default: false
Whether the search bar is disabled
loadingboolean
default: false
Whether to show loading state
maxSuggestionsnumber
default: 8
Maximum number of suggestions to display
Examples
4 different usage examples
Basic Usage
import { SearchBar } from "@/components/ui/search-bar"
import { useState } from "react"
export function BasicSearch() {
const [value, setValue] = useState("")
return (
<SearchBar
placeholder="Search..."
value={value}
onChange={setValue}
onSearch={(query) => console.log("Search:", query)}
/>
)
}Registry
View the component registry file
Live Preview
Interactive
4 examples available