Ant Design Svelte

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.

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

Not selected

Basic selection

A connected path of three levels. value/onChange store an array of keys; clearing single transmits undefined.

Initial value

defaultValue sets the path when created. For further control use value/onChange.

Not selected

Own trigger

Snippet children receives handlers and ARIA. A native button and a separate result replace React children.

Hover opening

expandTrigger="hover" expands levels by hovering; sheet selection remains an explicit click.

Unavailable options

disabled at option blocks the branch; disabled for Cascader blocks the entire field.

Not selected

Intermediate level selection

changeOnSelect allows you to choose a region or city. Pressing also reveals the next level.

0

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.

SHOW_PARENT

SHOW_CHILD

Marked Path Strategy

SHOW_PARENT collapses the entire selected branch, SHOW_CHILD returns leaves. The strategy also affects onChange.

Dimensions

large, medium and small. A field without size inherits the general settings of the section.

Own label and line

displayRender changes the path label; optionRender gets the source node and originNode, preserving the default content.

Waiting for selection

Lazy loading

loadData starts a local demo load. Updating children removes the indicator; timers are cleared when unmounted. showSearch is not compatible with loadData.

Not selected

Custom field names

fieldNames maps code, name, and items to the key, label, and children. CascaderPath<string> represents a path of string keys.

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.

Own drop-down panel

popupRender wraps standard menus in a snippet, preserving selection, keyboard and popup handling.

Panel position

placement picks one of four positions. builtinPlacements sets anchor points, the gap, and how the popup fits in limited space.

Design options

outlined, filled, borderless and underlined use the same selection model.

Test states

status="error" and status="warning" change the design of single and multiple, while maintaining the available selection.

Semantic slots

The classNames object and styles function customize root and nested popup parts. CSS properties can be supplied as objects.

Not selected

Separate panel

CascaderPanel shows columns without input field and popup. Horizontal scrolling is limited to the example container.

Not sent

Region in shape

Form stores an array of keys. Reset restores the original path; clear and submit check for required selection.

zhejiang / hangzhou / xihu

Multi-value panel

No regions selected

Regions for travel

Initial example from the review: search for the selected region and an independent multiple selection panel.

ui / button
[["ui","input"]]
ui / button
General: suite; local: project-paths

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.

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.

