Component

Select

安装 Installation

npx timkit add select --yes --framework react

用法 Usage

import { Select } from "@/components/ui/select"

className 与 variant、size 可以一起用。字段以 timkit agent inspect select --json 的 props 为准。

示例

Examples

一次看一个示例。左侧按名称筛选,预览里可切换源码和框架。

51 / 51

Select · With label · 01

Loading preview...

结构化 API

Structured API

与 UCS schema 对齐的 props、逻辑机与多框架运行时。

Component

select

Logic

zag / select

Runtime Frameworks

ReactVueWeappHTML

Supported Platforms

WebWeChat Mini Program

Configuration

PropTypeDefaultDescription
logic.provider*
enum (zag | native | none)
zagState and interaction provider used by this component.
logic.machine
string
selectUnderlying state machine identifier when provider is zag.
platforms*
array
Web, WeChat Mini ProgramPlatforms officially supported by this schema.
frameworks*
array
React, Vue, Weapp, HTMLFramework demos/code currently available in registry files.
dependencies
array
@timui/core, @zag-js/reactRuntime package dependencies required by this registry item.
optionalPeerDependencies
array
lucide-reactOptional peer dependencies used by this registry item.
registryDependencies
array
-Dependent Timkit registry components/hook entries.

Props

PropTypeDefaultDescription
placeholder
string
-The placeholder text.
value
string
-The controlled value.
disabled
boolean
falseWhen true, opening and selection are ignored.
readOnly
boolean
falseWhen true, opening and selection are ignored.
required
boolean
falseWhen true, the select is announced as required.
open
boolean
-The controlled open state of the list.
defaultOpen
boolean
-The default open state of the list when uncontrolled.

Events

PropTypeDefaultDescription
onValueChange
event
-Event handler called when the value changes.
onOpenChange
event
-Event handler called when the list open state changes.

TypeScript

来自 TypeScript 导出。

PropTypeDefaultDescription
id
string
-A unique identifier for the component.
collection
ListCollection<SelectItem>
-The items collection source for list-based components.
defaultValue
string
-The default value of the component when uncontrolled.
modelValue
string
-The controlled value bound via `v-model` (Vue specific).
name
string
-The name of the component, used when submitting an HTML form.

Slots

PropTypeDefaultDescription
default
slot
-The select segments

Parts

PropTypeDefaultDescription
root*
root
-The select container
trigger
part
-The toggle button
value
part
-The display value
content
part
-The dropdown content
item
part
-A single option
group
part
-A group of options
label
part
-A group label
separator
part
-A separator line
This API reference is generated from `/packages/core` component schemas to keep React/Vue/Weapp docs consistent.

该组件尚无扩展说明文档。

键盘与焦点

Keyboard

跨 React、Vue 与小程序共享的交互与可读名称约定。

  • ArrowDown opens the list.
  • ArrowDown and ArrowUp move the highlighted option.
  • Home moves to the first enabled option.
  • End moves to the last.
  • A letter moves to the next enabled option whose label starts with that letter.
  • An open list only moves the highlight for Home, End, and a letter.
  • A closed list selects the option those keys land on.
  • Enter selects the highlighted option.
  • Escape closes the list.
  • On the mini program, the close control is a button named Close and is in the tab order.
  • The trigger is in the tab order unless it is disabled.
  • Options are not.
  • One selected option is visible as Option N of the option count.
  • Several selected options read how many are selected.
  • An empty value has no option status.
  • On the mini program, an omitted name is the selected value, or Select an item.
  • A passed aria-label names the trigger.
  • On the mini program, the list is named by the trigger.
  • The check mark on a selected option is not part of its name.
  • The arrow on the trigger is not part of the name.
  • Each option exposes whether it is selected.
  • In static HTML, the closed list stays hidden and its content uses tabindex 0.
  • In static HTML, the trigger is a button with aria-haspopup listbox.
  • On the mini program, the trigger sets aria-haspopup listbox.
  • On the mini program, aria-activedescendant is set only while an option is highlighted.
  • On the mini program, aria-controls is set only while the popup is open.
  • On the mini program, the open list uses tabindex 0.
  • On the mini program, the close mark is hidden from the name.

行为契约

Contract

props、默认值和运行时状态。

  • When read-only, opening and selection are ignored.
  • A controlled open value stays until the parent changes it.
  • A required select is announced as required.