Skip to content

AutoComplete

Basic Usage

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} />;

Data Source Usage

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
defaultValuethe initial input contentstring-
valuethe input content valuestring-
apiquery sourcestringclearbit
queryDelayquery delaynumber500
placeholderinput placeholder contentstringInput company name
clearableshow clear buttonbooleantrue
backFillIf backFill selected item the input when using keyboardbooleantrue
popupAppendToBodywhether to append Dialog itself to bodybooleantrue
autoFocusauto focusbooleantrue
showSubmitButtonshow submit buttonbooleantrue
submitButtonLabelsubmit button labelstringSubmit
offsetToppixels to offset from input bottomnumber5
autoFlipauto flipbooleanfalse
historyEnabledopen save history recordbooleantrue
historyTypesave history record modestringlocalStorage
historyStorageKeysave history record keystringcompany-history
historyClearableshow history clear buttonbooleantrue

Events

NameDescriptionType
onChangetriggers when the input value changeFunction
onInputtriggers when the input value inputFunction
onFetchtriggers when query dataFunction
onAbortFetchtriggers when abort query dataFunction
onSelecttriggers when a suggestion is clickedFunction
onCleartriggers when the input is cleared by clicking the clear buttonFunction
onFocustriggers when the input focusesFunction
onBlurtriggers when the input blursFunction
onSubmittriggers when the button submitFunction
onDropdownVisibleChangetriggers when the dropdown appears/disappearsFunction

Released under the MIT License.