Skip to content
API 风格:

TreeSelect ​

A dropdown trigger combined with a Tree panel. Single mode returns a string, multiple mode (checkboxes) returns string[].

Basic usage ​

Single
vue
<script setup>
import { ref } from 'vue'
const treeValue = ref(undefined)
const treeData = [
  { key: 'a', label: 'Frontend', children: [
    { key: 'a-1', label: 'Vue' },
    { key: 'a-2', label: 'React' },
  ] },
  { key: 'b', label: 'Backend' },
]
</script>

<template>
  <LhTreeSelect :data="treeData" v-model="treeValue" />
</template>
vue
<script>
export default {
  data() {
    return {
      treeValue: undefined,
      treeData: [
        { key: 'a', label: 'Frontend', children: [
          { key: 'a-1', label: 'Vue' },
          { key: 'a-2', label: 'React' },
        ] },
        { key: 'b', label: 'Backend' },
      ],
    }
  },
}
</script>

<template>
  <LhTreeSelect :data="treeData" v-model="treeValue" />
</template>

Multiple ​

Multiple
vue
<script setup lang="ts">
import { ref } from 'vue'

const treeMulti = ref<string[]>([])
const treeData = [
  { key: 'a', label: 'Frontend', children: [
    { key: 'a-1', label: 'Vue' },
    { key: 'a-2', label: 'React' },
  ] },
  { key: 'b', label: 'Backend' },
]
</script>

<template>
  <!-- Multiple -->
  <LhTreeSelect :data="treeData" v-model="treeMulti" multiple placeholder="Pick a stack" />
</template>
vue
<script>
export default {
  data() {
    return {
      treeMulti: [],
      treeData: [
        { key: 'a', label: 'Frontend', children: [
          { key: 'a-1', label: 'Vue' },
          { key: 'a-2', label: 'React' },
        ] },
        { key: 'b', label: 'Backend' },
      ],
    }
  },
}
</script>

<template>
  <!-- Multiple -->
  <LhTreeSelect :data="treeData" v-model="treeMulti" multiple placeholder="Pick a stack" />
</template>

Disabled and mounting ​

disabled disables the selector; teleported set to false mounts the dropdown panel in place (no teleport to body).

Disabled / local panel
vue
<script setup lang="ts">
const treeData = [
  { key: 'a', label: 'Frontend', children: [
    { key: 'a-1', label: 'Vue' },
    { key: 'a-2', label: 'React' },
  ] },
  { key: 'b', label: 'Backend' },
]
</script>

<template>
  <LhTreeSelect :data="treeData" disabled />
  <LhTreeSelect :data="treeData" :teleported="false" />
</template>
vue
<script>
export default {
  data() {
    return {
      treeData: [
        { key: 'a', label: 'Frontend', children: [
          { key: 'a-1', label: 'Vue' },
          { key: 'a-2', label: 'React' },
        ] },
        { key: 'b', label: 'Backend' },
      ],
    }
  },
}
</script>

<template>
  <LhTreeSelect :data="treeData" disabled />
  <LhTreeSelect :data="treeData" :teleported="false" />
</template>

API ​

LhTreeSelect Props ​

AttributeDescriptionTypeDefault
dataTree data[LhTreeNode](#type-LhTreeNode)[]—
modelValueValue (string for single, string[] for multiple)string | string[]—
multipleMultiple mode (checkboxes; value is the checked key array)booleanfalse
disabledDisabledbooleanfalse
placeholderPlaceholder textstring—
teleportedTeleport the panel to bodybooleantrue
sxQuick layout propsLhSxProps—

LhTreeSelect Events ​

EventDescriptionCallback
update:modelValueEmitted when the value changes (use with v-model; string for single, string[] for multiple)(value: string | string[] | undefined) => void
changeEmitted after the selection changes(value: string | string[] | undefined) => void

Accessibility ​

  • The trigger is a real <button> with aria-haspopup="tree" + aria-expanded; the panel is role="listbox" (aria-multiselectable in multiple mode)
  • Inside the panel the full APG tree-pattern keyboard support is reused
  • Closes on outside click or Escape, returning focus to the trigger

Type Definitions ​

The TypeScript type structures exported by this component (auto-extracted from packages/components/tree-select/src/types.ts and @lh-ui/share/core/* sources; click each entry to expand; see the Props table above for attribute descriptions):

LhTreeSelectProps
ts
export interface LhTreeSelectProps {
  data: LhTreeNode[]
  modelValue?: string | string[]
  multiple?: boolean
  disabled?: boolean
  placeholder?: string
  teleported?: boolean
  sx?: LhSxProps
}
LhTreeNode (from @lh-ui/share/core/tree)
ts
export interface LhTreeNode {
  key: string
  label: string
  children?: LhTreeNode[]
  disabled?: boolean
  isLeaf?: boolean
}

Beauty of tradition, foundation of code