useTypeahead
@astryxdesign/core v0.7.1 · useTypeahead
参数
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
options | UseTypeaheadOptions | — | 配置对象。 |
options.getItemLabels | () => ReadonlyArray<string | null | undefined> | — | 按 DOM 顺序返回各项的标签。某一项是 null 或空字符串,表示这个位置不参与匹配,下标仍然跟调用方的项对得上。 |
options.onMatch | (index: number) => void | — | 匹配到之后把下标告诉你,你可以聚焦或者选中它;通常接 useListFocus 的 focusItem。 |
options.getCurrentIndex | () => number | () => -1 | 从哪一项开始找,一般是当前聚焦的那项。同一个字母一直按,就会在匹配项之间轮着走。负的数表示当前没有项。 |
options.resetMs | number | 750 | 多久没有新按键就清空缓冲区,单位毫秒。 |
options.isDisabled | (index: number) => boolean | — | 这个下标要不要跳过,比如禁用项。 |
返回值
| 名称 | 类型 | 说明 |
|---|---|---|
onKeyDown | (event: KeyboardEvent) => boolean | 按键处理函数。吃掉一个可打印字符时返回 true,调用方就不用再自己处理这个键。 |
reset | () => void | 清掉还没超时的缓冲区,比如这组选项关掉的时候。 |