Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

site-search

Site search component powered by Pagefind for fast, client-side full-text search.

Overview

The <site-search> component opens a native modal <dialog> with a search combobox, keyboard navigation and highlighted excerpts. It uses Pagefind for indexing and searching your static site content.

Keyboard Shortcuts

The search component supports the following keyboard shortcuts:

Shortcut Action
Cmd + K / Ctrl + K Open/close search. Bound once for the page: it opens the first visible <site-search>, so a page may hold several (e.g. desktop header and mobile menu)
Escape Close search
Arrow Up / Arrow Down Navigate results
Enter Go to the selected result, or the first result when none is selected

Trigger Variants

Text Button

Icon-Only Button

With Keyboard Hint

Configuration

Subpath deploys

The component imports pagefind.js from /pagefind/ by default. When the site is served from a subpath, point data-pagefind-path at the index directory. Result URLs get the directory above it as Pagefind’s baseUrl; set data-base-url to override that.

Labels

Search is one way into a site; an index, a glossary and a sitemap are others, and they help most when a visitor doesn't know the word to type. Put links to them in a <nav data-browse> child and the dialog shows them under a “Browse instead” heading while there are no results: before a query, and when a query finds nothing. The nav never shows in the page itself. Its aria-label, if you set one, becomes the heading.

The key cap beside the input is a button: it closes the dialog, as Escape does. Below 37.5rem the dialog is a full-width sheet from the top edge, the key cap becomes a touch-sized close button, and the keyboard hints in the footer are dropped.

Every UI string has a data-label-* override, including the result count ({count} is replaced; when the index matches more than the eight results listed, data-label-count-more also gets {total}, as in “8 of 23 results”) and the status shown when the index is missing. Developers get a console hint (“run npm run search:index”); visitors only see “Search unavailable”.

Attributes

AttributeValuesDefaultDescription
open (reflected)boolean—Reflected state — set by open()/close() methods, not intended as initial markup
data-pagefind-pathstring/pagefind/Directory that holds pagefind.js, resolved against the document base. Set it for subpath deploys (e.g. /my-site/pagefind/).
data-base-urlstring—Pagefind baseUrl prefixed to result URLs. Default: the directory above data-pagefind-path ("/" for the default path).
data-label-triggerstringSearchAccessible name of the generated icon trigger (only when no trigger button is authored)
data-label-dialogstringSite searchAccessible name of the search dialog
data-label-placeholderstringSearch documentation...Input placeholder
data-label-inputstringSearchAccessible name of the search input
data-label-resultsstringSearch resultsAccessible name of the results listbox
data-label-searchingstringSearching...Status text while a search runs
data-label-emptystringNo results foundStatus text when a query matches nothing
data-label-countstring{count} resultsStatus text for several results ({count} is replaced)
data-label-count-onestring1 resultStatus text for exactly one result
data-label-count-morestring{count} of {total} resultsStatus text when the index matched more results than the list shows ({count} listed, {total} matched)
data-label-unavailablestringSearch unavailableStatus text when the Pagefind index cannot be loaded (the developer hint goes to the console)
data-label-errorstringSearch error. Please try again.Status text when a search throws
data-label-untitledstringUntitledTitle shown for a result without meta.title
data-label-navigatestringto navigateFooter hint after the arrow keys
data-label-selectstringto selectFooter hint after Enter
data-label-closestringto closeFooter hint after Esc
data-label-dismissstringClose searchAccessible name of the close button beside the input (the Esc key cap; an × on narrow screens)
data-label-browsestringBrowse insteadHeading and accessible name of the browse links when the authored <nav data-browse> has no aria-label
data-label-poweredstringPowered byFooter credit prefix

Required Structure

ElementRequiredDescription
<button data-trigger>yesButton that opens the search dialog (generated with a search icon when absent)
<nav data-browse>yesOptional author-supplied links to other ways into the content (an index, a glossary, a sitemap). Shown in the dialog while there are no results; never shown in the page. Its aria-label, if set, is the heading.

Child Attributes

AttributeOnValuesDescription
data-triggerbuttonbooleanMarks the button that opens the search dialog. Falls back to first <button> if absent.

Events

EventDetailDescription
site-search:open—Fired when the search dialog opens
site-search:close—Fired when the search dialog closes (Escape, backdrop click, close(), or choosing a result)
site-search:change{ value, source: 'api' }Fired when the value property sets a new query

JavaScript API

MemberDescription
open()Open the dialog and focus the input
close()Close the dialog, clear the query and return focus to the trigger
isOpenRead-only: whether the dialog is open
valueThe current query; setting it runs a search and fires site-search:change
resultsRead-only copy of the current Pagefind result records
:state(input-debounce-pending)A keystroke is waiting out the 150 ms debounce

Pagefind Setup

The search component requires Pagefind to index your site content. Follow these steps to set up Pagefind:

1. Install Pagefind

2. Add Build Script

Add a script to run Pagefind after your site builds:

3. Mark Content Areas

Add data-pagefind-body to your main content areas to index them:

4. Exclude Navigation

Navigation and chrome are automatically excluded. You can also explicitly exclude elements:

5. Configuration (Optional)

Create a pagefind.yml for advanced configuration:

Accessibility

  • The search panel is a native <dialog> opened with showModal(): it sits in the top layer and the rest of the page is inert, so focus cannot leave it for the page behind
  • Escape closes the dialog and returns focus to the trigger
  • The input is a role="combobox" with aria-controls, aria-expanded and aria-activedescendant; the results are a role="listbox" that holds only role="option" links
  • A separate role="status" region announces “Searching…”, the result count, “No results found” and errors
  • Results are real links: Cmd/Ctrl-click and middle-click open them in a new tab
  • Result titles render as text and excerpts keep only Pagefind’s <mark> highlights; result URLs must be same-origin http(s)
↑