Cascader / CascaderPanel
Selecting related paths by level in a popup and a separate panel.
When to use
Cascader selects a region, directory partition, or other path in the associated data. The levels are revealed by adjacent columns: the user sees how the end point is connected to the parent ones. For a tree with individual node selection, use TreeSelect.
CascaderPanel shows speakers constantly. It shares the same value format with Cascader, but does not have an input field, search field, or drop-down popup.
Path model
In Svelte CascaderPath is an array of string or numeric keys from the root to the selected item. With multiple, the value becomes an array of such paths. label are used for display purposes; store value keys in the model.
| Problem | Setting | Example |
|---|---|---|
| Select destination | options, value, onChange |
Basic selection |
| Allow incomplete path | changeOnSelect |
Choosing an intermediate level |
| Select multiple branches | multiple |
Multiple paths |
| Get parent or destination paths | showCheckedStrategy |
Marked Path Strategy |
| Use your own data structure | fieldNames |
Custom field names |
For controlled selection, pass value and assign the result of onChange to your state. Clearing single reports undefined, multiple reports an empty array. In the basic example, next ?? [] stores a single local state type. defaultValue specifies only the initial local selection; for subsequent reset, update value.
With multiple, the SHOW_PARENT strategy collapses the entire marked branch into the parent path, and SHOW_CHILD leaves the final paths. Choose a strategy based on the application data format. disabled prohibits item selection; disableCheckbox specifically disables its checkbox.
Search and download
In the multiple paths example, components.input replaces the search editor. Pass attributes to the native field and attach register. Typing a separator from tokenSeparators clears the search text.
The search takes place along already known full paths. The showSearch object contains filter, sort, render, limit, searchValue and onSearch. To customize the result, use Svelte snippet render; it receives query, path, resolved Cascader prefix and fieldNames. Filtering and sorting remain normal functions. Search example searches for signatures of all levels.
For a lazy branch, set isLeaf=false and process loadData. In this API, the handler notifies the expansion: the returned Promise does not specify the end of the download. After the answer, update options by adding children or changing isLeaf. The application organizes the error and the possibility of re-request; download example also clears its timer when leaving the page.
loadData is not compatible with showSearch. To search for data that has not yet been loaded, obtain a tree in advance or do a separate applied search and transmit the found paths along with their variants.
Signatures, popup and form
displayRender renders the selected path; optionRender gets the option and context with path, searchValue and originNode. Render the originNode if you want to keep the default search highlighting. These parameters accept Svelte snippets; example of your signatures shows their signatures.
In popupRender, save the original menu snippet so that the selection and keyboard remain. Your trigger receives handlers and ARIA attributes via children: pass them to the real button. GetPopupContainer sets the panel container, placement — the opening side; the local container takes precedence over the ConfigProvider.
ConfigProvider.popupOverflow sets the overflow calculation region: the viewport or the scroll document region. The shared example demonstrates inheritance and an explicit viewport. The mode preserves the DOM container, selected path and search; coordinates update on the next opening, resize or scroll. The popup uses a fixed native popover; CascaderPanel does not use this setting.
In multiple tagRender gets the rendered tag data. Its value is the tag's encoded key, not a path array; change the model via onChange, delete via the passed onClose. The summary tag isMaxTag does not have a regular delete handler.
Cascader and Panel CSS prefixes show local prefixCls and global ConfigProvider.prefixCls. Without a local value, the field uses the general -select, columns and Panel use the general -cascader. A non-empty local prefixCls specifies the full name of both parts; an empty string returns inheritance. The row, checkbox, tag and popup classes follow these names, theme variables are set independently via theme.cssVar.prefix. Changing the prefix preserves paths, search input, caret, and focus. In Svelte, the popup saves padding:0, and the Panel gets the provider dir; Low-level differences with React do not require additional CSS rules in the application.
In shape of the region value is read from form.values and onChange calls form.setFieldValue with a path or an empty array. The mandatory rule checks the selection, reset restores the initialValues. Give the field a label or aria-label; arrows move focus through the menu, Enter selects, Escape closes the popup.
Cascader uses design tokens from the current theme for its appearance.
Examples
Basic selection
A connected path of three levels. value/onChange store an array of keys; clearing single transmits undefined.
<script lang="ts">
import { Cascader, type CascaderOption, type CascaderPath } from '@woodger/antd';
const options: CascaderOption[] = [
{ value: 'zhejiang', label: 'Zhejiang', children: [
{ value: 'hangzhou', label: 'Hangzhou', children: [
{ value: 'xihu', label: 'West Lake' }, { value: 'yuhang', label: 'Yuhang' }
] }
] },
{ value: 'jiangsu', label: 'Jiangsu', children: [
{ value: 'nanjing', label: 'Nanjing', children: [
{ value: 'zhonghuamen', label: 'Zhong Hua Men' }
] }
] }
];
let value = $state<CascaderPath>([]);
</script>
<Cascader
aria-label={("Base region")}
options={(options)}
{value}
onChange={next => { value = next ?? []; }}
placeholder={("Select region")}
/>
<p><output aria-label={("Base path")}>{(value.join(' / ')
|| ("Not selected"))}</output></p>
Initial value
defaultValue sets the path when created. For further control use value/onChange.
<script lang="ts">
import { Cascader, type CascaderOption } from '@woodger/antd';
const options: CascaderOption[] = [
{ value: 'zhejiang', label: 'Zhejiang', children: [
{ value: 'hangzhou', label: 'Hangzhou', children: [
{ value: 'xihu', label: 'West Lake' }, { value: 'yuhang', label: 'Yuhang' }
] }
] },
{ value: 'jiangsu', label: 'Jiangsu', children: [
{ value: 'nanjing', label: 'Nanjing', children: [
{ value: 'zhonghuamen', label: 'Zhong Hua Men' }
] }
] }
];
</script>
<Cascader
aria-label={("Starting region")}
options={(options)}
defaultValue={['zhejiang', 'hangzhou', 'xihu']}
/>
Own trigger
Snippet children receives handlers and ARIA. A native button and a separate result replace React children.
<script lang="ts">
import { Button, Cascader, type CascaderOption, type CascaderPath } from '@woodger/antd';
const options: CascaderOption[] = [
{ value: 'zhejiang', label: 'Zhejiang', children: [
{ value: 'hangzhou', label: 'Hangzhou', children: [
{ value: 'xihu', label: 'West Lake' }, { value: 'yuhang', label: 'Yuhang' }
] }
] },
{ value: 'jiangsu', label: 'Jiangsu', children: [
{ value: 'nanjing', label: 'Nanjing', children: [
{ value: 'zhonghuamen', label: 'Zhong Hua Men' }
] }
] }
];
let value = $state<CascaderPath>([]);
</script>
<Cascader options={(options)} {value} onChange={next => { value = next ?? []; }}>
{#snippet children(trigger)}
<Button onclick={trigger.onClick} onkeydown={trigger.onKeyDown} onkeyup={trigger.onKeyUp}
aria-expanded={trigger['aria-expanded']} aria-controls={trigger['aria-controls']}
disabled={trigger.disabled}>{("Select city")}</Button>
{/snippet}
</Cascader>
<p><output aria-label={("Path of your trigger")}>{(value.join(' / ')
|| ("Not selected"))}</output></p>
Hover opening
expandTrigger="hover" expands levels by hovering; sheet selection remains an explicit click.
<script lang="ts">
import { Cascader, type CascaderOption } from '@woodger/antd';
const options: CascaderOption[] = [
{ value: 'zhejiang', label: 'Zhejiang', children: [
{ value: 'hangzhou', label: 'Hangzhou', children: [
{ value: 'xihu', label: 'West Lake' }, { value: 'yuhang', label: 'Yuhang' }
] }
] },
{ value: 'jiangsu', label: 'Jiangsu', children: [
{ value: 'nanjing', label: 'Nanjing', children: [
{ value: 'zhonghuamen', label: 'Zhong Hua Men' }
] }
] }
];
</script>
<Cascader
aria-label={("Region with guidance")}
options={(options)}
expandTrigger="hover"
placeholder={("Point to region")}
/>
Unavailable options
disabled at option blocks the branch; disabled for Cascader blocks the entire field.
<script lang="ts">
import { Cascader, type CascaderOption } from '@woodger/antd';
const options: CascaderOption[] = [
{ value: 'zhejiang', label: 'Zhejiang', children: [
{ value: 'hangzhou', label: 'Hangzhou', children: [
{ value: 'xihu', label: 'West Lake' }, { value: 'yuhang', label: 'Yuhang' }
] }
] },
{ value: 'jiangsu', label: 'Jiangsu', children: [
{ value: 'nanjing', label: 'Nanjing', children: [
{ value: 'zhonghuamen', label: 'Zhong Hua Men' }
] }
] }
];
</script>
<style>
.examples {
display: grid;
justify-items: start;
gap: 16px;
}
</style>
<div class="examples">
<Cascader aria-label={("Region with an inaccessible branch")} options={(options.map(
(option, index) => ({ ...option, disabled: index === 1 })
))} />
<Cascader
aria-label={("Unavailable Cascader")}
options={(options)}
disabled
defaultValue={['zhejiang', 'hangzhou', 'xihu']}
/>
</div>
Intermediate level selection
changeOnSelect allows you to choose a region or city. Pressing also reveals the next level.
<script lang="ts">
import { Cascader, type CascaderOption, type CascaderPath } from '@woodger/antd';
const options: CascaderOption[] = [
{ value: 'zhejiang', label: 'Zhejiang', children: [
{ value: 'hangzhou', label: 'Hangzhou', children: [
{ value: 'xihu', label: 'West Lake' }, { value: 'yuhang', label: 'Yuhang' }
] }
] },
{ value: 'jiangsu', label: 'Jiangsu', children: [
{ value: 'nanjing', label: 'Nanjing', children: [
{ value: 'zhonghuamen', label: 'Zhong Hua Men' }
] }
] }
];
let value = $state<CascaderPath>([]);
</script>
<Cascader
aria-label={("Any region level")}
options={(options)}
changeOnSelect
{value}
onChange={next => { value = next ?? []; }}
/>
<p><output aria-label={("Intermediate path")}>{(value.join(' / ')
|| ("Not selected"))}</output></p>
Multiple paths
multiple stores an array of paths. components.input supplies the search editor. Typing a comma or semicolon from tokenSeparators clears the search field. disableCheckbox lets the branch remain expandable.
<script lang="ts">
import { Cascader, type CascaderOption, type CascaderPath, type SelectInputContext } from '@woodger/antd';
const options: CascaderOption[] = [
{ value: 'zhejiang', label: 'Zhejiang', children: [
{ value: 'hangzhou', label: 'Hangzhou', children: [
{ value: 'xihu', label: 'West Lake' }, { value: 'yuhang', label: 'Yuhang' }
] }
] },
{ value: 'jiangsu', label: 'Jiangsu', children: [
{ value: 'nanjing', label: 'Nanjing', children: [
{ value: 'zhonghuamen', label: 'Zhong Hua Men' }
] }
] }
];
let paths = $state<readonly CascaderPath[]>([]);
</script>
{#snippet editor({ attributes, register }: SelectInputContext)}
<input {...attributes} spellcheck={false} {@attach register} />
{/snippet}
<Cascader
aria-label={("Multiple regions")}
options={(options.map((option, index) => ({ ...option, disableCheckbox: index === 1 })))}
multiple
showSearch
tokenSeparators={[',', ';']}
components={{ input: editor }}
value={paths}
maxTagCount={1}
onChange={next => { paths = next; }}
/>
<p><output aria-label={("Number of paths")}>{(paths.length)}</output></p>
SHOW_PARENT
SHOW_CHILD
Marked Path Strategy
SHOW_PARENT collapses the entire selected branch, SHOW_CHILD returns leaves. The strategy also affects onChange.
<script lang="ts">
import { Cascader, type CascaderOption } from '@woodger/antd';
const options: CascaderOption[] = [
{ value: 'zhejiang', label: 'Zhejiang', children: [
{ value: 'hangzhou', label: 'Hangzhou', children: [
{ value: 'xihu', label: 'West Lake' }, { value: 'yuhang', label: 'Yuhang' }
] }
] },
{ value: 'jiangsu', label: 'Jiangsu', children: [
{ value: 'nanjing', label: 'Nanjing', children: [
{ value: 'zhonghuamen', label: 'Zhong Hua Men' }
] }
] }
];
const strategies = ['SHOW_PARENT', 'SHOW_CHILD'] as const;
</script>
<style>
.examples {
display: grid;
gap: 16px;
}
p {
margin: 0 0 8px;
}
</style>
<div class="examples">
{#each strategies as strategy (strategy)}
<div><p>{(strategy)}</p><Cascader aria-label={("Strategy " + String((strategy)) + "")} options={(options)} multiple
showCheckedStrategy={strategy} defaultValue={[
['zhejiang', 'hangzhou', 'xihu'], ['zhejiang', 'hangzhou', 'yuhang']
]} /></div>
{/each}
</div>
Dimensions
large, medium and small. A field without size inherits the general settings of the section.
<script lang="ts">
import { Cascader, type CascaderOption } from '@woodger/antd';
const options: CascaderOption[] = [
{ value: 'zhejiang', label: 'Zhejiang', children: [
{ value: 'hangzhou', label: 'Hangzhou', children: [
{ value: 'xihu', label: 'West Lake' }, { value: 'yuhang', label: 'Yuhang' }
] }
] },
{ value: 'jiangsu', label: 'Jiangsu', children: [
{ value: 'nanjing', label: 'Nanjing', children: [
{ value: 'zhonghuamen', label: 'Zhong Hua Men' }
] }
] }
];
const sizes = ['large', 'medium', 'small'] as const;
</script>
<style>
.examples {
display: grid;
justify-items: start;
gap: 16px;
}
</style>
<div class="examples">
{#each sizes as size (size)}<Cascader
aria-label={("Cascader size " + String((size)) + "")}
options={(options)}
{size}
placeholder={(size)}
/>{/each}
</div>
Own label and line
displayRender changes the path label; optionRender gets the source node and originNode, preserving the default content.
<script lang="ts">
import {
Cascader, type CascaderContent, type CascaderOption, type CascaderRenderInfo
} from '@woodger/antd';
const options: CascaderOption[] = [
{ value: 'zhejiang', label: 'Zhejiang', children: [
{ value: 'hangzhou', label: 'Hangzhou', children: [
{ value: 'xihu', label: 'West Lake' }, { value: 'yuhang', label: 'Yuhang' }
] }
] },
{ value: 'jiangsu', label: 'Jiangsu', children: [
{ value: 'nanjing', label: 'Nanjing', children: [
{ value: 'zhonghuamen', label: 'Zhong Hua Men' }
] }
] }
];
</script>
{#snippet display(labels: CascaderContent[])}<strong>
{(String(labels.at(-1) ?? ''))}
</strong><span> · {(labels.length)}{(" level")}</span>{/snippet}
{#snippet option(option: CascaderOption, info: CascaderRenderInfo)}
{@render info.originNode()}
{#if option.value === 'xihu'}<small>{("lake")}</small>{/if}
{/snippet}
<Cascader
aria-label={("Region with its label")}
options={(options)}
defaultValue={['zhejiang', 'hangzhou', 'xihu']}
displayRender={display}
optionRender={option}
/>
Search by path
showSearch.filter searches all path labels in a case-insensitive manner. limit limits the results, onSearch reflects the input.
<script lang="ts">
import { Cascader, type CascaderOption, type CascaderPath } from '@woodger/antd';
const options: CascaderOption[] = [
{ value: 'zhejiang', label: 'Zhejiang', children: [
{ value: 'hangzhou', label: 'Hangzhou', children: [
{ value: 'xihu', label: 'West Lake' }, { value: 'yuhang', label: 'Yuhang' }
] }
] },
{ value: 'jiangsu', label: 'Jiangsu', children: [
{ value: 'nanjing', label: 'Nanjing', children: [
{ value: 'zhonghuamen', label: 'Zhong Hua Men' }
] }
] }
];
let value = $state<CascaderPath>([]);
let search = $state('');
</script>
<Cascader
aria-label={("Region search")}
options={(options)}
{value}
onChange={next => { value = next ?? []; }}
showSearch={{
filter: (search, path) => path.some(option => String(option.label).toLowerCase().includes(
search.toLowerCase()
)),
limit: 10,
onSearch: next => { search = next; }
}}
notFoundContent={("Regions not found")}
/>
<p><output aria-label={("Region search result")}>{(search
|| ("Empty search"))}; {(value
.join(' / ')
|| ("Not selected"))}</output></p>
Lazy loading
loadData starts a local demo load. Updating children removes the indicator; timers are cleared when unmounted. showSearch is not compatible with loadData.
<script lang="ts">
import { onDestroy } from 'svelte';
import { Cascader, type CascaderOption } from '@woodger/antd';
let options = $state<CascaderOption[]>([{ value: 'zhejiang', label: 'Zhejiang', isLeaf: false }]);
let pending = $state(false);
let timer: ReturnType<typeof setTimeout> | undefined;
function handleLoad(path: CascaderOption[]) {
const parent = path.at(-1);
if (!parent || parent.value !== 'zhejiang' || pending) {
return;
}
pending = true;
timer = setTimeout(() => {
options = [{ value: 'zhejiang', label: 'Zhejiang', children: [
{ value: 'hangzhou', label: 'Hangzhou', isLeaf: true }
] }];
pending = false;
timer = undefined;
}, 600);
}
onDestroy(() => clearTimeout(timer));
</script>
<Cascader
aria-label={("Loading region")}
options={(options)}
loadData={handleLoad}
placeholder={("Expand Zhejiang")}
/>
<p><output aria-label={("Downloads Cascader")}>{(pending ? "Loading…" : "Waiting for selection")}</output></p>
Custom field names
fieldNames maps code, name, and items to the key, label, and children. CascaderPath<string> represents a path of string keys.
<script lang="ts">
import { Cascader, type CascaderPath } from '@woodger/antd';
const options = [{ code: 'ui', name: "Interface", items: [
{ code: 'button', name: 'Button' }, { code: 'input', name: 'Input' }
] }];
let value = $state<CascaderPath<string>>([]);
</script>
<Cascader
aria-label={("Catalog with your own fields")}
options={(options)}
fieldNames={{ value: 'code', label: 'name', children: 'items' }}
{value}
onChange={next => { value = next ?? []; }}
/>
<p><output aria-label={("Directory path")}>{(value.join(' / ')
|| ("Not selected"))}</output></p>
Prefix and icons
The prefix and expandIcon snippets customize the icons, and the suffix function returns the arrow snippet. allowClear.label sets an accessible name for the clear button.
<script lang="ts">
import { Cascader, type CascaderOption } from '@woodger/antd';
const options: CascaderOption[] = [
{ value: 'zhejiang', label: 'Zhejiang', children: [
{ value: 'hangzhou', label: 'Hangzhou', children: [
{ value: 'xihu', label: 'West Lake' }, { value: 'yuhang', label: 'Yuhang' }
] }
] },
{ value: 'jiangsu', label: 'Jiangsu', children: [
{ value: 'nanjing', label: 'Nanjing', children: [
{ value: 'zhonghuamen', label: 'Zhong Hua Men' }
] }
] }
];
</script>
{#snippet prefix()}<span aria-hidden="true">⌖</span>{/snippet}
{#snippet suffixIcon()}<span aria-hidden="true">⌄</span>{/snippet}
{#snippet expand()}<span aria-hidden="true">›</span>{/snippet}
<Cascader
aria-label={("Region with icons")}
options={(options)}
{prefix}
suffix={() => suffixIcon}
expandIcon={expand}
allowClear={{ label: ("Clear region") }}
/>
Own drop-down panel
popupRender wraps standard menus in a snippet, preserving selection, keyboard and popup handling.
<script lang="ts">
import type { Snippet } from 'svelte';
import { Cascader, type CascaderOption } from '@woodger/antd';
const options: CascaderOption[] = [
{ value: 'zhejiang', label: 'Zhejiang', children: [
{ value: 'hangzhou', label: 'Hangzhou', children: [
{ value: 'xihu', label: 'West Lake' }, { value: 'yuhang', label: 'Yuhang' }
] }
] },
{ value: 'jiangsu', label: 'Jiangsu', children: [
{ value: 'nanjing', label: 'Nanjing', children: [
{ value: 'zhonghuamen', label: 'Zhong Hua Men' }
] }
] }
];
</script>
<style>
.footer {
padding: 12px;
border-top: 1px solid var(--ant-color-border-secondary);
font-size: 12px;
}
</style>
{#snippet popup(menus: Snippet)}
{@render menus()}
<div class="footer">{("Region → city → attraction")}</div>
{/snippet}
<Cascader
aria-label={("Region with basement panel")}
options={(options)}
popupRender={popup}
/>
Panel position
placement picks one of four positions. builtinPlacements sets anchor points, the gap, and how the popup fits in limited space.
<script lang="ts">
import { Cascader, type CascaderOption, type CascaderPopupAlign } from '@woodger/antd';
const options: CascaderOption[] = [
{ value: 'zhejiang', label: 'Zhejiang', children: [
{ value: 'hangzhou', label: 'Hangzhou', children: [
{ value: 'xihu', label: 'West Lake' }, { value: 'yuhang', label: 'Yuhang' }
] }
] },
{ value: 'jiangsu', label: 'Jiangsu', children: [
{ value: 'nanjing', label: 'Nanjing', children: [
{ value: 'zhonghuamen', label: 'Zhong Hua Men' }
] }
] }
];
const placements = ['topLeft', 'topRight', 'bottomLeft', 'bottomRight'] as const;
const overflow = { adjustY: true, shiftX: true };
const builtinPlacements = {
topLeft: { points: ['bl', 'tl'], offset: [0, -8], overflow },
topRight: { points: ['br', 'tr'], offset: [0, -8], overflow },
bottomLeft: { points: ['tl', 'bl'], offset: [0, 8], overflow },
bottomRight: { points: ['tr', 'br'], offset: [0, 8], overflow }
} satisfies Record<typeof placements[number], CascaderPopupAlign>;
</script>
<style>
.examples {
display: grid;
justify-items: start;
gap: 16px;
}
</style>
<div class="examples">
{#each placements as placement (placement)}
<Cascader aria-label={("Position " + String((placement)) + "")} options={(options)} {placement} {builtinPlacements}
placeholder={placement} />
{/each}
</div>
Design options
outlined, filled, borderless and underlined use the same selection model.
<script lang="ts">
import { Cascader, type CascaderOption } from '@woodger/antd';
const options: CascaderOption[] = [
{ value: 'zhejiang', label: 'Zhejiang', children: [
{ value: 'hangzhou', label: 'Hangzhou', children: [
{ value: 'xihu', label: 'West Lake' }, { value: 'yuhang', label: 'Yuhang' }
] }
] },
{ value: 'jiangsu', label: 'Jiangsu', children: [
{ value: 'nanjing', label: 'Nanjing', children: [
{ value: 'zhonghuamen', label: 'Zhong Hua Men' }
] }
] }
];
const variants = ['outlined', 'filled', 'borderless', 'underlined'] as const;
</script>
<style>
.examples {
display: grid;
justify-items: start;
gap: 16px;
}
</style>
<div class="examples">
{#each variants as variant (variant)}
<Cascader aria-label={("Cascader variant " + String((variant)) + "")} options={(options)} {variant} placeholder={(variant)} />
{/each}
</div>
Test states
status="error" and status="warning" change the design of single and multiple, while maintaining the available selection.
<script lang="ts">
import { Cascader, type CascaderOption } from '@woodger/antd';
const options: CascaderOption[] = [
{ value: 'zhejiang', label: 'Zhejiang', children: [
{ value: 'hangzhou', label: 'Hangzhou', children: [
{ value: 'xihu', label: 'West Lake' }, { value: 'yuhang', label: 'Yuhang' }
] }
] },
{ value: 'jiangsu', label: 'Jiangsu', children: [
{ value: 'nanjing', label: 'Nanjing', children: [
{ value: 'zhonghuamen', label: 'Zhong Hua Men' }
] }
] }
];
</script>
<style>
.examples {
display: grid;
justify-items: start;
gap: 16px;
}
</style>
<div class="examples">
<Cascader
aria-label={("Region with error")}
options={(options)}
status="error"
placeholder={("Error")}
/>
<Cascader aria-label={("Regions with warning")} options={(options)} multiple status="warning" placeholder={("Warning")} />
</div>
Semantic slots
The classNames object and styles function customize root and nested popup parts. CSS properties can be supplied as objects.
<script lang="ts">
import { Cascader, type CascaderOption } from '@woodger/antd';
const options: CascaderOption[] = [
{ value: 'zhejiang', label: 'Zhejiang', children: [
{ value: 'hangzhou', label: 'Hangzhou', children: [
{ value: 'xihu', label: 'West Lake' }, { value: 'yuhang', label: 'Yuhang' }
] }
] },
{ value: 'jiangsu', label: 'Jiangsu', children: [
{ value: 'nanjing', label: 'Nanjing', children: [
{ value: 'zhonghuamen', label: 'Zhong Hua Men' }
] }
] }
];
</script>
<Cascader
aria-label={("Semantic Cascader")}
options={(options)}
classNames={{ input: 'documented-cascader-input' }}
styles={({ props }) => ({
root: 'border-style:dashed',
popup: {
root: 'border:1px solid var(--ant-color-primary)',
list: 'padding:8px',
listItem: props.disabled
? 'opacity:0.5'
: 'font-weight:600'
}
})}
/>
Separate panel
CascaderPanel shows columns without input field and popup. Horizontal scrolling is limited to the example container.
<script lang="ts">
import { CascaderPanel, type CascaderOption, type CascaderPath } from '@woodger/antd';
const options: CascaderOption[] = [
{ value: 'zhejiang', label: 'Zhejiang', children: [
{ value: 'hangzhou', label: 'Hangzhou', children: [
{ value: 'xihu', label: 'West Lake' }, { value: 'yuhang', label: 'Yuhang' }
] }
] },
{ value: 'jiangsu', label: 'Jiangsu', children: [
{ value: 'nanjing', label: 'Nanjing', children: [
{ value: 'zhonghuamen', label: 'Zhong Hua Men' }
] }
] }
];
let value = $state<CascaderPath>([]);
</script>
<style>
.panel {
max-width: 100%;
overflow-x: auto;
}
</style>
<div
class="panel"
><CascaderPanel
aria-label={("Permanent region panel")}
options={(options)}
{value}
onChange={next => { value = next ?? []; }}
/></div>
<p><output aria-label={("Permanent panel path")}>{(value.join(' / ')
|| ("Not selected"))}</output></p>
Region in shape
Form stores an array of keys. Reset restores the original path; clear and submit check for required selection.
<script lang="ts">
import {
Button,
Cascader,
Form,
FormItem,
createForm,
type CascaderOption,
type CascaderPath
} from '@woodger/antd';
const options: CascaderOption[] = [
{
value: 'zhejiang', label: 'Zhejiang', children: [
{
value: 'hangzhou', label: 'Hangzhou', children: [
{ value: 'xihu', label: 'West Lake' }, { value: 'yuhang', label: 'Yuhang' }
]
}
]
},
{
value: 'jiangsu', label: 'Jiangsu', children: [
{
value: 'nanjing', label: 'Nanjing', children: [
{ value: 'zhonghuamen', label: 'Zhong Hua Men' }
]
}
]
}
];
const form = createForm<{ region: CascaderPath }>({
initialValues: { region: ['zhejiang', 'hangzhou', 'xihu'] },
rules: ({ region: [{ required: true, message: "Select region." }] })
});
let result = $state('');
</script>
<style>
.actions {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
</style>
<Form {form} onFinish={values => { result = values.region.join(' / '); }}>
<FormItem name="region" label={("Delivery region")}>
<Cascader options={(options)} value={form.values.region} onChange={next => form
.setFieldValue(
'region',
next ?? []
)} />
</FormItem>
<div
class="actions"
><Button
type="primary"
htmlType="submit"
>{("Save region")}</Button><Button
htmlType="reset"
>{("Reset region")}</Button></div>
</Form>
<p><output aria-label={("Saved region")}>{(result
|| ("Not sent"))}</output></p>
Multi-value panel
Regions for travel
Initial example from the review: search for the selected region and an independent multiple selection panel.
<script lang="ts">
import { Cascader, CascaderPanel, type CascaderOption, type CascaderPath } from '@woodger/antd';
const options: CascaderOption[] = [
{
value: 'zhejiang',
label: 'Zhejiang',
children: [{ value: 'hangzhou', label: 'Hangzhou', children: [
{ value: 'xihu', label: 'West Lake' },
{ value: 'yuhang', label: 'Yuhang' }
] }]
},
{
value: 'jiangsu',
label: 'Jiangsu',
children: [{ value: 'nanjing', label: 'Nanjing', children: [
{ value: 'zhonghuamen', label: 'Zhong Hua Men' }
] }]
},
{ value: 'disabled', label: "Unavailable region", disabled: true }
];
let value = $state<CascaderPath>(['zhejiang', 'hangzhou', 'xihu']);
let paths = $state<readonly CascaderPath[]>([]);
</script>
<style>
.example {
display: grid;
gap: 16px;
min-width: 0;
}
.field {
display: grid;
gap: 8px;
max-width: 400px;
}
h3 {
margin: 0 0 8px;
font-size: 14px;
}
.panel {
max-width: 100%;
overflow-x: auto;
}
output {
display: block;
overflow-wrap: anywhere;
}
</style>
<div class="example">
<div class="field">
<label for="showcase-cascader">{("Region with search")}</label>
<Cascader
id="showcase-cascader"
options={(options)}
{value}
showSearch
allowClear
placeholder={("Select region")}
onChange={next => { value = next ?? []; }}
/>
</div>
<output aria-label={("Selected region")}>{(value.join(' / ')
|| ("Region not selected"))}</output>
<div>
<h3>{("Multi-value panel")}</h3>
<div class="panel">
<CascaderPanel
options={(options)}
multiple
value={paths}
aria-label={("Regions for travel")}
onChange={next => { paths = next; }}
/>
</div>
</div>
<output aria-label={("Selected regions")}>{(paths.map(path => path.join(' / '))
.join('; ')
|| ("No regions selected"))}</output>
</div>
Without local prefixCls, the field uses the common -select, columns and Panel use the common -cascader. A non-empty local prefixCls specifies one fully qualified name for both parts. The namespace of theme variables is independent; search render gets the allowed Cascader prefix.
Cascader and Panel CSS prefixes
General and local namespace, search, multiple paths and RTL. Changing the prefix saves the selection and editor; The namespace of the theme is set separately.
<script lang="ts">
import {
Cascader, CascaderPanel, Checkbox, ConfigProvider,
type CascaderFieldNames, type CascaderOption, type CascaderPath
} from '@woodger/antd';
const options: CascaderOption[] = [
{ value: 'ui', label: "Interface", children: [
{ value: 'button', label: 'Button' }, { value: 'input', label: 'Input' }
] },
{ value: 'data', label: "Data", children: [{ value: 'table', label: 'Table' }] }
];
let custom = $state(true);
let local = $state(true);
let rtl = $state(false);
let single = $state<CascaderPath>(['ui', 'button']);
let paths = $state<readonly CascaderPath[]>([['ui', 'input']]);
let panel = $state<CascaderPath>(['ui', 'button']);
const prefix = $derived(custom ? 'suite' : 'ant');
const localPrefix = $derived(local ? 'project-paths' : '');
</script>
<style>
.example,
.fields,
section {
display: grid;
grid-template-columns: minmax(0, 1fr);
gap: 12px;
min-width: 0;
}
.example { gap: 20px; }
.controls {
display: flex;
flex-wrap: wrap;
gap: 12px;
}
.panel-scroll {
max-width: 100%;
min-width: 0;
overflow-x: auto;
}
p { margin: 0; }
output { overflow-wrap: anywhere; }
</style>
{#snippet searchResult(
_query: string, path: CascaderOption[], ownerPrefix: string,
fields: Required<CascaderFieldNames>
)}
<span data-search-prefix={ownerPrefix}>
{path.map(option => String(option[fields.label])).join(' / ')}
</span>
{/snippet}
<div class="example">
<div class="controls">
<Checkbox bind:checked={custom}>{("General prefix Cascader suite")}</Checkbox>
<Checkbox bind:checked={local}>{("Cascader local prefix")}</Checkbox>
<Checkbox bind:checked={rtl}>{("RTL Cascader with prefix")}</Checkbox>
</div>
<ConfigProvider prefixCls={prefix} direction={rtl ? 'rtl' : 'ltr'}
theme={{ cssVar: { prefix: 'paths-theme' } }}>
<div class="fields">
<section aria-label={("Single Cascader with Prefix")}>
<Cascader options={(options)} prefixCls={localPrefix} value={single}
onChange={next => { single = next ?? []; }}
showSearch={{ render: searchResult }} style="width:100%"
aria-label={("Search Cascader with prefix")} />
<output
aria-label={("Cascader path with prefix")}
>{(single.join(' / ') || '—')}</output>
</section>
<section aria-label={("Multiple Cascader with Prefix")}>
<Cascader options={(options)} prefixCls={localPrefix} multiple value={paths}
onChange={next => { paths = next; }} showSearch={{ render: searchResult }}
style="width:100%" aria-label={("Multiple Cascader paths with prefix")} />
<output
aria-label={("Cascader paths with prefix")}
>{JSON.stringify(paths)}</output>
</section>
<section aria-label={("Cascader panel with prefix")}>
<div class="panel-scroll">
<CascaderPanel options={(options)} prefixCls={localPrefix} value={panel}
onChange={next => { panel = next ?? []; }} aria-label={("Cascader speakers with prefix")} />
</div>
<output
aria-label={("Panel path with prefix")}
>{(panel.join(' / ') || '—')}</output>
</section>
</div>
</ConfigProvider>
<output
aria-label={("Cascader CSS prefix")}
>{("\n General: ")}{prefix}{("; local: ")}{(localPrefix
|| ("from the provider"))}
</output>
<p>
{("Without local prefixCls, the field uses the common -select, columns and Panel use the common -cascader. A non-empty local prefixCls specifies one fully qualified name for both parts. The namespace of theme variables is independent; search render gets the allowed Cascader prefix.")}
</p>
</div>
API
Twenty themes of the Cascader live page on ant.design are presented in the cards above. Additionally, the Form and original example trip from the review are shown. The table is checked against the public CascaderProps package.
| Property | Description | Type | Default |
|---|---|---|---|
prefixCls | Full local prefix Select control and Cascader columns/Panel. The empty string and undefined inherit the independent common -select and -cascader; a non-empty value gives the same namespace to both parts. Theme namespace is independent. | string | ConfigProvider: -select / -cascader |
options | Node hierarchy. value, label, children, disabled, disableCheckbox and isLeaf describe the structure and selection. | readonly CascaderOption[] | [] |
value | Managed path; for multiple - an array of paths. Use onChange, bind:value is not supported. | CascaderPath | readonly CascaderPath[] | undefined |
defaultValue | Initial local value, read once. | CascaderPath | readonly CascaderPath[] | [] |
onChange | Single is cleared to undefined, multiple to []. Unknown keys are retained; selectedOptions may contain undefined. | (value, selectedOptions) => void | — |
multiple | Selecting related paths via checkbox. The public type CascaderValue<true> describes an array of paths. | boolean | false |
showCheckedStrategy | Reduces a completely marked branch to its parent or returns leaves. Defines both the display and the result of onChange. | SHOW_PARENT | SHOW_CHILD | SHOW_PARENT |
changeOnSelect | Allows single to select an intermediate node while maintaining the next level expansion. | boolean | false |
showSearch | Search by full paths: filter, sort, render, limit, matchInputWidth, searchValue, onSearch and autoClearSearchValue. Snippet render receives query, path, resolved Cascader prefix and fieldNames. | boolean | CascaderSearchConfig | false |
loadData | The loader must update options.children or isLeaf. The returned Promise does not clear the indicator; cannot be combined with showSearch. | (selectedOptions) => void | — |
fieldNames | Links non-standard data fields to the Cascader tree. | CascaderFieldNames | label / value / children |
expandTrigger | Expands the next column by clicking or hovering. | click | hover | click |
allowClear | clearIcon customizes the clear icon, and label sets its accessible name. | boolean | SelectAllowClear | true |
open | Managed popup; defaultOpen sets the start, onOpenChange accepts the new state. | boolean | Local state |
displayRender | Replaces path mapping while preserving value keys. | Snippet<[labels, selectedOptions]> | Labels via / |
optionRender | info.originNode retains the original label and search highlighting. | Snippet<[option, info]> | Standard string |
children | Gets its trigger onClick/onKeyDown/onKeyUp and ARIA; pass them to the native control. | Snippet<[CascaderTriggerInfo]> | Input field |
popupRender | Wrapper around menus. They need to be rendered to save the selection and keyboard. | Snippet<[Snippet]> | Standard menus |
maxTagCount | Number of visible tags multiple; The summary tag and tagRender receive separate information. | number | responsive | All tags |
size | Field size. Without a local value, ConfigProvider.componentSize is inherited. | large | medium | small | From ConfigProvider |
variant | Field option. status accepts error or warning. | outlined | filled | borderless | underlined | From context / outlined |
placement | Preferred popup position; getPopupContainer selects a container. | topLeft | topRight | bottomLeft | bottomRight | bottomLeft |
popupAlign | Anchor points, offsets, and overflow adjustment for the selected popup position. | CascaderPopupAlign | — |
builtinPlacements | Map of popup positions for placement values. | Readonly<Record<string, CascaderPopupAlign>> | Built-in map |
components | components.input replaces the editor inside the standard control. Pass attributes and register to the native element. | CascaderProps["components"] | — |
tokenSeparators | Separators that clear the search text when typed in multiple mode. | SelectTokenSeparators | — |
classNames | Semantic slots classes, object or function from info.props. | CascaderSemanticValue<string> | — |
styles | CSS strings and objects for root, input, item, and popup parts. | CascaderStyles | — |
suffix | Content on the right of the field. To render a snippet, return it from the suffix function. suffixIcon supplies the fallback icon. | CascaderProps["suffix"] | Arrow |
suffixIcon | Replaces the default arrow. The suffix setting controls all content on the right of the field. | CascaderContent | Arrow |
CascaderPanel
Individual CascaderPanel export accepts a common selection of paths: options, value/defaultValue, multiple, onChange, fieldNames, changeOnSelect, showCheckedStrategy, expandTrigger, loadData, optionRender, disabled and prefixCls. The panel does not have an input field, search field, or popup field, so the trigger, placement, and popupRender parameters do not apply to it.
Differences from the current ant.design page
Currently version 6.7.0 on ant.design. The package does not yet have a new suffix, semantic slot clear and extended allowClear with label/tabIndex/disabled. Use suffixIcon and the available clearIcon object. The ConfigProvider.cascader configuration supports design and icons; Panel inherits from it only expandIcon and loadingIcon.
Methods
Cascader provides focus(options?) and blur() via bind:this. bind:inputElement returns input, bind:nativeElement returns the root div. With its own trigger input there is no. CascaderPanel only provides nativeElement.
<script lang="ts">
import { Button, Cascader } from '@woodger/antd';
let control = $state<Pick<ReturnType<typeof Cascader>, 'focus' | 'blur'>>();
</script>
<style>
.controls {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 12px;
}
</style>
<div class="controls">
<Cascader bind:this={control} aria-label={("Cascader Methods")} options={([
{ value: 'ui', label: "Interface", children: [{ value: 'button', label: 'Button' }] }
])} />
<Button onclick={() => control?.focus()}>{("Focus Cascader")}</Button>
<Button onclick={() => control?.blur()}>{("Remove focus Cascader")}</Button>
</div>
Semantic DOM
Field - input with role combobox, aria-expanded, aria-controls and active child. Popup contains menu columns, options - menuitemcheckbox buttons. Arrows move focus and reveal levels; Enter selects, Escape closes the popup. In multiple, the associated mark of the parent is propagated to the available children.
| Slots | Purpose |
|---|---|
root / prefix / suffix | Field and its additions. |
input / placeholder / content | Input, prompt and selected value area. |
item / itemContent / itemRemove | multiple tag, its contents and removal. |
popup.root / popup.list / popup.listItem | Popup, column and menu bar. |
The popup object can specify nested slots or a single line for the root. The semantic slots example retains the original structure and keyboard navigation.
Registration tokens
All eight component tokens are connected via theme.components.Cascader. The preview is isolated by a nested ConfigProvider; the same parameters change a separate Panel. If necessary, the design of a specific slot can be specified via styles.
<script lang="ts">
import { Cascader, CascaderPanel, ConfigProvider } from '@woodger/antd';
const options = [{ value: 'ui', label: "Interface", children: [
{ value: 'button', label: 'Button' }, { value: 'input', label: 'Input' }
] }];
</script>
<style>
.field {
width: min(100%, 260px);
margin-bottom: 16px;
}
.panel {
max-width: 100%;
overflow-x: auto;
}
</style>
<ConfigProvider theme={{
components: {
Cascader: {
controlWidth: '100%',
controlItemWidth: 120,
dropdownHeight: 140,
menuPadding: 6,
optionPadding: '8px 14px',
optionSelectedBg: '#722ed1',
optionSelectedColor: '#fff',
optionSelectedFontWeight: 700
}
}
}}>
<div class="field">
<Cascader aria-label={("Cascader field tokens")} options={(options)} defaultValue={[
'ui',
'button'
]} />
</div>
<div
class="panel"
><CascaderPanel
aria-label={("Cascader panel tokens")}
options={(options)}
defaultValue={['ui', 'button']}
/></div>
</ConfigProvider>
| Token | Purpose |
|---|---|
controlItemWidth | Menu column width. |
controlWidth | Field width. |
dropdownHeight | Popup menu height. |
menuPadding | Indentation inside a column. |
optionPadding | Line indent. |
optionSelectedBg | Background of the selected row. |
optionSelectedColor | Color of the selected row. |
optionSelectedFontWeight | Saturation of the selected row. |
Common tokens of the current topic
List verified with ant.design. theme.useToken() values respond to section settings.
| Token | Current value |
|---|---|
colorBgContainer | #ffffff |
colorBgContainerDisabled | rgba(0,0,0,0.04) |
colorBorder | #d9d9d9 |
colorHighlight | #ff4d4f |
colorIcon | rgba(0,0,0,0.45) |
colorPrimary | #2f54eb |
colorPrimaryBorder | #adc6ff |
colorPrimaryHover | #597ef7 |
colorSplit | rgba(5,5,5,0.06) |
colorText | rgba(0,0,0,0.88) |
colorTextDisabled | rgba(0,0,0,0.25) |
colorWhite | #fff |
borderRadiusSM | 4 |
controlInteractiveSize | 16 |
controlItemBgHover | rgba(0,0,0,0.04) |
fontFamily | -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol',
'Noto Color Emoji' |
fontSize | 14 |
fontSizeIcon | 12 |
fontSizeLG | 16 |
lineHeight | 1.5714285714285714 |
lineType | solid |
lineWidth | 1 |
lineWidthBold | 2 |
lineWidthFocus | 3 |
marginXS | 8 |
motionDurationFast | 0.1s |
motionDurationMid | 0.2s |
motionDurationSlow | 0.3s |
motionEaseInBack | cubic-bezier(0.71, -0.46, 0.88, 0.6) |
motionEaseOutBack | cubic-bezier(0.12, 0.4, 0.29, 1.46) |
paddingXS | 8 |
paddingXXS | 4 |
FAQ
How is Cascader different from TreeSelect?
Cascader returns the full path and shows the levels in separate columns. TreeSelect returns the node key and expands the tree in one pane.
Why doesn't the download finish after resolve Promise?
Update options.children or isLeaf. In the current Svelte API, it is the data change that completes loading the branch, not the resolve loadData handler.
Is it possible to search simultaneously with loadData?
No, the search works using known full paths. Download data in advance or organize a separate search in the application.
Why does multiple return the parent path?
SHOW_PARENT merges the fully checked branch. For destination paths, select SHOW_CHILD; the signatures do not become model values.