NavigationSearch
Searchastronomic.dev# Search
To build your own search dialog: the search box, type tabs, filters and grouped results over the page, on the search package's index. For a ready layout, use SearchClassic.
Interactive: inline script.
## Usage
```astro
import Search from "@astronomic-dev/ui/components/Search.astro";
```
## Examples
### The shell
Both button looks and the shell with no recipe classes: the panel fills the screen, the box and close at the top, the results, then the key hints and See all results. It searches this kit's own index: try "lightbx". SearchClassic is a recipe built on it.
```astro
---
import SearchButton from "@astronomic-dev/ui/components/SearchButton.astro";
import Search from "@astronomic-dev/ui/components/Search.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>
<Search index="kit" />
```
## Props
### Search
| 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. |
| `panelClass` | `string` | None | For recipes. Classes for the visible panel. The dialog fills the screen and is the search container, so the panel's layout reads it (@min-[40rem]/search:). |
| `headerClass` | `string` | None | For recipes. Classes for the header row around the search box. |
| `inputClass` | `string` | None | For recipes. Classes for the search box. |
| `tabsClass` | `string` | None | For recipes. Classes for the row of type tabs. |
| `facetsClass` | `string` | None | For recipes. Classes for the filter rows, one per facet. |
| `bodyClass` | `string` | None | For recipes. Classes for the row around the results and the preview pane. |
| `resultsClass` | `string` | None | For recipes. Classes for the list of results. |
| `groupClass` | `string` | None | For recipes. Classes for one group of results. |
| `groupLabelClass` | `string` | None | For recipes. Classes for a group's label row (its name and its count). |
| `optionClass` | `string` | None | For recipes. Classes for a page result. The active one has aria-selected="true" (aria-selected:). |
| `headingOptionClass` | `string` | None | For recipes. Classes for a section result, under its page. |
| `snippetClass` | `string` | None | For recipes. Classes for a result's snippet. |
| `previewClass` | `string` | None | For recipes. Classes for the preview pane beside the results, drawn only with a `preview` slot. |
| `footerClass` | `string` | None | For recipes. Classes for the footer with the key hints and See all results. |
| Slot | Description |
| --- | --- |
| `preview` | A pane beside the results, for a recipe that shows the active result (empty in SearchClassic). |
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.
## 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.
Search
FreeTo build your own search dialog: the search box, type tabs, filters and grouped results over the page, on the search package's index. For a ready layout, use SearchClassic.
- File
- Search.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 shell
Both button looks and the shell with no recipe classes: the panel fills the screen, the box and close at the top, the results, then the key hints and See all results. It searches this kit's own index: try "lightbx". SearchClassic is a recipe built on it.
This preview did not load.
main.astro
examples/search/main.astro
---
import SearchButton from "@astronomic-dev/ui/components/SearchButton.astro";
import Search from "@astronomic-dev/ui/components/Search.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>
<Search index="kit" />Minimal · Light