React
示例
当前选择:Asia/Shanghai
禁用状态
用法
import { useState } from 'react';
import { Combobox } from '@momoyeyu/momo-ui';
import '@momoyeyu/momo-ui/styles.css';
export function Example() {
const [zone, setZone] = useState("Asia/Shanghai");
return (
<>
<Combobox label="时区" value={zone} onChange={setZone}
searchLabel="搜索时区" emptyLabel="未找到时区"
options={[{value: "Asia/Shanghai", label: "Asia/Shanghai", keywords: "上海"}]}
/>
</>
);
}API
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
label | string | 必填 | 控件的可访问名称。 |
searchLabel | string | 必填 | 搜索输入的可访问名称与占位文案。 |
emptyLabel | string | 必填 | 没有匹配项时的提示。 |
value | string | 必填 | 当前选项值。 |
options | readonly Choice[] | 必填 | 每项包含 value、label,可选 keywords。 |
onChange | (value: string) => void | 必填 | 选择后收到值。 |
id | string | — | 触发按钮的 ID。 |
disabled | boolean | false | 禁止打开。 |
用 Enter、空格或方向键打开,输入筛选,上下键移动高亮,Enter 选中,Escape 返回触发按钮。