FormsFilterSwitch
Searchastronomic.dev# FilterSwitch
For a two-part switch between modes, such as Buy and Rent, at the start of the filters.
Static: no JavaScript.
## Usage
```astro
import FilterSwitch from "@astronomic-dev/ui/components/FilterSwitch.astro";
```
## Examples
### Buy or rent
Two native radios on one track. Click, or Tab to it and use the arrow keys.
```astro
---
import FilterSwitch from "@astronomic-dev/ui/components/FilterSwitch.astro";
import { modes } from "../_data/vega.ts";
---
<FilterSwitch modes={modes} label="Buy or rent" value="buy" name="example-mode" />
```
## Props
### FilterSwitch
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `modes` | `{ value: string; label: string }[]` | None | Two to four modes, such as Buy and Rent. |
| `label` | `string` | None | The switch's name, read before its options ("Buy or rent"); a visually hidden legend. |
| `value` | `string` | None | The checked mode. Default: the first. |
| `name` | `string` | `"mode"` | The radios' name. Keep "mode" inside Filters: its script reads it. |
| `class` | `string` | None | More classes for the <fieldset>, merged with cn(). |
Any other attribute goes on the <fieldset>. Filters renders it from modes and modesLabel.
## Accessibility
| Key | Action |
| --- | --- |
| Tab | Moves to the checked option; one Tab stop for the switch |
| Left and Right arrows | Check the previous or next option |
- A fieldset of native radios: a screen reader says the legend, then "Buy, radio button, checked, 1 of 2".
- The checked option sits on the accent thumb in the accent's text color; the focus ring is on the option.
- Each option is at least 44px tall on a touch screen. The thumb slides only when motion is allowed.
FilterSwitch
FreeFor a two-part switch between modes, such as Buy and Rent, at the start of the filters.
- File
- FilterSwitch.astro
- Group
- Forms
- Kind
- Static: no JavaScript
- Examples
- 1
Examples
Drag the orange handle to set the width. Frames get real breakpoints.
- Static
- Interactive
- Framed
Buy or rent
Two native radios on one track. Click, or Tab to it and use the arrow keys.
Force statemain.astro
examples/filterswitch/main.astro
---
import FilterSwitch from "@astronomic-dev/ui/components/FilterSwitch.astro";
import { modes } from "../_data/vega.ts";
---
<FilterSwitch modes={modes} label="Buy or rent" value="buy" name="example-mode" />Minimal · Light