Autocomplete

Autocomplete UI Component

Installation

npm i @synerise/ds-autocomplete
or
yarn add @synerise/ds-autocomplete

Usage

import Autocomplete from '@synerise/ds-autocomplete'
<Autocomplete />

Demo

API

PropertyDescriptionTypeDefault
allowClearShow clear button, effective in multiple mode only.booleanfalse
autoFocusget focus when component mountedbooleanfalse
backfillbackfill selected item the input when using keyboardbooleanfalse
children (for customize input element)customize input elementHTMLInputElement HTMLTextAreaElement React.ReactElement<InputProps>
children (for dataSource)Data source to auto completeReact.ReactElement<OptionProps> Array<React.ReactElement<OptionProps>>-
dataSourceData source for autocompleteDataSourceItemType[]-
dropdownMenuStyleadditional style applied to dropdown menuobject
defaultActiveFirstOptionWhether active first option by defaultbooleantrue
defaultValueInitial selected option.string or string[]-
disabledWhether disabled selectboolean-
readonlyWhether disabled select with readonly styles appliedboolean-
filterOptionIf true, filter options by input, if function, filter options against it. The function will receive two arguments, inputValue and option, if the function returns true, the option will be included in the filtered set; Otherwise, it will be excluded.boolean or function(inputValue, option)true
optionLabelPropWhich prop value of option will render as content of select.stringchildren
placeholderplaceholder of inputstring-
valueselected optionstring or string[] or { key: string, label: string or ReactNode } or Array<{ key: string, label: string or ReactNode }>-
onBlurCalled when leaving the component.function()-
onChangeCalled when select an option or input value change, or value of input is changedfunction(value)-
onFocusCalled when entering the componentfunction()-
onSearchCalled when searching items.function(value)-
onSelectCalled when a option is selected. param is option's value and option instance.function(value, option)-
defaultOpenInitial open state of dropdownboolean-
openControlled open state of dropdownboolean-
onDropdownVisibleChangeCall when dropdown openfunction(open)-
getPopupContainerParent Node which the selector should be rendered to. Default to body. When position issues happen, try to modify it into scrollable content and position it relative.function(triggerNode)document.querySelector(.ant-select-auto-complete)
errorTexterror message, if provided input will be set in error statestring-
labelinput labelstring-
descriptioninput descriptionstring-
autoResize'resize' width of the input based on width of the text in inputAutoResizePropundefined

AutoResizeProp

type AutoResizeProp = `boolean` | {
minWidth: string;
maxWidth?: string;
stretchToFit?: boolean
};

Setting stretchToFit: true will make the field stretch to fit the containing element. The component observes the width of the wrapper and adjusts the maxWidth accordingly.
Important if the Input is within a flex-item then there is necessary CSS that needs to be applied to the flex-item containers in order for the flex-item to grow to fill the allowed space, but at the same time not stretch the flex container (identical issue happens when text-overflow needs to happen inside a flex-item).

$flexItemSurroundingTheInput {
min-width: 0;
flex-grow: 1
}

See https://css-tricks.com/flexbox-truncated-text/ for more details.