SearchBar
@experimental
Polished global search input with optional HTMX integration.
Quick Start
Features
- Polished search input with optional icon prefix
- HTMX-powered live search with debouncing
- Works with any server-side search endpoint
- Accessible with proper ARIA attributes
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
placeholder |
str |
"Search..." |
Input placeholder text. |
endpoint |
str \| None |
None |
HTMX endpoint for search results. |
target |
str \| None |
None |
HTMX target selector for results. |
swap |
str |
"innerHTML" |
HTMX swap strategy. |
name |
str |
"q" |
Query parameter name. |
method |
str |
"get" |
HTTP method for search requests. |
autocomplete |
str |
"off" |
Input autocomplete attribute. |
**kwargs |
Any |
Extra wrapper attributes. |
Usage Examples
Basic Search Input
Live Search with HTMX
Custom Parameter Name
Notes
- Pure HTML/CSS with optional HTMX enhancement.
- When
endpointis provided, the input submits automatically on input changes with 300ms debounce. - Marked
@experimental.
API Reference
faststrap.components.navigation.search_bar.SearchBar(placeholder='Search...', *, endpoint=None, target=None, swap='innerHTML', name='q', method='get', autocomplete='off', **kwargs)
Polished global search input with optional HTMX integration.
Renders a search form with an icon-prefixed input. When endpoint
is provided, the form submits via HTMX and swaps results into
target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
placeholder
|
str
|
Input placeholder text. |
'Search...'
|
endpoint
|
str | None
|
HTMX endpoint to query for search results. |
None
|
target
|
str | None
|
HTMX target selector for results. |
None
|
swap
|
str
|
HTMX swap strategy. |
'innerHTML'
|
name
|
str
|
Query parameter name for the search term. |
'q'
|
method
|
str
|
HTTP method for the search request. |
'get'
|
autocomplete
|
str
|
Input autocomplete attribute. |
'off'
|
**kwargs
|
Any
|
Additional HTML attributes for the wrapper. |
{}
|
Returns:
| Type | Description |
|---|---|
Div
|
FastHTML |