Components
Select

Select

Import

import { VKSelect } from "@vivakits/react-components";

Basic Select

The Select component enables users to choose one or more options from a list. To configure the options, provide an array of objects with label and value properties. To control the option changing, pass a value prop and an onChange handler.

Select

Variants

The Select component offers two different variants, which can be selected using the variant prop.

Select
Select

Sizes

The Select component is available in four different sizes, adjustable via the size prop.

Select
Select
Select
Select

Rounded

The shape of the Select component can be customized with the rounded prop, allowing you to adjust the corner radius to achieve the desired level of roundness.

Select
Select
Select
Select
Select
Select
Select

Label

The label of the Select component can be modified using the label prop. You can position the label at the start, end, or horizontal positions. Additionally, you can customize the label's styling with the labelClassName prop.

Select
Select
Select

Required

You can designate the Select component as required by using the isRequired prop. This ensures that a selection must be made before the form can be submitted, enforcing mandatory user input.

Select

Show Cancel Button

The Select component includes an optional cancel button, which can be enabled using the showCancel prop. When this button is displayed and clicked, it will clear the current selection, resetting the value state to empty.

Select
Select

Show Divider

The Select component includes an optional divider, which can be displayed by setting the showDivider prop.

Select

Placeholder

The Select component features a placeholder that you can customize through the placeholder prop. By default, the placeholder text is set to 'Select'. This allows you to provide a temporary hint or prompt to users before they make a selection.

Select Color

Error

You can indicate an error state for the Select component by setting the hasError prop. When this prop is enabled, it visually highlights the component to signal to the user that there is an issue. Additionally, you can provide a custom error message through the errorMessage prop to give users more context about the error and how to address it.

Select
Custom error message

Loading State

You can designate the Select component as being in a loading state by utilizing the isLoading prop. When enabled, this visually indicates to users that the component is currently fetching or processing data, providing feedback on the ongoing operation.

Select

Menu Placement and Max Height

The Select component offers flexibility in menu placement, which can be adjusted using the menuPlacement prop. Additionally, you can customize the maximum height of the menu with the menuMaxHeight prop. By default, the menu is positioned at the bottom.

Select
Select

Is Multiple

The Select component supports multiple selections through the isMultiple prop. By default, selected options in the multiselect state are hidden. However, you can reveal them by using the showSelectedOptions prop. This allows users to easily view their selected options within the component.

Select
Select

Is Scrollable

By default, when multiple options can be chosen, the Select component automatically adjusts its height. However, by using the isScrollable prop, you can enforce a fixed height for the Select component, making it scrollable when necessary.

Select

Is Searchable

You can enable search functionality for the Select component by utilizing the isSearchable prop. When activated, this feature allows users to easily search and filter through the available options, enhancing usability, especially in scenarios with extensive lists of options.

No Options Message

The Select component includes a customizable message for scenarios where no options are available. This message can be tailored using the noOptionsMessage prop, allowing you to provide helpful guidance or instructions to users when the list of options is empty.

Select

Customize Icon

You have the option to display a checked icon next to selected options by using the optionsWithCheck prop. This icon can be customized using the checkedIcon prop. Since selected options are hidden by default in the multiselect state, you need to use the showSelectedOptions prop to reveal the checked icon. Additionally, you can customize the cross icon for selected values using the removeValueIcon prop.

Select
Select

Create Options

isCreatable determines whether the select component permits us to create new options. When a new option is created by us, the createOptionByAPI callback function is triggered. This function takes the newly created option as a parameter and can be utilized for additional actions, such as sending the new option to an API or logging it.

Disabled Option

isDisabled determines whether the select component is interactable.

Select

Dropdown Indicator

dropdownIndicator lets us customize the dropdown indicator icon.

Select
🔽

Customization

We can customize the options using the node property in the options array. And if we want to show the node in the selected value, we can use the showValueNode prop.

Select
Select

Customization with Utility Classes

We can customize our select component by passing an object of utility classes.

Select

API Reference

PropertyDescriptionTypeDefault
optionsArray of options to be displayed in the dropdownOption[][]
valueSelected valueOption | Option[]
onChangeCallback function to be called when the value changes(option: Option | Option[]) => void
vairantsolidoutlineChanges select appreancesolid
sizesmmdlgxlChanges select sizemd
roundeddefaultnonexssmmdlgfulllChanges the border radius of selectprimary
labelLabel for the select componentstring
labelPositionstartendhorizontalChanges the position of the labelstart
labelClassNameCustom utility classes for labelstring
isRequiredDesignates the select component as requiredbooleanfalse
showCancelDisplays a cancel button to clear the selectionbooleanfalse
showDividerDisplays a divider in the dropdownbooleanfalse
placeholderPlaceholder textstringSelect
hasErrorIndicates an error statebooleanfalse
errorMessageError message to displaystring
isLoadingIndicates a loading statebooleanfalse
menuPlacementPlacement of the dropdown menu'top' | 'bottom''bottom'
menuMaxHeightMaximum height of the dropdown menustring
isMultipleDesignates the select component as multiselectbooleanfalse
isScrollableDesignates the select component as scrollablebooleanfalse
isSearchableDesignates the select component as searchablebooleanfalse
noOptionsMessageMessage to display when no options are availablestring
optionsWithCheckDisplays a checked icon next to selected optionsbooleanfalse
checkedIconCustom icon for selected optionsReactNode
removeValueIconCustom icon for removing selected valuesReactNode
showSelectedOptionsReveals selected options in the multiselect statebooleanfalse
IsCreatableDesignates the select component as creatablebooleanfalse
IsDisabledDisables the select componentbooleanfalse
DropdownIndicatorCustom icon for dropdownReactNode
createOptionByAPICallback function to be called when a new option is created(newOption: Option) => void
stylesCustom utility classes for stylingStyles