Command palette

@yasinsensoy/web

Web · Components

Cascader

Cascading picker: leveled choices like province → district → neighbourhood or category → subcategory.

4 exports

Live example

Preview

Code

import { Cascader } from "@yasinsensoy/web";

<Cascader name="location" options={cities} loadChildren={ilceleriFetch} search clearable />

Events

  1. Events appear here when you interact with the preview.

Import

import { Cascader } from "@yasinsensoy/web";

Cascader

componentClient component

Cascading picker: leveled choices like province → district → neighbourhood or category → subcategory. On desktop columns open side by side; on mobile a single column advances level by level and "Back" returns.

  • Value: a path array (["istanbul", "kadikoy"]); "Istanbul / Kadıköy" in the box. By default only the last level is selectable; intermediate levels too with changeOnSelect.
  • Loading: hasChildren options are fetched with loadChildren when opened (e.g. districts from the server when a province is selected); a spinner shows in the row while loading, and "Try again" on error.
  • Search: search searches all paths, Turkish case-insensitive.
  • Keyboard: ↑/↓ move within a column, → or Enter opens the child column, ← returns to the parent column, Enter selects a leaf, Esc closes.
  • Form: with name the path is submitted as "istanbul/kadikoy"; required works.

For tree-shaped selection (multiple selection, search, drag) use TreeSelect.

Cascader(props: CascaderProps): JSX.Element

Examples

<Cascader name="location" placeholder="Province / district" options={provinces}
  loadChildren={(province, _path, signal) => fetchDistricts(province.value, signal)} />

<Cascader changeOnSelect search options={categories} onValueChange={(path) => setCategory(path)} />

An option inside a Cascader.

NameTypeDescription
valuestringUnique value at this level; the path is made of these values.
label?stringDisplay name. Defaults to value.
icon?IconPropIcon at the start of the name.
description?ReactNodeSmall description below the name.
children?readonly CascaderOption[]Child options.
hasChildren?booleanChild options aren't loaded yet but exist; requested with loadChildren when opened. false means it is a leaf.
disabled?booleanNot selectable.

Classes that can be given to the inner parts of Cascader.

NameTypeDescription
trigger?stringTrigger button.
content?stringThe open panel.
column?stringEach column.

CascaderProps

interface

Props of the Cascader component.

NameTypeDefaultDescription
optionsreadonly CascaderOption[]Option tree (e.g. province → district → neighbourhood). See CascaderOption.
value?readonly string[]Selected path in controlled use (["istanbul", "kadikoy"]); [] for none.
defaultValue?readonly string[]Initial path in uncontrolled use.
onValueChange?(path: string[], options: CascaderOption[]) => voidCalled with the path and the options along it when the selection changes ([] when cleared).
loadChildren?(option: CascaderOption, path: readonly CascaderOption[], signal: AbortSignal) => Promise<readonly CascaderOption[]>Fetches the children of a hasChildren option when it opens (e.g. districts when a province is selected). The result is cached; on error "Try again" appears.
changeOnSelect?booleanfalseCan intermediate levels be selected too? When true, "Istanbul" can also be selected on its own; a click selects it and opens the child column, and the panel stays open.
expandTrigger?"click" | "hover""click"Open the child column on hover ("hover") or on click?
search?booleanfalseSearch box: typing searches all paths ("kadı" → "Istanbul / Kadıköy"). Searches only loaded options.
separator?string" / "Separator of the path in the box.
renderValue?(options: CascaderOption[]) => ReactNodeHow the path appears in the box; names are joined with the separator when omitted.
placeholder?ReactNode"Seçiniz"Text shown when nothing is selected.
icon?IconPropIcon at the start of the box.
clearable?booleanfalse× button that clears the selection.
variant?FieldVariant | CustomVariant<"field">Appearance. See FieldVariant.
effect?EffectPropEffect or effects of the field box (e.g. "glow", ["lift", "beam"]). The accent color is the focus color (--ui-field-focus). Defaults to UIProvider appearance.defaults.field.effect. See BuiltinEffect.
name?stringForm field name. The path is joined with valueSeparator and submitted ("istanbul/kadikoy").
valueSeparator?string"/"Separator of the path in the form.
form?stringId of the form the field belongs to.
required?booleanThe form can't be submitted without a selection.
disabled?booleanDisabled.
id?stringId of the trigger button.
autoFocus?booleanFocused when the page opens.
open?booleanWhether the panel is open in controlled use.
defaultOpen?booleanfalseOpen initially in uncontrolled use?
onOpenChange?(open: boolean) => voidWhen the panel opens or closes.
tooltip?TooltipPropTooltip on hovering the box. See TooltipProp.
className?stringClasses added to the container.
classNames?CascaderClassNamesClasses added to the inner parts.
aria-label?stringScreen reader name.
aria-labelledby?stringId of the element naming the box.
aria-describedby?stringId of the element describing the box.
aria-invalid?boolean | "true" | "false"Show as invalid.