Search
Introduction
The Search component is an instant-search autocomplete input that filters and navigates through pre-compiled JSON document indexes completely client-side. Rather than firing expensive database requests on every keystroke, the Search input lazily loads its static JSON document once on initial user interaction and provides debounced, instant matches.
The Search component is fully integrated as a search block in the Page Builder, allowing content authors and developers to configure index source addresses, result label metrics, dropdown constraints, and empty-state placeholders directly within the CMS.
Usage via CMS Page Builder (JSON)
These examples illustrate how content editors bind and structure instant search controls inside the JSON page schemas (content/pages/*.json).
1. Instant Article Search Dropdown
Queries are filtered against a pre-compiled blog post search index, displaying a dropdown with up to 5 matching results.
{
"type": "search",
"src": "/api/posts/search.json",
"placeholder": "Search articles...",
"itemLabel": "articles",
"maxSuggestions": 5,
"debounceMs": 150,
"interactive": true
}
2. In-Place Element Grid Filtering
Instead of displaying a navigation dropdown, this configuration hides or reveals existing elements on the page (such as card modules or lists) whose unique attributes (like data-post-slug) match the filtered results.
{
"type": "search",
"src": "/api/posts/search.json",
"placeholder": "Filter visual cards...",
"itemLabel": "modules",
"filterAttribute": "data-post-slug",
"emptyStateId": "search-no-results-placeholder",
"interactive": true
}
3. Standard No-JS Fallback Form
Demonstrates a standard layout configuration wrapping a semantic GET form method that queries a direct URL parameter when Javascript execution is unavailable.
{
"type": "search",
"src": "/api/posts/search.json",
"action": "/blog",
"placeholder": "Search website...",
"syncUrl": true,
"interactive": true
}
CMS Configuration Reference
These fields map directly to Sveltia CMS block properties under public/admin/config.yml or the Page Builder configurations:
| Property | CMS Field Type | Default | Description / Supported Options |
|---|---|---|---|
Index Source URL (src) | string | "/api/posts/search.json" | Relative or absolute path pointing to the static compiled JSON search index document. |
Placeholder Text (placeholder) | string | "Search..." | Ghost helper text rendered inside the input field before typing. |
Initial Query (initialQuery) | string | - | Pre-seeded query value (e.g. matching an active ?q= URL parameter). |
Debounce Delay (debounceMs) | number | 150 | Time delay in milliseconds after a keystroke is registered before filtering matches. |
Max Suggestions (maxSuggestions) | number | 8 | Maximum number of results displayed inside the autocomplete list. |
Filter Attribute (filterAttribute) | string | - | Target DOM attribute (e.g. data-post-slug) of page elements to show/hide in-place based on matches. |
Empty State ID (emptyStateId) | string | - | DOM ID of the visual "No matches found" placeholder card to reveal when matches drop to zero. |
Noun Label (itemLabel) | string | "results" | Text used to denote categories in the counts (e.g., "articles", "resources"). |
Show Result Count (showCount) | boolean | true | Renders a small status count ("Showing X of N") below the search input. |
No-JS Action Path (action) | string | - | Fallback endpoint path where the GET form is submitted with a standard ?q= parameter. |
Sync URL (syncUrl) | boolean | true | Mirrors the active search string directly into the browser address bar as ?q=. |
Force Interactive (interactive) | boolean | true | Hydrates the component as an interactive client-side island to fetch indices and filter entries instantly. |
Developer Notes & Accessibility
- Standard GET Fallback: When the
actionparameter is specified, the input wraps inside a semantic HTML<form method="get">element. If JavaScript fails to hydrate, standard keystroke submission queries are safely posted straight to the fallback action path for robust static compatibility. - Roving Dropdown Keyboard Controls: Fully supports intuitive accessibility keys:
- Arrow keys (
ArrowUp/ArrowDown) roam active focus sequentially through autocomplete dropdown items. - Pressing
Entertriggers immediate navigation to the highlighted item's target route (href). - Pressing
Escapecollapses the dropdown or clears the active search string.
- Arrow keys (
- Micro-Payload Client Filtering: Index documents point to pre-compiled static haystacks matching token structures. By separating content compiling to the build step (SSG), search execution is kept extremely lightweight with no live runtime APIs required.