Sponsor

Select

Select component is a component that allows users pick a value from predefined options. Ideally, it should be used when there are more than 5 options, otherwise you might consider using a radio group instead.

Import#

Usage#

Here's a basic usage of the Select component.

Editable Example

Changing the size of the Select#

There are three sizes of select : large (48px), default (40px) and small (32px).

Editable Example

Changing the appearance of the Select#

Just like the input component, select comes in 3 variants, outline, unstyled , flushed , and filled. Pass the variant prop and set it to either of these values.

Editable Example

Changing the icon in the Select#

As with most Chakra components, you can change the arrow icon used in the select. Simply pass the icon prop.

In case the custom icon size doesn't look right, you can pass the iconSize prop to change it.

🚨 This feature works in v0.5.1. Kindly upgrade if you need it

Editable Example

Overriding the styles of the Select#

Even though the select comes with predefined styles, you can override pretty much any property. Here's we'll override the background color.

Editable Example

Props#

The Select component composes PseudoBox so you can pass all PseudoBox props, and React.SelectHTMLAttributes.

NameTypeDefaultDescription
sizesm, md, lgmdThe visual size of the select element.
iconReact.ElementType, stringchevron-downThe icon to use in place if the chevron-down
iconSizeBoxProps['size']20pxThe visual size of the icon
iconColorBoxProps['color']The color of the icon
variantoutline, unstyled, flushed, filledoutlineThe variant of the select style to use.
focusBorderColorstringThe border color when the select is focused.
errorBorderColorstringThe border color when isInvalid is set to true.
isDisabledbooleanfalseIf true, the select will be disabled. This sets aria-disabled=true and you can style this state by passing _disabled prop.
isInvalidbooleanfalseIf true, the select will indicate an error. This sets aria-invalid=true and you can style this state by passing _invalid prop.
isRequiredbooleanfalseIf true, the select element will be required.
isReadOnlybooleanfalseIf true, prevents the value of the select from being edited.
rootPropsBoxPropsThe props to pass to the wrapper of the select. The select is wrapped in a Box to help align the icon, if you want to pass some props to that wrapper, use this prop

Proudly made in 🇳🇬

Released under the MIT License.

Copyright © 2020 Segun Adebayo