组件仍在补充, 欢迎加群交流哦,微信: a2298613245
headless ui
✕
组件还在补充中,希望能够帮助你有一个亮点项目放入简历!
全局方案
按钮 Button
图标 Icon
布局 Grid
间距 Space
输入框 Input
弹窗 Modal
弹出框 Popover
消息 Toast
警告 Alert
单选框 Radio
复选框 Checkbox
标签 Tag
其它组件
基础用法
AI 时代的组件库
Select 完整案例
传统案例

选择器 Select
当用户需要从一组同类数据中选择一个或多个时,可以使用下拉选择器,点击后选择对应项。

单选 Tailwind 版本

edit js

多选 Tailwind 版本

Select frameworks
edit js

单选 CSS 版本

edit css
edit js

多选 CSS 版本

Select frameworks...
edit css
edit js

使用方法

1import { Select, IconCheckLine, IconCloseLine, IconDownLine, IconEmptyFill, } from '@t-headless-ui/react'; 2 3// single select 4<Select.Root> 5 <Select.View> 6 <Select.Input /> 7 <Select.Clear /> 8 <Select.Affix /> 9 </Select.View> 10 <Select.Content> 11 <Select.Empty /> 12 <Select.List> 13 {(item) => ( 14 <Select.Option 15 key={item.value} 16 item={item} 17 /> 18 )} 19 </Select.List> 20 </Select.Content> 21</Select.Root> 22 23// multiple select 24<Select.Root isMultiple> 25 <Select.View> 26 <Select.MultiInputRoot> 27 <Select.MultiTag /> 28 <Select.MultiInput /> 29 </Select.MultiInputRoot> 30 <Select.Clear /> 31 <Select.Affix /> 32 </Select.View> 33 <Select.Content> 34 <Select.Empty /> 35 <Select.List> 36 {(item) => ( 37 <Select.Option 38 key={item.value} 39 item={item} 40 /> 41 )} 42 </Select.List> 43 </Select.Content> 44</Select.Root>

API

