Select

Designer doc
Select is an input component to select a value from an option list.

Example

Basic Usage
View code
An icon button can be used to trigger dropdown selection too.
View code
Customization, Option Groups, and Other States
Unlike Ant Design’s Select, Coral’s Select supports SelectOption to be rendered anywhere inside SelectList, but you need to provide index prop if they are not directly under it.
This flexibility allows you to achieve more customizable rendering like option groups.
View code
Ellipsis Tooltip
You can use SelectEllipsisTooltip to achieve similar result with EllipsisTooltip. The main difference is that SelectEllipsisTooltip will position the tooltip on the right in the SelectList, and top in SelectButton or SelectSearch.
By default, number of lines to ellipsis is 2. You can customize it by specifying maxRows prop.
View code
onChange vs onSelect
As the name of the callback suggests, onChange is only called when the value changes. For example, if the current value is 1, selecting 1 will not trigger the callback.
On the other hand, onSelect is triggered whenever an option is selected - either mouse click or keyboard enter. This callback can be helpful to create select again to deselect behaviour.
View code
You can replace SelectButton component into SelectSearch. But note that you should not pass value and onChange props to SelectSearch. Instead you should pass it to Select as searchValue and onSearch prop. Also, you should never use both SelectButton and SelectSearch in the same Select component.
Regarding the list of options, Coral’s Select doesn’t handle your search result - which in most cases makes customisations much easier. Simply render SelectOption whatever (e.g. .filter()) and whenever (e.g. api call) you want.
View code
Customize selected option rendering in input box
By default, SelectSearch and SelectButton will render the same DOM element under selected option. You can customize it through children prop.
View code
Since Coral’s Select doesn’t handle search results. As a result, it can avoid fairly confusing callbacks like in React Select to accomplish async options.
View code
SelectList Width
SelectList accepts optional width prop, which defaults to ‘auto’ meaning it will adjust with the button or input element width. You can also pass a number to this prop or simply style through css should also be fine.
Then, why is this prop provided if I can just style it through css to override it? Answer: so that you can always go back to ‘auto’ after a certain component composition uses a number width.
View code
Controlled isOpen
View code
Customizing Arrow Icon
You can also customize the dropdown arrow by providing rightElement prop to the SelectButton or SelectSearch. By default, there’s no clear icon on selection, you can pass clearable prop to SelectArrowIcon like so:
View code
Virtualized
To optimize rendering large data, you can use SelectVirtualizedList. This component integrates SelectList with react-virtual. Coral uses react-virtual instead of more popular libraries like react-virtualized or react-window because react-virtual exposes the API as a hook and easier to integrate with Coral components that already has markup and styles.
Note that this component list has a tradeoff from the more commonly used SelectList:
  • Must have a predefined height, by default is 36. Set it through itemSize prop.
  • Cannot have a nested or non-direct SelectOption.
View code
You can also use both SelectVirtualizedList and SelectSearch like so:
View code
Empty List Placeholder
When children is falsy (empty list, null, undefined, false), SelectList and SelectVirtualizedList will show a placeholder instead. You can customize the placeholder by specifying emptyPlaceholder prop, and default to “No Data”. To not show any placeholder, you can pass null to this prop.
View code
Adding Tooltip Example
View code

Accessibility

Try playing around with Arrow Down, Arrow Up, Escape, Enter when popup opens or closed. Select and any other wrapping components (e.g. MultiSelect) have exceptionally complex keyboard accessibility.
If you’re interested, carefully explore Chrome URL Bar behaviours on both keyboard and mouse interactions.

References

API

