Search

A search box for the whole site.

When to use it

A search box for the whole site, in the header or on its own page, for sites with many pages.

When not to

Small sites, where a menu is quicker.

Accessibility

A search landmark with a labelled field; results are announced as they change and are links. It searches an index made at build time, so it needs no server.

See it live

The component library shows this component in the default theme, in every variant: open it in the component library

The search example as the component library shows it in the default theme

Fields

What the component’s dialog asks for. In a Doc, keyed rows start with the key; rows in order follow the order below. One row, its cells in the order of the fields.

Field

Key

Kind

Required

Placeholder text

placeholder

Plain text, one line

No

Variants

This component has no variants of its own; a theme can add some.

In Google Docs

A component is a table. Its first cell names it; the rows below hold its fields. This is the example table:

search

Search trips

In a page file

In a site kept as a folder or in Git, the same component is a block of the page’s JSON file:

JSON
{
  "name": "search",
  "rows": [
    [
      "Search trips"
    ]
  ]
}

Markup and classes

What the component writes takes these classes, for a theme’s CSS: the component’s own name, name__part for its parts and name--variant for each variant (the variant’s plain name is there too).

Class

What it marks

search

The component

search__form

A part of it

search__results

A part of it

search__status

A part of it

search__summary

A part of it

The HTML the example above writes, as the component library builds it in the default theme:

html
<div class="search" data-messages="{&quot;results&quot;:{&quot;one&quot;:&quot;{count} result&quot;,&quot;other&quot;:&quot;{count} results&quot;},&quot;noResults&quot;:&quot;Nothing found for \&quot;{query}\&quot;.&quot;,&quot;loadError&quot;:&quot;Search could not be loaded.&quot;}" data-index="/search-index.json">
  <form class="search__form" role="search" method="get">
    <label class="visually-hidden" for="q">Search trips</label>
    <input type="search" id="q" name="q" placeholder="Search trips" autocomplete="off">
    <button type="submit" class="button">Search</button>
  </form>
  <p class="search__status" role="status" aria-live="polite"></p>
  <ul class="search__results"></ul>
</div>

Visitor texts

Texts it shows visitors, in the page’s language. Every one is in the visitor texts reference.

Key

Text

site.search.label

Search the site

site.search.placeholder

Search the site

site.search.submit

Search

site.search.results

one: {count} result; other: {count} results

site.search.noResults

Nothing found for "{query}".

site.search.loadError

Search could not be loaded.

Extending it

Its files in SeedPage. A theme or a site changes the markup by giving a file of the same name (the Liquid part), and a new component can extend this one.

  • src/components/search.js
  • src/components/search/search.liquid
  • src/components/search.client.js

It has a browser script, the .client.js file above. Without it the component still shows all its content; the script only adds behaviour.