FormsFilterRange
Searchastronomic.dev# FilterRange
For a range filter, such as a price with Min and Max, or beds with "3+".
Interactive: inline script.
## Usage
```astro
import FilterRange from "@astronomic-dev/ui/components/FilterRange.astro";
```
## Examples
### Price and beds
A price with Min and Max from the mode's steps, and beds with one "at least" select (bound "min").
```astro
---
import FilterRange from "@astronomic-dev/ui/components/FilterRange.astro";
import { fields } from "../_data/vega.ts";
const price = fields.find((field) => field.key === "price")!;
const beds = fields.find((field) => field.key === "beds")!;
---
<div class="grid max-w-md gap-5">
<FilterRange field={price} mode="buy" value={[750000, 1250000]} />
<FilterRange field={beds} mode="buy" value={[3, null]} />
</div>
```
### Dropdown
With dropdown: a Popover with Min and Max radio lists, and beds as one Select with picker, which closes on pick. The trigger says what is picked, as the server draws it.
```astro
---
import FilterRange from "@astronomic-dev/ui/components/FilterRange.astro";
import { fields } from "../_data/vega.ts";
const price = fields.find((field) => field.key === "price")!;
const beds = fields.find((field) => field.key === "beds")!;
---
<div class="grid max-w-md gap-5">
<FilterRange dropdown field={price} mode="buy" value={[750000, 1250000]} />
<FilterRange dropdown field={beds} mode="buy" value={[3, null]} />
</div>
```
## Props
### FilterRange
| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `field` | `ListingField` | None | A range field (kind "range") from your fields list: its steps, format and bound. |
| `mode` | `string` | `""` | The mode whose steps and label show ("Price" or "Rent"). |
| `value` | `[number \| null, number \| null]` | `[null, null]` | The picked range. A value that is not a step is added as an option. |
| `anyText` | `string` | `FILTERS_TEXTS.anyText` | A minimum-only field's empty option ("Any"). |
| `minText` | `string` | `FILTERS_TEXTS.minText` | Min's empty option ("No min"). |
| `maxText` | `string` | `FILTERS_TEXTS.maxText` | Max's empty option ("No max"). |
| `minLabel` | `string` | `"Min"` | The Min select's name for screen readers, after the legend. |
| `maxLabel` | `string` | `"Max"` | The Max select's name for screen readers, after the legend. |
| `dropdown` | `boolean` | `false` | Draws the field as a Popover with Min and Max radio lists; with bound "min", as one Select with picker. Same names (price-min, price-max) and values. |
| `rangeText` | `string` | `"{min} to {max}"` | With dropdown: the words for both ends. |
| `fromText` | `string` | `"{min}+"` | With dropdown: the words for a minimum only. |
| `upToText` | `string` | `"Up to {max}"` | With dropdown: the words for a maximum only. |
| `disabled` | `boolean` | `false` | The field's controls can't be used and do not submit. With dropdown, the trigger too. |
| `id` | `string` | None | The Min select's id; Max adds "-max". With dropdown, the trigger's id. Default: a page-unique id. |
| `class` | `string` | None | More classes for the <fieldset>, merged with cn(). |
Any other attribute goes on the <fieldset>. Filters renders one per range field.
## Accessibility
| Key | Action |
| --- | --- |
| Enter or Space | With dropdown, on the trigger: opens and closes the panel |
| Up and Down arrows | With dropdown, in a radio list: move and pick, as native radios do |
| Escape | With dropdown: closes the panel and returns focus to the trigger |
- A fieldset whose legend is the field's label for the mode; each native select has its own label ("Min", "Max"), so a screen reader says "Price, Min".
- With dropdown and bound "min", one select named by the field's label ("Beds").
- With dropdown the trigger is a button named by the label and the words ("Price $750K to $1.25M"), and each radio list a group named Min or Max. A Max at or below the Min is ruled out.
- Sale prices read short ("$750K"), rents whole ("$2,500"). In Filters, the options and the legend change with the mode.
FilterRange
FreeFor a range filter, such as a price with Min and Max, or beds with "3+".
- File
- FilterRange.astro
- Group
- Forms
- Kind
- Interactive: inline script
- Examples
- 2
Examples
Drag the orange handle to set the width. Frames get real breakpoints.
- Static
- Interactive
- Framed
Price and beds
A price with Min and Max from the mode's steps, and beds with one "at least" select (bound "min").
Force statemain.astro
examples/filterrange/main.astro
---
import FilterRange from "@astronomic-dev/ui/components/FilterRange.astro";
import { fields } from "../_data/vega.ts";
const price = fields.find((field) => field.key === "price")!;
const beds = fields.find((field) => field.key === "beds")!;
---
<div class="grid max-w-md gap-5">
<FilterRange field={price} mode="buy" value={[750000, 1250000]} />
<FilterRange field={beds} mode="buy" value={[3, null]} />
</div>Dropdown
With dropdown: a Popover with Min and Max radio lists, and beds as one Select with picker, which closes on pick. The trigger says what is picked, as the server draws it.
This preview did not load.
dropdown.astro
examples/filterrange/dropdown.astro
---
import FilterRange from "@astronomic-dev/ui/components/FilterRange.astro";
import { fields } from "../_data/vega.ts";
const price = fields.find((field) => field.key === "price")!;
const beds = fields.find((field) => field.key === "beds")!;
---
<div class="grid max-w-md gap-5">
<FilterRange dropdown field={price} mode="buy" value={[750000, 1250000]} />
<FilterRange dropdown field={beds} mode="buy" value={[3, null]} />
</div>Minimal · Light