NavigationSearchPage
Searchastronomic.dev# SearchPage
For your /search page: a search box, type tabs, filters with counts and every result as a link with its matching sections, the query kept in the address bar.
Interactive: inline script.
## Usage
```astro
import SearchPage from "@astronomic-dev/ui/components/SearchPage.astro";
```
## Examples
### The kit's own search page
Type "lightbx" or "navbar": results come as you type, all of them, 20 at a time. Each page shows its snippet and its matching sections. The tabs pick a type; the address bar keeps the query on your own /search page.
```astro
---
import SearchPage from "@astronomic-dev/ui/components/SearchPage.astro";
---
<div>
<SearchPage index="kit" />
</div>
```
## Props
### SearchPage
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `index` | `string` | None | The index this page searches, one of the search integration's indexes. Default: the site's default index. |
| `types` | `string[] \| string` | None | The types it shows, as a list or a comma list: its tabs and its results. Default: every type of the index. |
| `headingTag` | `"h2" \| "h3" \| "h4"` | `"h2"` | The results' title level. With results grouped (the index's group.page setting), the group's type is at this level and the titles one below. |
| `strings` | `SearchPageStrings` | None | Words for this page over the site's `strings` setting, only the ones you pass, and the page's own: label (the box's hidden label), submit, showMore and moreShown ("Result {position} of {total}: {title}"). |
| `class` | `string` | None | More classes for the <search> element, merged with cn(), so yours win on conflicts. |
| `formClass` | `string` | None | More classes for the form: the search box and its button in a row. |
| `listClass` | `string` | None | More classes for the box that holds the results (a list, or a section per group). |
Needs the search integration (search() from @astronomic-dev/search/astro in astro.config): it reads the manifest URL, the words and the browse links from it. Put it on your /search page; the form submits there (under the base). The search loads at once when the address has a query, else on hover, focus or typing.
## Accessibility
| Key | Action |
| --- | --- |
| Enter | In the search box: searches, and adds the search to the browser's history, so Back returns to it |
| Left and Right arrows, Home and End | On the type tabs: pick the previous, next, first or last type |
| Enter or Space | On a filter: turns it on or off. On Show more results: shows the next 20; focus stays on the button |
- It is a <search> landmark around a form with a labeled search box (type="search") and a Search button. Your page gives it a heading, such as an h1 "Search".
- Results are a list of links: each page's title, its snippet with the matched words marked, and its matching sections as links under it. Titles are h2 by default (headingTag); with results grouped under their type, the type is the heading and the titles are one level below.
- The type tabs follow the tabs pattern: one Tab stop on the selected tab, the arrows to switch. The filters are toggle buttons (aria-pressed) with their counts.
- One polite live region says the count ("12 results") once you stop typing, not on every key. After Show more results it reads the first new result and the count.
- No search runs while text is being composed with an input method.
- The query, the type and the filters are in the address bar (?q=dark+mode&type=docs&theme=vega), so a search can be shared, reloaded and reached with Back.
- With no results it names your query and offers to search all types when a tab or a filter narrowed it. If the index fails to load it says so, offers Try again and shows your browse links.
- Without JavaScript the form still submits (?q=), and your browse links show, since the results need JavaScript.
SearchPage
FreeFor your /search page: a search box, type tabs, filters with counts and every result as a link with its matching sections, the query kept in the address bar.
- File
- SearchPage.astro
- Group
- Navigation
- Kind
- Interactive: inline script
- Examples
- 1
Examples
Drag the orange handle to set the width. Frames get real breakpoints.
- Static
- Interactive
- Framed
The kit's own search page
Type "lightbx" or "navbar": results come as you type, all of them, 20 at a time. Each page shows its snippet and its matching sections. The tabs pick a type; the address bar keeps the query on your own /search page.
examples/searchpage/main.astro
---
import SearchPage from "@astronomic-dev/ui/components/SearchPage.astro";
---
<div>
<SearchPage index="kit" />
</div>Minimal · Light