Select
Prop nameTypeDefaultDescription
idstring
initialIsOpenboolean
initialKeyboardHighlightedIndexnumber
initialMouseHighlightedIndexnumber
initialSearchValuestring
initialSelectedIndexnumber
initialValueSelectValue
isOpenboolean
keyboardHighlightedIndexnumber
mouseHighlightedIndexnumber
onChangeChangeCallback
Called when selected value is changed. Different from onSelect, onChange is not called when the value is already selected.
onIsOpenChange(isOpen: boolean) => void
onKeyboardHighlightedIndexChange(index: number) => void
onMouseHighlightedIndexChange(index: number) => void
onSearchSearchCallback
onSelectChangeCallback
Different from onChange: onSelect is triggered even if the option's value is the selected one.
onSelectedIndexChange(index: number) => void
searchValuestring
This is not the selected value. Rather, it's a search value on input if you use SelectSearch.
selectedIndexnumber
stateReducerAcdcStateReducer(state, { nextState }) => nextState
valueSelectValue
SelectArrowIcon
Prop nameTypeDefaultDescription
asany
Tag or component, but a simple tag (i.e. built-in components, e.g. div, span) is recommended.
clearableboolean
colorTypeColorTypes
Set color based on theme. If color is specified, that prop is used instead of this.
disabledboolean
Equivalent to button's disabled property.
keyboardClickKeysstring[]
loadingboolean
onBlurFocusEventHandler<HTMLDivElement>
onClickMouseEventHandler<HTMLDivElement>
onKeyDownKeyboardEventHandler<HTMLDivElement>
onKeyUpKeyboardEventHandler<HTMLDivElement>
onMouseDownMouseEventHandler<HTMLDivElement>
onMouseLeaveMouseEventHandler<HTMLDivElement>
onMouseUpMouseEventHandler<HTMLDivElement>
onReleaseEventHandler<SyntheticEvent<HTMLDivElement, Event>>
Callback that's triggered after click i.e. mouseup and keyup of enter or space.
onTouchEndTouchEventHandler<HTMLDivElement>
onTouchStartTouchEventHandler<HTMLDivElement>
radiusstring
sizeIconButtonSizes
tooltipReactNode
tooltipPropsOmit<TooltipProps, "title" | "children">
variantIconButtonVariantsflat
SelectButton
Prop nameTypeDefaultDescription
asany
Tag or component, but a simple tag (i.e. built-in components, e.g. div, span) is recommended.
disabledboolean
Equivalent to button's disabled property.
keyboardClickKeysstring[]
onBlurFocusEventHandler<HTMLDivElement>
onClickMouseEventHandler<HTMLDivElement>
onKeyDownKeyboardEventHandler<HTMLDivElement>
onKeyUpKeyboardEventHandler<HTMLDivElement>
onMouseDownMouseEventHandler<HTMLDivElement>
onMouseLeaveMouseEventHandler<HTMLDivElement>
onMouseUpMouseEventHandler<HTMLDivElement>
onReleaseEventHandler<SyntheticEvent<HTMLDivElement, Event>>
Callback that's triggered after click i.e. mouseup and keyup of enter or space.
onTouchEndTouchEventHandler<HTMLDivElement>
onTouchStartTouchEventHandler<HTMLDivElement>
placeholderReactNode
rightElementReactNode<SelectArrowIcon />
SelectEllipsisTooltip
Prop nameTypeDefaultDescription
activeboolean
arrowArrowProps
asany
Tag or component, but a simple tag (i.e. built-in components, e.g. div, span) is recommended.
closeDelaynumber
containerHTMLElement
containerPropsInnerProps
contentPropsInnerProps
immediateboolean
initialActiveboolean
initialImmediateboolean
maxRowsnumber
offset[number, number]
onActiveChange(active: boolean) => void
onImmediateChange(immediate: boolean) => void
onOverflowChange(overflow: boolean) => void
openDelaynumber
overflowboolean
placement"left" | "right" | "bottom" | "top" | "top-start" | "top-end" | "left-start" | "left-end" | "right-start" | "right-end" | "bottom-start" | "bottom-end"
popperOptionsPopperPopperOptions
Options for Popper.js instance
popperUpdateKeystring
renderChild(child: any, handlers: any, ariaAttrs: any) => ReactNode
springConfigPartial<AnimationConfig>
titleReactNode
titleContainerPropsHTMLAttributes<HTMLDivElement>
variantTooltipVariants
SelectHighlighter
Prop nameTypeDefaultDescription
textstring
SelectIconButton
Prop nameTypeDefaultDescription
asany
Tag or component, but a simple tag (i.e. built-in components, e.g. div, span) is recommended.
badgePropsOmit<BadgeProps, "children">
colorTypeColorTypes
Set color based on theme. If color is specified, that prop is used instead of this.
disabledboolean
Equivalent to button's disabled property.
keyboardClickKeysstring[]
loadingboolean
onBlurFocusEventHandler<HTMLDivElement>
onClickMouseEventHandler<HTMLDivElement>
onKeyDownKeyboardEventHandler<HTMLDivElement>
onKeyUpKeyboardEventHandler<HTMLDivElement>
onMouseDownMouseEventHandler<HTMLDivElement>
onMouseLeaveMouseEventHandler<HTMLDivElement>
onMouseUpMouseEventHandler<HTMLDivElement>
onReleaseEventHandler<SyntheticEvent<HTMLDivElement, Event>>
Callback that's triggered after click i.e. mouseup and keyup of enter or space.
onTouchEndTouchEventHandler<HTMLDivElement>
onTouchStartTouchEventHandler<HTMLDivElement>
radiusstring
showBadgeboolean
sizeIconButtonSizes
tooltipReactNode
tooltipPropsOmit<TooltipProps, "title" | "children">
variantIconButtonVariants
SelectList
Prop nameTypeDefaultDescription
asvoid | WebTarget
Tag or component, but a simple tag (i.e. built-in components, e.g. div, span) is recommended.
forwardedAsvoid | WebTarget
themeDefaultTheme
SelectListFooter
Prop nameTypeDefaultDescription
asany
Tag or component, but a simple tag (i.e. built-in components, e.g. div, span) is recommended.
SelectListSearch
Prop nameTypeDefaultDescription
asany
Tag or component, but a simple tag (i.e. built-in components, e.g. div, span) is recommended.
autoComplete"on" | "off" | "nope"
disabledboolean
fullWidthboolean
width: 100% is too troublesome to handle with custom css because of the nesting
invalidboolean
leftElementReactNode
leftElementContainerPropsHTMLAttributes<HTMLDivElement> & { ref?: MutableRefObject<HTMLDivElement>; }
onChange(e: ChangeEvent<HTMLInputElement>) => void
onTextChange(val: string) => void
placeholderReactNode
readOnlyboolean
rightElementReactNode
rightElementContainerPropsHTMLAttributes<HTMLDivElement> & { ref?: MutableRefObject<HTMLDivElement>; }
type"number" | "text" | "password"
wrapperPropsWrapperProps
SelectOption
Prop nameTypeDefaultDescription
asany
Tag or component, but a simple tag (i.e. built-in components, e.g. div, span) is recommended.
disabledboolean
indexnumber
leftElementReactNode
valueSelectValue
SelectSearch
Prop nameTypeDefaultDescription
asany
Tag or component, but a simple tag (i.e. built-in components, e.g. div, span) is recommended.
autoComplete"on" | "off" | "nope"
contentPropsSelectSelectedContentProps
disabledboolean
fullWidthboolean
width: 100% is too troublesome to handle with custom css because of the nesting
invalidboolean
leftElementReactNode
leftElementContainerPropsHTMLAttributes<HTMLDivElement> & { ref?: MutableRefObject<HTMLDivElement>; }
onChange(e: ChangeEvent<HTMLInputElement>) => void
onTextChange(val: string) => void
placeholderReactNode
readOnlyboolean
rightElementReactNode
rightElementContainerPropsHTMLAttributes<HTMLDivElement> & { ref?: MutableRefObject<HTMLDivElement>; }
type"number" | "text" | "password"
wrapperPropsWrapperProps
SelectVirtualizedList
Prop nameTypeDefaultDescription
acdcScrollerPropsOptionsUseAcdcScrollerPropsOptions
Options for the useAcdcScrollerProps hook
asany
Tag or component, but a simple tag (i.e. built-in components, e.g. div, span) is recommended.
containerHTMLElement
containerPropsDivProps
elevationLevelnumber
emptyPlaceholderReactNode<Result image={<EmptyBox size={64} />} description="No data" />
estimatedItemSizenumber
footerReactNode
headerReactElement<any, any>
immediateboolean
innerPropsHTMLAttributes<HTMLUListElement> & { as?: any; ref?: Ref<HTMLUListElement>; }
itemSize(index: number) => number() => 36
overscanCountnumber20
placement"left" | "right" | "bottom" | "top" | "top-start" | "top-end" | "left-start" | "left-end" | "right-start" | "right-end" | "bottom-start" | "bottom-end"
popperReferenceHTMLElement
popperUpdateKeystring
widthSelectListWidth
    Example
    Example
    Basic Usage
    Basic Usage
    Customization, Option Groups, and Other States
    Customization, Option Groups, and Other States
    Ellipsis Tooltip
    Ellipsis Tooltip
    onChange vs onSelect
    onChange vs onSelect
    Search
    Search
    Customize selected option rendering in input box
    Customize selected option rendering in input box
    Async Search
    Async Search
    Customizing Arrow Icon
    Customizing Arrow Icon
    Virtualized
    Virtualized
    Empty List Placeholder
    Empty List Placeholder
    Adding Tooltip Example
    Adding Tooltip Example
    Accessibility
    Accessibility
    References
    References
    API
    API
    Select
    Select
    SelectArrowIcon
    SelectArrowIcon
    SelectButton
    SelectButton
    SelectEllipsisTooltip
    SelectEllipsisTooltip
    SelectHighlighter
    SelectHighlighter
    SelectIconButton
    SelectIconButton
    SelectList
    SelectList
    SelectListFooter
    SelectListFooter
    SelectListSearch
    SelectListSearch
    SelectOption
    SelectOption
    SelectSearch
    SelectSearch
    SelectVirtualizedList
    SelectVirtualizedList
Coral is a thoroughly developed design system widely adopted by developers and designers for creating beautiful and user-friendly Sea internal products.

Copyright © 2018-2025 Sea Labs