Components/TreeSelect

TreeSelect

A select that picks from tree-shaped data in a dropdown.

VerifiedSince 0.3.4

Usage

Basic

Loading demo...

Permission Orchestration

TxTreeSelect picks the owner team and forms an authorization flow with TxTransfer and TxTimeline.

Loading demo...

Best Practices

  • Use TxTreeSelect for compact owner, namespace, category, and org-unit picks; use TxTree when users need persistent context, bulk operations, or custom row controls.
  • Give nodes stable key and label fields instead of a legacy value field, with keys independent of localized text.
  • Match the value's shape to multiple before render; switching at runtime doesn't convert between a scalar and an array.
  • Keep default expansion shallow, such as root departments or product areas.
  • Use the node slot only for badges or subtitles, never for click targets that compete with row selection.

API Reference

Props

PropTypeDefaultDescription
modelValuestring | number | Array<string | number> | undefined-Selected key in single mode; an array of keys with multiple.
nodesTreeSelectNode[][]Tree nodes for the dropdown, also used to resolve the trigger text.
multiplebooleanfalseCheckbox multi-select, shown as tags in the trigger.
disabledbooleanfalseDisables the trigger, dropdown interaction, keyboard toggling, and clearing.
placeholderstring'请选择'Placeholder when no selected key resolves to a label.
searchablebooleantrueShows a search field whose text goes to the inner TxTree as filterText.
clearablebooleantrueShows a clear button when something is selected and the component is enabled.
placementPopoverPlacement'bottom-start'Placement of the dropdown.
dropdownOffsetnumber6Distance between the dropdown and the trigger.
dropdownWidthnumber0Dropdown width; 0 leaves it to TxPopover.
dropdownMaxWidthnumber480Maximum dropdown width.
dropdownMaxHeightnumber320Maximum tree height; taller content scrolls.
defaultExpandedKeysArray<string | number>[]Keys the inner TxTree starts expanded.

Events

EventParamsDescription
update:modelValuevalue: TreeSelectValueFires after a selection, a clear, or setValue().
changevalue: TreeSelectValueFires right after update:modelValue with the same value.
open-Fires when the dropdown opens.
close-Fires when the dropdown closes.

Slots

SlotPropsDescription
node{ node, level, expanded, selected }Replaces the node label area of a row; caret, checkbox, indent, and click handling stay with the component.

Exposed Methods

NameTypeDescription
open()() => voidOpens the dropdown.
close()() => voidCloses the dropdown.
toggle()() => voidToggles the dropdown.
focus()() => voidFocuses the combobox trigger.
blur()() => voidBlurs the combobox trigger.
clear()() => voidUnless disabled, emits undefined in single mode or [] in multiple mode.
setValue(value)(value: TreeSelectValue) => voidEmits the given value through update:modelValue and change, without checking it against nodes.
getValue()() => TreeSelectValueReturns the current modelValue.
getCheckedKeys()() => Array<string | number>Returns the selected keys as an array, in single mode too.

Types

EXAMPLE.TS
type TreeSelectValue = string | number | Array<string | number> | undefined

interface TreeSelectNode {
  key: string | number // stable and unique; the selected value
  label: string // node text, default search target, and trigger text
  disabled?: boolean // blocks selecting this node
  children?: TreeSelectNode[]
}

Overview

  • The trigger is a focusable role="combobox" (aria-haspopup="tree", aria-controls pointing at the popup) whose popup holds a role="tree" TxTree; Enter and Space toggle the dropdown, Escape closes it.
  • Single selection closes the dropdown and clears to undefined; multiple selection stays open and clears to [].
  • Disabled nodes can't be selected but still expand when they have children.
  • Search uses TxTree's default label filter, with no custom filterMethod or controlled expandedKeys; for domain search, compose an external search or use TxTree directly.
  • Trigger text is resolved from the current nodes; unknown selected keys stay selected but show no text.
  • setValue() only emits; the parent still owns modelValue through v-model, which ordinary code should prefer.

Technologies

  • The dropdown is a TxPopover that receives the placement and width props; the tree reuses TxTree, passing only defaultExpandedKeys, filterText, and multiple.
  • Source: packages/tuffex/packages/components/src/tree-select/.
查看源码
packages/tuffex/packages/components/src/tree-select/index.ts