Skip to content

react-component/select

Repository files navigation

@rc-component/select


React Select Component.

NPM versionnpm downloadbuild statusCodecovbundle sizedumi

Screenshots

Feature

  • support IE11+,Chrome,Firefox,Safari

Keyboard

  • Open select (focus input || focus and click)
  • KeyDown/KeyUp/Enter to navigate menu

install

@rc-component/select

Usage

basic use

importSelect,{Option}from'@rc-component/select';import'@rc-component/select/assets/index.css';exportdefault()=>(<Select><Optionvalue="jack">jack</Option><Optionvalue="lucy">lucy</Option><Optionvalue="yiminghe">yiminghe</Option></Select>);

API

Select props

namedescriptiontypedefault
idhtml id to set on the component wrapperString''
classNameadditional css class of root dom nodeString''
data-*html data attributes to set on the component wrapperString''
prefixClsprefix classString''
animationdropdown animation name. only support slide-up nowString''
transitionNamedropdown css animation nameString''
choiceTransitionNamecss animation name for selected items at multiple modeString''
dropdownMatchSelectWidthwhether dropdown's width is same with selectbooleantrue
dropdownClassNameadditional className applied to dropdownString-
dropdownStyleadditional style applied to dropdownReact.CSSProperties{}
dropdownAlignadditional align applied to dropdownAlignType{}
dropdownMenuStyleadditional style applied to dropdown menuObjectReact.CSSProperties
notFoundContentspecify content to show when no result matches.ReactNode'Not Found'
tokenSeparatorsseparator used to tokenize on tag/multiple modestring[]?
opencontrol select openboolean
defaultOpencontrol select default openboolean
placeholderselect placeholderReact Node
showSearchwhether show search input in single modeboolean | Objecttrue
allowClearwhether allowClearboolean{clearIcon?: ReactNode }
tagswhen tagging is enabled the user can select from pre-existing options or create a new tag by picking the first choice, which is what the user has typed into the search box so far.booleanfalse
tagRenderrender custom tags.(props: CustomTagProps) => ReactNode-
maxTagTextLengthmax tag text length to shownumber-
maxTagCountmax tag count to shownumber-
maxTagPlaceholderplaceholder for omitted valuesReactNode/function(omittedValues)-
comboboxenable combobox mode(can not set multiple at the same time)booleanfalse
multiplewhether multiple selectbooleanfalse
disabledwhether disabled selectbooleanfalse
optionLabelProprender option value or option children as content of selectString: 'value'/'children''value'
defaultValueinitial selected option(s)String | String[]-
valuecurrent selected option(s)String | String[] |{key:String, label:React.Node} |{key:String, label:React.Node}[]-
labelInValuewhether to embed label in value, see above value type. Not support combobox modebooleanfalse
backfillwhether backfill select option to search input (Only works in single and combobox mode)booleanfalse
onChangecalled when select an option or input value change(combobox)function(value, option:Option | Option[])-
onBlurcalled when blurfunction-
onFocuscalled when focusfunction-
onPopupScrollcalled when menu is scrolledfunction-
onSelectcalled when a option is selected. param is option's value and option instanceFunction(value, option:Option)-
onDeselectcalled when a option is deselected. param is option's value. only called for multiple or tagsFunction(value, option:Option)-
onInputKeyDowncalled when key down on inputFunction(event)-
defaultActiveFirstOptionwhether active first option by defaultbooleantrue
getPopupContainercontainer which popup select menu rendered intofunction(trigger:Node):Nodefunction(){return document.body}
getInputElementcustomize input elementfunction(): Element-
showActionactions trigger the dropdown to showString[]?-
autoFocusfocus select after mountboolean-
prefixspecify the select prefix icon or textReactNode-
suffixIconspecify the select arrow iconReactNode-
clearIconspecify the clear iconReactNode-
removeIconspecify the remove iconReactNode-
menuItemSelectedIconspecify the item selected iconReactNode | (props: MenuItemProps) => ReactNode-
dropdownRenderrender custom dropdown menu(menu: React.Node) => ReactNode-
loadingshow loading icon in arrowbooleanfalse
virtualDisable virtual scrollbooleantrue
directiondirection of dropdown'ltr' | 'rtl''ltr'
optionRenderCustom rendering options(oriOption: FlattenOptionData<BaseOptionType> , info:{index: number }) => React.ReactNode-
labelRenderCustom rendering label(props: LabelInValueType) => React.ReactNode-
maxCountThe max number of items can be selectednumber-

Methods

namedescriptionparametersreturn
focusfocus select programmably--
blurblur select programmably--

showSearch

namedescriptiontypedefault
autoClearSearchValueauto clear search input value when multiple select is selected/deselectedbooleantrue
filterOptionwhether filter options by input value. default filter by option's optionFilterProp prop's valueboolean| (inputValue: string, option: Option) => booleantrue
filterSortSort function for search options sorting, see Array.sort's compareFunction.Function(optionA:Option, optionB: Option)-
optionFilterPropwhich prop value of option will be used for filter if filterOption is trueString'value'
searchValueThe current input "search" textstring-
onSearchcalled when input changedfunction-

Option props

namedescriptiontypedefault
classNameadditional class to optionString''
disabledno effect for click or keydown for this itembooleanfalse
keyif react want you to set key, then key is same as value, you can omit valueString/number-
valuedefault filter by this attribute. if react want you to set key, then key is same as value, you can omit valueString/number-
titleif you are not satisfied with auto-generated title which is show while hovering on selected value, you can customize it with this propertyString-

OptGroup props

namedescriptiontypedefault
labelgroup labelString/React.Element-
key-String-
valuedefault filter by this attribute. if react want you to set key, then key is same as value, you can omit valueString-
classNamesame as Option propsString''
titlesame as Option propsString-

Development

npm install npm start 

Example

local example: http://localhost:9001/

online example: https://select-react-component.vercel.app/

Test Case

npm test 

Coverage

npm run coverage 

License

@rc-component/select is released under the MIT license.