NavigationSearchClassic
Searchastronomic.dev# SearchClassic
The classic site search: a panel near the top of the screen, results under their type, a page's matching sections under it. Full screen on a phone.
Interactive: inline script.
## Usage
```astro
import SearchClassic from "@astronomic-dev/ui/components/SearchClassic.astro";
```
## Examples
### The kit's own search
Click either button, or press Cmd+K or Ctrl+K, and try "lightbx" or "navbar". The panel sits near the top, results under their type and a page's sections under it; each page shows a breadcrumb over its title; the active result has a soft fill and an accent edge. In a frame under 40rem wide it fills the screen.
```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
### SearchClassic
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `index` | `string` | None | The index this dialog 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. |
| `group` | `string \| false` | None | The grouping: "type", a facet's name, or false (mixed by score, each result's breadcrumb starting with its type). Default: the index's group setting. |
| `shortcut` | `false` | None | false turns the shortcut off for this dialog. Default: the site's `shortcut` setting, on the dialog of the page's main search button. |
| `strings` | `SearchStrings` | None | Words for this dialog over the site's `strings` setting, only the ones you pass (placeholder, close, seeAll and the rest, plus escKey, headingMark, crumbMark and typeText: the esc key cap, the # mark before a heading result, the › between breadcrumb parts and the Type label before the tabs). The site's words are the place for a translation. |
| `class` | `string` | None | More classes for the <dialog>, merged with cn(), so yours win on conflicts. |
Needs the search integration (search() from @astronomic-dev/search/astro in astro.config): it reads the manifest URL, the shortcut and the words from it. Render one per index, types and group you open, anywhere in the page. It is a closed <dialog> until a SearchButton with the same index, types and group is used, so it has no content of its own.
### 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.
SearchClassic
FreeThe classic site search: a panel near the top of the screen, results under their type, a page's matching sections under it. Full screen on a phone.
- File
- SearchClassic.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
Click either button, or press Cmd+K or Ctrl+K, and try "lightbx" or "navbar". The panel sits near the top, results under their type and a page's sections under it; each page shows a breadcrumb over its title; the active result has a soft fill and an accent edge. In a frame under 40rem wide it fills the screen.
This preview did not load.
main.astro
examples/searchclassic/main.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" />Minimal · Light