Cascading Select
shadcn-htmx/cascading-selectFreeComponent
Two dependent native <select>s: choosing the parent reloads the child's <option>s — and an optional detail panel — from the server via an hx-swap-oob fragment. Cascade rides htmx's default `change` trigger on <select>; zero custom JS.
Live preview
live · rendered by the registry
Rendered by shadcn-htmx on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://shadcn-htmx.productdevbook.com/r/cascading-select.jsonSource
1/** @jsxImportSource hono/jsx */2import type { Child, PropsWithChildren } from "hono/jsx"3import { cn, type ClassValue } from "@/registry/lib/cn"45// Cascading Select — shadcn-htmx, htmx v4 + Tailwind v4.6//7// A pair of dependent native <select>s: picking the parent (e.g. car make)8// reloads the child's <option>s (e.g. model) — and, optionally, a detail9// panel — from the server. One request, two updates: the response swaps the10// child options into the target, and a second fragment carrying11// hx-swap-oob updates the detail panel "out of band".12//13// Built on:14// repos/htmx/www/src/content/patterns/02-forms/04-linked-selects.md15// The canonical linked-selects recipe: parent <select hx-get hx-target>16// swaps a fresh <option> list into the child; a detail card rides along.17// repos/htmx/www/src/content/reference/01-attributes/06-hx-trigger.md:32-3718// htmx defaults the trigger to `change` for <select>, so NO hx-trigger is19// needed — choosing an option fires the request.20// repos/htmx/www/src/content/reference/01-attributes/13-hx-swap-oob.md21// hx-swap-oob="true" on the detail fragment swaps it into #<id>-detail by22// id, piggybacking a second update onto the same response.23// repos/htmx/www/src/content/reference/01-attributes/07-hx-swap.md24// default swap is innerHTML — the returned <option>s replace the child's25// contents; hx-include carries the parent value with the request.26//27// Native semantics (the whole control is two real <select>s in a <fieldset>):28// repos/mdn/files/en-us/web/html/reference/elements/select/index.md29// repos/mdn/files/en-us/web/html/reference/elements/option/index.md30// repos/mdn/files/en-us/web/html/reference/elements/fieldset/index.md31// The <fieldset> + <legend> groups the related controls for AT. Each32// <select> brings keyboard control, type-to-search, mobile pickers, and33// form submission with zero JS. With htmx off the parent still submits34// its value in a normal form post — progressive enhancement, not emulation.35//36// JS budget: NONE. The cascade is htmx's default `change` trigger + an OOB37// swap; there is no site.js for this component.38//39// Style analogues: registry/ui/select.tsx (the chevron-overlaid native40// <select>, classes mirrored verbatim) and registry/ui/edit-in-place.tsx41// (server-fragment composite returning bare <option>/<div> partials).4243// Mirrors registry/ui/select.tsx `triggerBase` verbatim so a cascading44// … truncated
More from shadcn-htmx
All 83 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | shadcn-htmx | Components | Free | no deps | |
| Active Searchactive-search | shadcn-htmx | Components | Free | no deps | |
| Alertalert | shadcn-htmx | Components | Free | no deps | |
| Alert Dialogalert-dialog | shadcn-htmx | Components | Free | no deps | |
| Aspect Ratioaspect-ratio | shadcn-htmx | Components | Free | no deps | |
| Auto Gridauto-grid | shadcn-htmx | Components | Free | no deps | |
| Autocompleteautocomplete | shadcn-htmx | Components | Free | no deps | |
| Autosize Textareaautosize-textarea | shadcn-htmx | Components | Free | no deps |