Basic parameters of Cascader
PropertyDescriptionTypeDefault
prefixClsFull 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.stringConfigProvider: -select / -cascader
optionsNode hierarchy. value, label, children, disabled, disableCheckbox and isLeaf describe the structure and selection.readonly CascaderOption[][]
valueManaged path; for multiple - an array of paths. Use onChange, bind:value is not supported.CascaderPath | readonly CascaderPath[]undefined
defaultValueInitial local value, read once.CascaderPath | readonly CascaderPath[][]
onChangeSingle is cleared to undefined, multiple to []. Unknown keys are retained; selectedOptions may contain undefined.(value, selectedOptions) => void—
multipleSelecting related paths via checkbox. The public type CascaderValue<true> describes an array of paths.booleanfalse
showCheckedStrategyReduces a completely marked branch to its parent or returns leaves. Defines both the display and the result of onChange.SHOW_PARENT | SHOW_CHILDSHOW_PARENT
changeOnSelectAllows single to select an intermediate node while maintaining the next level expansion.booleanfalse
showSearchSearch by full paths: filter, sort, render, limit, matchInputWidth, searchValue, onSearch and autoClearSearchValue. Snippet render receives query, path, resolved Cascader prefix and fieldNames.boolean | CascaderSearchConfigfalse
loadDataThe loader must update options.children or isLeaf. The returned Promise does not clear the indicator; cannot be combined with showSearch.(selectedOptions) => void—
fieldNamesLinks non-standard data fields to the Cascader tree.CascaderFieldNameslabel / value / children
expandTriggerExpands the next column by clicking or hovering.click | hoverclick
allowClearclearIcon customizes the clear icon, and label sets its accessible name.boolean | SelectAllowCleartrue
openManaged popup; defaultOpen sets the start, onOpenChange accepts the new state.booleanLocal state
displayRenderReplaces path mapping while preserving value keys.Snippet<[labels, selectedOptions]>Labels via /
optionRenderinfo.originNode retains the original label and search highlighting.Snippet<[option, info]>Standard string
childrenGets its trigger onClick/onKeyDown/onKeyUp and ARIA; pass them to the native control.Snippet<[CascaderTriggerInfo]>Input field
popupRenderWrapper around menus. They need to be rendered to save the selection and keyboard.Snippet<[Snippet]>Standard menus
maxTagCountNumber of visible tags multiple; The summary tag and tagRender receive separate information.number | responsiveAll tags
sizeField size. Without a local value, ConfigProvider.componentSize is inherited.large | medium | smallFrom ConfigProvider
variantField option. status accepts error or warning.outlined | filled | borderless | underlinedFrom context / outlined
placementPreferred popup position; getPopupContainer selects a container.topLeft | topRight | bottomLeft | bottomRightbottomLeft
popupAlignAnchor points, offsets, and overflow adjustment for the selected popup position.CascaderPopupAlign—
builtinPlacementsMap of popup positions for placement values.Readonly<Record<string, CascaderPopupAlign>>Built-in map
componentscomponents.input replaces the editor inside the standard control. Pass attributes and register to the native element.CascaderProps["components"]—
tokenSeparatorsSeparators that clear the search text when typed in multiple mode.SelectTokenSeparators—
classNamesSemantic slots classes, object or function from info.props.CascaderSemanticValue<string>—
stylesCSS strings and objects for root, input, item, and popup parts.CascaderStyles—
suffixContent on the right of the field. To render a snippet, return it from the suffix function. suffixIcon supplies the fallback icon.CascaderProps["suffix"]Arrow
suffixIconReplaces the default arrow. The suffix setting controls all content on the right of the field.CascaderContentArrow

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.

Available slots Cascader
SlotsPurpose
root / prefix / suffixField and its additions.
input / placeholder / contentInput, prompt and selected value area.
item / itemContent / itemRemovemultiple tag, its contents and removal.
popup.root / popup.list / popup.listItemPopup, 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>
Cascader Component Tokens
TokenPurpose
controlItemWidthMenu column width.
controlWidthField width.
dropdownHeightPopup menu height.
menuPaddingIndentation inside a column.
optionPaddingLine indent.
optionSelectedBgBackground of the selected row.
optionSelectedColorColor of the selected row.
optionSelectedFontWeightSaturation of the selected row.

Common tokens of the current topic

List verified with ant.design. theme.useToken() values ​​respond to section settings.

Cascader Common Tokens
TokenCurrent value
colorBgContainer#ffffff
colorBgContainerDisabledrgba(0,0,0,0.04)
colorBorder#d9d9d9
colorHighlight#ff4d4f
colorIconrgba(0,0,0,0.45)
colorPrimary#2f54eb
colorPrimaryBorder#adc6ff
colorPrimaryHover#597ef7
colorSplitrgba(5,5,5,0.06)
colorTextrgba(0,0,0,0.88)
colorTextDisabledrgba(0,0,0,0.25)
colorWhite#fff
borderRadiusSM4
controlInteractiveSize16
controlItemBgHoverrgba(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'
fontSize14
fontSizeIcon12
fontSizeLG16
lineHeight1.5714285714285714
lineTypesolid
lineWidth1
lineWidthBold2
lineWidthFocus3
marginXS8
motionDurationFast0.1s
motionDurationMid0.2s
motionDurationSlow0.3s
motionEaseInBackcubic-bezier(0.71, -0.46, 0.88, 0.6)
motionEaseOutBackcubic-bezier(0.12, 0.4, 0.29, 1.46)
paddingXS8
paddingXXS4

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.