Skip to content

AutoComplete 自动完成

基本用法

tsx
import { useState } from 'react';
import '@company-ui/style';
import { AutoComplete } from '@company-ui/react';

const [inputValue, setInputValue] = useState('');

<AutoComplete defaultValue={inputValue} value={inputValue} onChange={setInputValue} />;

其他数据源用法

tsx
import { useState } from 'react';
import '@company-ui/style';
import { AutoComplete } from '@company-ui/react';

const [inputValue, setInputValue] = useState('');

<AutoComplete
  defaultValue={inputValue}
  value={inputValue}
  api="qcc_open"
  historyStorageKey="qcc-open-company-history"
  submitButtonLabel="查一查"
  placeholder="请输入企业名称或统一社会信用代码"
  autoFocus={false}
  onChange={setInputValue}
/>;

API

Attributes

NameDescriptionTypeDefault
defaultValue输入框默认内容string-
value输入框内容string-
api查询数据源stringclearbit
queryDelay查询数据延迟number500
placeholder输入占位符内容stringInput company name
clearable显示清除按钮booleantrue
backFill使用键盘选择选项的时候把选中项回填到输入框中booleantrue
popupAppendToBody是否插入至 body 元素上booleantrue
autoFocus自动获取焦点booleantrue
showSubmitButton显示提交按钮booleantrue
submitButtonLabel提交按钮文字stringSubmit
offsetTop距离文本框底部的偏移值number5
autoFlip文本框是否自动翻转booleanfalse
historyEnabled打开保存历史记录booleantrue
historyType保存历史记录模式stringlocalStorage
historyStorageKey保存历史记录键stringcompany-history
historyClearable显示历史记录清除按钮booleantrue

Events

NameDescriptionType
onChange当输入值改变时触发Function
onInput当输入值输入时触发Function
onFetch查询数据时触发Function
onAbortFetch当中止查询数据时触发Function
onSelect当单击建议时触发Function
onClear当单击文本框清除按钮时触发Function
onFocus当输入聚焦时触发Function
onBlur当输入取消聚焦时触发Function
onSubmit按钮提交时触发Function
onDropdownVisibleChange当下拉菜单出现/消失时触发Function

本中文文档内容版权为 Michael Sun 所有,保留所有权利。