Skip to main content
239

Search Lumen

Find components, APIs, guides, and recipes.

GitHub
Themes
Web docs
Overlays

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
01

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.

AstroCode target · live preview uses Astro
Search components

Search components

    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.
    astro
    ---
    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>
    Edit SearchDialog in browser

    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.

    02

    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.

    bash@santi020k/lumen-astro
    pnpm add @santi020k/lumen-astro
    bashAstro wrapper
    lumen add SearchDialog

    API 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.

    AttributeValuesDefaultDescription
    idstringrequiredNames 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.
    labelsPartial<LumenSearchDialogLabels>English defaultsLocalizes 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-labelstring attributesEnglish defaultsLocalize the same copy as labels in Astro and React.
    shortcutbooleantrueOpens 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, classNamestring""Merges custom classes with the generated ui-* root classes.
    ...native attributesHTML 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.

    cssScoped theme overrides
    .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.

    HookValuesDefaultContract
    class, classNamestring""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.

    KeyAction
    Ctrl+K, Command+KWith 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 fieldSearch for the query. A newer query cancels the previous request.
    ArrowDown, ArrowUpFrom the field, focus the first or last result. On a result, focus the next or previous one, wrapping at the ends.
    Enter in the fieldFollow the first result.
    Enter on a resultFollow the link and close the dialog.
    EscapeClose 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.

    EventTargetDetailWhen
    ui:search-dialog-requestSearchDialog dialog ([data-ui-search-dialog]) or lumen-search-dialog hostLumenSearchDialogRequestDetail: { 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.

    Web docsFull catalog