Skip to content

AutoComplete

Basic Usage

ts
import '@company-ui/style';
import { Autocomplete } from '@company-ui/dom';

new Autocomplete({
  target: '#autocomplete1',
});

Data Source Usage

ts
import '@company-ui/style';
import { Autocomplete } from '@company-ui/dom';

new Autocomplete({
  api: 'qcc_open',
  target: '#autocomplete2',
  autoFocus: false,
  submitButtonLabel: '查一查',
  historyStorageKey: 'qcc-open-company-history',
  placeholder: '请输入企业名称或统一社会信用代码',
});

API

Attributes

NameDescriptionTypeDefault
targetid of the html element tagstring-
apiquery data sourcestringclearbit
queryDelayquery data 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
avatarUrlavatar urlstring-
clearIconclear iconstring
historyhistory optionsHistoryOptionsHistoryOptions

HistoryOptions

NameDescriptionTypeDefault
enabledhistory enabledbooleantrue
typehistory save modestringlocalStorage
keyhistory save keystringcompany-history
showClearshow clear history linkbooleantrue
itemIconhistory item iconstring
clearIconclear history link iconstring

Events

NameDescriptionType
onInputtriggers when the input value changeFunction
onChangetriggers when the input value changeFunction
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.