Skip to content

Search

Search across a site, in a dialog, from a small index of pages. No service and no library: it runs in the browser.

import Search from '@sypnia/ui/astro/Search.astro'

On this page
  1. Search four pages
  2. When to use it
  3. For everyone

Search four pages

Every word must match, in any order; titles weigh most; accents do not matter. The arrow keys choose and Enter goes.

    Search pages, sections and terms

    Code
    ---
    // Press the button, Ctrl K or «/». This one searches four entries given inline; a site passes `index="/search.json"`.
    import Search from '@sypnia/ui/astro/Search.astro';
    import Button from '@sypnia/ui/astro/Button.astro';
    const entries = [
      { title: 'Quickstart', url: '#quickstart', group: 'Get started', text: 'Install the SDK and make your first table.' },
      { title: 'Import a CSV', url: '#csv', group: 'Guides', text: 'Upload a file, map the columns, preview.' },
      { title: 'Tokens', url: '#tokens', group: 'Reference', text: 'Make, rotate and revoke API tokens.' },
      { title: 'Configuración', url: '#config', group: 'Guías', text: 'Found by «configuracion» too: accents do not matter.' },
    ];
    ---
    <Button icon="search" data-search-open="example-search">Search the example</Button>
    <Search entries={entries} id="example-search" />

    When to use it

    Use it when

    • A docs site or a gallery of up to a few thousand pages.
    • People know the word they want and should not have to browse.

    Do not use it when

    • Searching a person's data in an app: that is the CommandPalette or a SearchInput over the data.

    For everyone

    • The field is a combobox and the results a listbox; the chosen result is announced as you move.
    • It opens with Ctrl K, ⌘ K or «/», and Escape closes it (a native dialog).
    • When nothing matches it says so, and suggests fewer words.
    1. Search four pages
    2. When to use it
    3. For everyone

      Search pages, sections and terms