SearchDialog
Opens a modal site search with live status, keyboard navigation between results, and a retry after a failed request.
- Frameworks
- Astro · React · Elements · Dioxus
- Registry
lumen add SearchDialog- Interaction
- Enhanced runtime
See it and copy it
Framework example
Choose Astro, React, Elements, or Dioxus to compare native usage against the shared visual output. Each example assumes the framework-level setup is already complete.
View SearchDialog code
Framework usage
Switch targets to compare the adapter code. This live preview runs the Astro example. Before copying an example, complete the matching framework setup; React, Elements, and Dioxus use their own behavior APIs.Width controls resize the preview container. Resize your browser to test viewport breakpoints.---
import { SearchDialog, SearchDialogTrigger } from '@santi020k/lumen-astro'
---
{/* These docs already open their own search with Ctrl+K, so the example turns the shortcut off. */}
<SearchDialogTrigger fallbackHref="/docs/components" label="Search components" target="search-dialog-example" />
<SearchDialog id="search-dialog-example" labels={{ title: 'Search components' }} shortcut={false} />
<script>
import { bindLumenSearchDialog, type LumenSearchResult } from '@santi020k/lumen-astro/search-dialog'
// Illustrative only: query your search index or API, and pass signal to fetch so stale requests stop.
const pages: readonly LumenSearchResult[] = [
{ description: 'Modal content for a focused task.', href: '/docs/components/dialog', title: 'Dialog' },
{ description: 'Confirms a destructive action.', href: '/docs/components/alert-dialog', title: 'AlertDialog' },
{ description: 'A palette of actions people can filter.', href: '/docs/components/command', title: 'Command' },
{ description: 'Text entry that picks from a list.', href: '/docs/components/combobox', title: 'Combobox' },
{ description: 'A native search input for forms.', href: '/docs/components/search-field', title: 'SearchField' },
{ description: 'A side panel for secondary work.', href: '/docs/components/sheet', title: 'Sheet' }
]
bindLumenSearchDialog('search-dialog-example', query => {
const terms = query.toLowerCase()
return pages.filter(page => `${page.title} ${page.description ?? ''}`.toLowerCase().includes(terms))
})
</script>'use client'
import { SearchDialog, SearchDialogTrigger } from '@santi020k/lumen-react'
// Illustrative only: query your search index or API, and pass signal to fetch so stale requests stop.
const pages = [
{ description: 'Modal content for a focused task.', href: '/docs/components/dialog', title: 'Dialog' },
{ description: 'Confirms a destructive action.', href: '/docs/components/alert-dialog', title: 'AlertDialog' },
{ description: 'A palette of actions people can filter.', href: '/docs/components/command', title: 'Command' },
{ description: 'Text entry that picks from a list.', href: '/docs/components/combobox', title: 'Combobox' },
{ description: 'A native search input for forms.', href: '/docs/components/search-field', title: 'SearchField' },
{ description: 'A side panel for secondary work.', href: '/docs/components/sheet', title: 'Sheet' }
]
// Defined outside the component, so the provider stays the same between renders.
const searchComponents = (query: string) => {
const terms = query.toLowerCase()
return pages.filter(page => `${page.title} ${page.description}`.toLowerCase().includes(terms))
}
export const Example = () => (
<>
<SearchDialogTrigger fallbackHref="/docs/components" label="Search components" target="component-search" />
<SearchDialog id="component-search" labels={{ title: 'Search components' }} search={searchComponents} />
</>
)<script type="module">
import { defineLumenElements } from '@santi020k/lumen-elements/define'
defineLumenElements()
</script>
<lumen-search-dialog-trigger target="component-search"><a href="/docs/components">Search components</a></lumen-search-dialog-trigger>
<lumen-search-dialog id="component-search" title-label="Search components"></lumen-search-dialog>
<script type="module">
// Illustrative only: query your search index or API, and pass signal to fetch so stale requests stop.
const pages = [
{ description: 'Modal content for a focused task.', href: '/docs/components/dialog', title: 'Dialog' },
{ description: 'Confirms a destructive action.', href: '/docs/components/alert-dialog', title: 'AlertDialog' },
{ description: 'A palette of actions people can filter.', href: '/docs/components/command', title: 'Command' },
{ description: 'Text entry that picks from a list.', href: '/docs/components/combobox', title: 'Combobox' },
{ description: 'A native search input for forms.', href: '/docs/components/search-field', title: 'SearchField' },
{ description: 'A side panel for secondary work.', href: '/docs/components/sheet', title: 'Sheet' }
]
document.getElementById('component-search').search = query => {
const terms = query.toLowerCase()
return pages.filter(page => `${page.title} ${page.description}`.toLowerCase().includes(terms))
}
</script>use dioxus::prelude::*;
use lumen_dioxus::prelude::*;
#[component]
fn Example() -> Element {
let site_search = use_search_dialog();
rsx! {
SearchDialogTrigger { dialog: site_search, fallback_href: "/search", target: "site-search" }
SearchDialog {
dialog: site_search,
id: "site-search",
search: move |query: String| -> SearchDialogFuture {
Box::pin(async move {
let query = query.to_lowercase();
let pages = [("Getting started", "/docs/start"), ("Theming", "/docs/theming")];
let results: Vec<SearchResult> = pages
.into_iter()
.filter(|(title, _)| title.to_lowercase().contains(&query))
.map(|(title, href)| SearchResult::new(title, href))
.collect();
Ok(results)
})
},
}
}
}Framework differences
React: Pass the provider as search and keep it stable: define it outside the component or wrap it in useCallback, because a new function runs the open query again. React owns only the open state. Import from @santi020k/lumen-react or @santi020k/lumen-react/components/search-dialog.
Elements: Author an empty <lumen-search-dialog id="site-search">; it renders its own dialog, field, status, Retry search button, and result list, and gives the inner dialog the host id plus "-dialog". Set element.search to the provider, or call bindLumenSearchDialog with the host id.
Choose your target
Add this component
Choose the package for your runtime. All adapters share the Lumen stylesheet. Use the matching registry command when you want a local wrapper for that framework.
pnpm add @santi020k/lumen-astrolumen add SearchDialogpnpm add @santi020k/lumen-reactlumen add SearchDialog --target reactpnpm add @santi020k/lumen-elementslumen add SearchDialog --target elementsAPI reference
Lumen-specific props and runtime attributes for the Astro primitive. Use the framework differences above and the copyable examples for React composition and Elements attributes; the public adapter types define their supported contracts.
| Attribute | Values | Default | Description |
|---|---|---|---|
| id | string | required | Names the dialog. SearchDialogTrigger target and bindLumenSearchDialog use it, and the title and field ids derive from it. |
| search | (query: string, signal: AbortSignal) => LumenSearchResults | Promise<LumenSearchResults> | - | Returns the results for the trimmed query. Pass signal to fetch: a newer query, closing, or removing the dialog aborts it, and late responses are ignored. Throwing or rejecting shows the failure status with a Retry search button. Keep it stable in React, for example with useCallback. In Elements, set the search property. |
| bindLumenSearchDialog(id, search) | (id: string, search: LumenSearchProvider, root?: EventTarget) => () => void | - | Answers the ui:search-dialog-request events of the dialog with that id and returns a function that removes the listener. Call it before binding another provider for the same id. Import it from @santi020k/lumen-astro/search-dialog or @santi020k/lumen-elements/components/search-dialog. |
| LumenSearchResult | { href: string, title: string, description?: string } | - | One result link. Relative links resolve against the page. Only http and https links without credentials render, results without a title are skipped, and a later result with an href already listed is dropped. |
| labels | Partial<LumenSearchDialogLabels> | English defaults | Localizes title, field, close, loading, results, empty, failure, and retry. Keep the {count} placeholder in results ("Results found: {count}"). A blank label keeps its default. |
| title-label, field-label, close-label, loading-label, results-label, empty-label, failure-label, retry-label | string attributes | English defaults | Localize the same copy as labels in Astro and React. |
| shortcut | boolean | true | Opens the dialog with Ctrl+K or Command+K and shows the hint on its triggers. Set it to false when the page already uses the shortcut or has another SearchDialog. In Elements, set shortcut="false". |
| class, className | string | "" | Merges custom classes with the generated ui-* root classes. |
| ...native attributes | HTML attributes | - | Forwards standard attributes to the root element unless the component consumes them. |
Customize SearchDialog
Start with semantic theme tokens and a class on the public component. Keep its accessible name, focus treatment, and interaction state intact.
.product-search-dialog {
--surface: 0 0% 100%;
--ink: 220 20% 15%;
--line: 220 15% 82%;
}Apply product-search-dialog through Astro's class, React's className, or the custom element's class. Verify foreground and background contrast in both schemes.
| Hook | Values | Default | Contract |
|---|---|---|---|
| class, className | string | "" | Merges custom classes with the generated ui-* root classes. |
Use the documented hooks above and adapter types when targeting component states. Theme guide · Accessibility verification scope
Keyboard interactions
Keyboard behavior provided by the Astro UIPrimitives runtime for this component.
| Key | Action |
|---|---|
| Ctrl+K, Command+K | With shortcut on (the default), open the dialog unless focus is in a text field or another dialog is open. While it is open, move focus back to the search field. |
| Type in the search field | Search for the query. A newer query cancels the previous request. |
| ArrowDown, ArrowUp | From the field, focus the first or last result. On a result, focus the next or previous one, wrapping at the ends. |
| Enter in the field | Follow the first result. |
| Enter on a result | Follow the link and close the dialog. |
| Escape | Close the dialog and return focus to the trigger, or to where it was before the shortcut. |
Runtime events
CustomEvents dispatched by the Astro UIPrimitives runtime for this component.
| Event | Target | Detail | When |
|---|---|---|---|
| ui:search-dialog-request | SearchDialog dialog ([data-ui-search-dialog]) or lumen-search-dialog host | LumenSearchDialogRequestDetail: { query: string, signal: AbortSignal, respondWith(results: LumenSearchResults | Promise<LumenSearchResults>): void } | Cancelable. Bubbles for each query when the dialog has no search provider; bindLumenSearchDialog answers it for you. Call respondWith synchronously; only the first response counts. A newer query, closing, or removing the dialog aborts signal. Without a response the dialog shows the failure status; preventDefault leaves it idle. React and Elements can pass a search provider instead. |