Skip to main content

Search

Search input with debounce and optional suggestions dropdown.

Preview ยท Search

Codeโ€‹

<div class="vstack" style="max-width:320px">
<input type="search" placeholder="Search tenants, users, records..." />
<fieldset class="group">
<legend>๐Ÿ”</legend>
<input type="search" placeholder="Global search..." />
<button>Go</button>
</fieldset>
</div>

Propsโ€‹

PropTypeDefaultDescription
placeholderstring'Search...'Input placeholder text
valuestring''Controlled value
debouncenumber300Debounce delay in ms โ€” 0 to disable
showSuggestionsbooleanfalseShow autocomplete dropdown
suggestionsstring[] | SearchSuggestion[][]Autocomplete items
loadingbooleanfalseShow spinner while suggestions load
onSearch / (search)(query: string) => voidrequiredFires after debounce
onSuggestionSelect / (suggestionSelect)(item: SearchSuggestion) => voidโ€”Fires when suggestion clicked

TypeScript interfacesโ€‹

interface SearchSuggestion {
value: string; // Value emitted on select
label: string; // Display text in dropdown
category?: string; // Optional group heading
}

// Simple string suggestions
<PrimusSearch
placeholder="Search tenants..."
suggestions={['Acme Corp', 'Globex Inc', 'Initech']}
onSearch={(q) => setQuery(q)}
/>

// Rich suggestions with category grouping
<PrimusSearch
placeholder="Search..."
showSuggestions
suggestions={[
{ value: 't-1', label: 'Acme Corp', category: 'Tenants' },
{ value: 'u-1', label: 'Jane Doe', category: 'Users' },
]}
onSearch={fetchResults}
onSuggestionSelect={(item) => navigate('/' + item.value)}
/>

Propsโ€‹

PropTypeDefaultDescription
placeholderstring'Search...'Input placeholder
valuestringโ€”Controlled input value
debouncenumber300Debounce delay in ms
showSuggestionsbooleanfalseShow suggestion dropdown
suggestionsSearchSuggestion[][]Suggestion list
loadingbooleanfalseShow spinner in input
onSearch / (search)(query: string) => voidโ€”Fires after debounce
onSuggestionSelect / (suggestionSelect)(item: SearchSuggestion) => voidโ€”Fires when suggestion clicked

TypeScript interfacesโ€‹

interface SearchSuggestion {
value: string; // Unique identifier
label: string; // Display text
category?: string; // Optional group heading e.g. 'Tenants', 'Users'
meta?: string; // Secondary text shown alongside label
}

// Example
const suggestions: SearchSuggestion[] = [
{ value: 'tenant-1', label: 'Acme Corp', category: 'Tenants', meta: 'Enterprise' },
{ value: 'tenant-2', label: 'Globex Inc', category: 'Tenants', meta: 'Pro' },
{ value: 'user-1', label: 'Jane Doe', category: 'Users', meta: 'jane@acme.com' },
];
Version history

See the Changelog for version history and breaking changes.