NavigationSearchButton
Searchastronomic.dev# SearchButton
To open the search from a header or a page: an icon button, or a field with words and the shortcut. A real link to your search page without JavaScript.
Static: no JavaScript.
## Usage
```astro
import SearchButton from "@astronomic-dev/ui/components/SearchButton.astro";
```
## Examples
### Two looks
An icon button named Search, and openText="Search the kit": a field with the words and the shortcut's key hint. Both open the same SearchClassic dialog on the kit's own index. With JavaScript off each is a link to the search page.
```astro
---
import SearchButton from "@astronomic-dev/ui/components/SearchButton.astro";
import SearchClassic from "@astronomic-dev/ui/components/SearchClassic.astro";
---
<div class="flex flex-wrap items-center gap-3">
<SearchButton index="kit" main openText="Search the kit" class="w-64 max-w-full" />
<SearchButton index="kit" />
</div>
<SearchClassic index="kit" />
```
## Props
### SearchButton
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `index` | `string` | None | The index its dialog searches. Default: the site's default index. |
| `types` | `string[] \| string` | None | The types its dialog shows. Default: every type of the index. |
| `group` | `string \| false` | None | Its dialog's grouping. The button opens the Search dialog with the same index, types and group. |
| `href` | `string` | None | Where the link goes with no JavaScript, and where See all results goes. Default: /search under the base. |
| `main` | `boolean` | `false` | The page's main search button: the shortcut opens its dialog, focus returns to it, and a field-style button shows the key hint. Default: the first search button. |
| `label` | `string` | `"Search"` | The icon-only button's accessible name. Not used with `openText`, whose words name the button. |
| `openText` | `string` | None | Visible words, such as "Search the docs": the button draws as a field with the icon, the words and the shortcut's key hint (⌘K or Ctrl K, hidden from screen readers). |
| `tone` | `"page" \| "band"` | `"page"` | The surface it sits on: `page`, or `band`, an optional band such as the Navbar's bar, where it takes the band's colors. |
| `class` | `string` | None | More classes for the link, merged with cn(), so yours win on conflicts. |
A real <a href> to your search page. The Search shell's script makes it the button that opens the dialog, and loads the search on hover, focus or the first click.
## Accessibility
| Key | Action |
| --- | --- |
| Cmd+K or Ctrl+K | Opens the search from anywhere on the page, also from a text field (the site's shortcut setting) |
| / | Opens the search, except while you type in a text field, a text area or an editable area |
| Enter or Space | On a search button: opens the search |
| Up and Down arrows | Move the active result, wrapping at the ends. Focus stays in the search box |
| Enter | Opens the active result |
| Cmd+Enter or Ctrl+Enter | Opens the active result in a new tab |
| Escape | Clears the box; a second Escape closes the search and returns focus to the button that opened it |
| Tab and Shift+Tab | Move from the box to the selected type tab, the filters, the close button, then See all results; focus stays inside |
| Left and Right arrows, Home and End | On the type tabs: pick the previous, next, first or last type |
- It is a modal <dialog> named by the strings' dialogLabel (default "Search"). While it is open, the page behind cannot be reached and does not scroll.
- The search box is a combobox that controls the list of results (a listbox). The active result is marked with aria-activedescendant, so focus stays in the box while the arrows move.
- Results are grouped under their type, each group named by its label. A page's matching sections sit under it as their own results.
- One polite live region says the count ("12 results") once you stop typing, not on every key.
- No search runs while text is being composed with an input method, and Enter during composition opens nothing.
- 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.
- With no results it names your query, offers to search all types when a tab or a filter narrowed it, and shows your recent searches. If the index fails to load it says so, offers Try again and shows your browse links.
- Without JavaScript each search button is a plain link to your search page.
- The search loads on first use: hovering or focusing a search button, a click, or the shortcut. A click or the shortcut pressed while it loads is kept, then done.
- On a phone the panel fills the screen. Under reduced motion or the theme's calm setting it opens at once.
- With ClientRouter there is nothing to do: after a page change the new page's dialog and shortcut are used.
SearchButton
FreeTo open the search from a header or a page: an icon button, or a field with words and the shortcut. A real link to your search page without JavaScript.
- File
- SearchButton.astro
- Group
- Navigation
- Kind
- Static: no JavaScript
- Examples
- 1
Examples
Drag the orange handle to set the width. Frames get real breakpoints.
- Static
- Interactive
- Framed
Two looks
An icon button named Search, and openText="Search the kit": a field with the words and the shortcut's key hint. Both open the same SearchClassic dialog on the kit's own index. With JavaScript off each is a link to the search page.
Minimal · Light