Select.Root Props
接口名: SelectRootProps
参数名类型描述默认值
classNamestring自定义类名-
childrenReactNode下拉框选项的内容-
disabledboolean是否禁用选择器-
readOnlyboolean是否只读-
showSearchboolean是否能搜索-
isMultipleboolean是否支持多选-
onKeyDown(e: any) => void选择框的键盘事件回调-
defaultValuestring | string[] | number | number[] | LabeledValue | LabeledValue[]选择框的默认值-
valuestring | string[] | number | number[] | LabeledValue | LabeledValue[]选择器的值(受控模式)-
inputValuestring输入框的值(受控模式)-
options(string | number | { label: string | number; value: string | number; disabled?: boolean; extra?: any; children?: OptionsType; })[]指定可选项-
labelInValueboolean设置 `onChange` 回调中 `value` 的格式。默认是string,设置为true时候,value格式为: { label: string, value: string }-
filterOptionboolean | ((inputValue: string, option: { label: any; value: any; disabled?: boolean; extra?: any; }) => boolean)是否根据输入的值筛选数据。如果传入函数的话,接收 `inputValue` 和 `option` 两个参数,当option符合筛选条件时,返回 `true`,反之返回 `false`。true
renderFormat(option: OptionData | null, value: LabeledValue) => ReactNode定制回显内容。返回值将会显示在下拉框内。若 `value` 对应的 `Option` 不存在,则第一个参数是 null-
destroyOnCloseboolean是否在隐藏的时候销毁 DOM 结构true
defaultPopupVisibleboolean下拉框是否默认打开。-
popupVisibleboolean控制下拉框是否打开。-
tokenSeparatorsstring[]在多选模式下自动分词的分隔符。-
onChange(value: any, option: OptionData | OptionData[]) => void点击选择框的回调-
onSelect(value: LabeledValue, option: OptionData) => void选中选项时触发的回调,(只在 `multiple` 模式下触发)。-
onDeselect(value: LabeledValue, option: OptionData) => void取消选中的时候触发的回调,(只在 `multiple` 模式下触发)。-
onClear(visible: boolean) => void点击清除时触发,参数是当前下拉框的展开状态。-
onSearch(value: string, reason: InputValueChangeReason) => void搜索时的回调-
onFocus(e: any) => void获得焦点时的回调-
onBlur(e: any) => void失去焦点时的回调-
onVisibleChange(visible: boolean) => void下拉框收起展开时触发-
onInputValueChange(value: string, reason: InputValueChangeReason) => void输入框文本改变的回调。-
onPaste(e: any) => void输入框文本粘贴的回调。-
refReact.RefObject<SelectHandle>选择框的引用对象-
offsetDistancenumber主轴方向上的距离偏移-
offsetSkiddingnumber副轴方向上的平移偏移-
Select.View Props
接口名: SelectViewProps
参数名类型描述默认值
idstring自定义类名-
styleReact.CSSProperties自定义样式-
classNamestring自定义类名-
placeholderstring选择框默认文字-
maxTagCountInputTagRootProps['maxTagCount']最大标签数, 支持自定义渲染,请在 InputTag 组件中查看 maxTagCount 类型定义-
childrenReact.ReactNode子元素-
Select.Input Props
接口名: SelectInputProps
参数名类型描述默认值
classNamestring自定义类名,单选是给 input 元素添加类名,多选是给包裹 input 框的外层 div 添加类名-
childrenReactNode子元素, 仅在多选模式下有效-
Select.MultiInputRoot Props
接口名: SelectMultiInputRootProps
参数名类型描述默认值
childrenany子元素-
classNameany自定义类名-
Select.MultiTag Props
接口名: SelectMultiTagProps
参数名类型描述默认值
renderTagInputTagProps['renderTag']自定义标签渲染,具体参数见 InputTag 组件的 renderTag 类型定义-
Select.Content Props
接口名: SelectContentProps
参数名类型描述默认值
classNamestring自定义类名-
styleReact.CSSProperties自定义样式-
attachstring下拉框挂载的父节点,默认挂载到 body 上, attach 会传入 document.querySelector 获取父节点。body
childrenReactNode下拉框选项的内容-
Select.Option Props
接口名: SelectOptionProps
继承: Omit<HTMLAttributes<HTMLDivElement>, 'children'>
参数名类型描述默认值
childrenReactNode--
itemOptionData--
SelectListProps
接口名: SelectListProps
参数名类型描述默认值
children(props: OptionData) => ReactNode--
Select.Affix Props
接口名: SelectAffixProps
继承: Omit<HTMLAttributes<HTMLDivElement>, 'children'>
参数名类型描述默认值
childrenReactNode--
Select.Clear Props
接口名: SelectClearProps
继承: Omit<HTMLAttributes<HTMLDivElement>, 'children'>
参数名类型描述默认值
childrenReactNode--
Select.Empty Props
接口名: SelectEmptyProps
继承: Omit<HTMLAttributes<HTMLDivElement>, 'children'>
参数名类型描述默认值
childrenReactNode--
Option Data Type
接口名: OptionData
参数名类型描述默认值
labelstring | number--
valuestring | number--
disabledboolean--
extraany--
_keystring--
_indexnumber--
_origin'children' | 'options'--
_validboolean--
isGroupTitleboolean--
Options Type
接口名: OptionsType
类型
SelectRootProps['options']
InputValueChangeReason
接口名: InputValueChangeReason
类型
'manual' | 'optionChecked' | 'optionListHide' | 'tokenSeparator'
LabeledValue
接口名: LabeledValue
参数名类型描述默认值
valuestring | number--
labelstring | number--
Select Reference Type
接口名: SelectHandle
参数名类型描述默认值
domHTMLDivElementDOM 节点-
focus() => void使选择框聚焦-
blur() => void使选择框失焦-
选择器 Select
单选 Tailwind 版本
多选 Tailwind 版本
单选 CSS 版本
多选 CSS 版本
使用方法
API