Skip to main content

Select

Quick start

Here's a quick start guide to get started with the Select component

Importing Component

import { Select } from "@hover-design/react";

Code Snippets and Examples

Select Default
const options = [
{ label: "First", value: "first" },
{ label: "Second", value: "second", disabled: true },
{ label: "Third", value: "third" },
{ label: "Fourth", value: "fourth" }
];

<div className="App">
<Select options={options} />
</div>;
Select with Label
const options = [
{ label: "First", value: "first" },
{ label: "Second", value: "second", disabled: true },
{ label: "Third", value: "third" },
{ label: "Fourth", value: "fourth" }
];

<div className="App">
<Select label="This is a Select Label" options={options} />
</div>;
Select Rounded
const options = [
{ label: "First", value: "first" },
{ label: "Second", value: "second", disabled: true },
{ label: "Third", value: "third" },
{ label: "Fourth", value: "fourth" }
];

<div className="App">
<Select borderRadius="20px" options={options} />
</div>;
Select Searchable (ComboBox)
const options = [
{ label: "First", value: "first" },
{ label: "Second", value: "second", disabled: true },
{ label: "Third", value: "third" },
{ label: "Fourth", value: "fourth" }
];

<div className="App">
<Select placeholder="Search Here!" isSearchable options={options} />
</div>;
Select Clearable
const options = [
{ label: "First", value: "first" },
{ label: "Second", value: "second", disabled: true },
{ label: "Third", value: "third" },
{ label: "Fourth", value: "fourth" }
];

<div className="App">
<Select isClearable options={options} />
</div>;
Select Error
const options = [
{ label: "First", value: "first" },
{ label: "Second", value: "second", disabled: true },
{ label: "Third", value: "third" },
{ label: "Fourth", value: "fourth" }
];

<div className="App">
<Select error="This is an error" options={options} />
</div>;
This is an error
Select Loading
const options = [
{ label: "First", value: "first" },
{ label: "Second", value: "second", disabled: true },
{ label: "Third", value: "third" },
{ label: "Fourth", value: "fourth" }
];

<div className="App">
<Select options={options} isLoading />
</div>;
Select with Loading Options
const options = [
{ label: "First", value: "first" },
{ label: "Second", value: "second", disabled: true },
{ label: "Third", value: "third" },
{ label: "Fourth", value: "fourth" },
];

const loadingOptions = {
loadingContent: "Data is Loading",
loader: <Loader color="orange" />,
}

<div className="App">
<Select options={options} isLoading loadingOptions={loadingOptions} />
</div>;
Select Disabled
const options = [
{ label: "First", value: "first" },
{ label: "Second", value: "second", disabled: true },
{ label: "Third", value: "third" },
{ label: "Fourth", value: "fourth" }
];

<div className="App">
<Select isDisabled options={options} />
</div>;
Controlled Select
const [selectedValue, setSelectedValue] = useState("first");

const options = [
{ label: "First", value: "first" },
{ label: "Second", value: "second", disabled: true },
{ label: "Third", value: "third" },
{ label: "Fourth", value: "fourth" }
];

<div className="App">
<Select
value={selectedValue}
onChange={(value) => setSelectedValue(value)}
options={options}
/>
</div>;
MultiSelect
const options = [
{ label: "First", value: "first" },
{ label: "Second", value: "second", disabled: true },
{ label: "Third", value: "third" },
{ label: "Fourth", value: "fourth" }
];

<div className="App">
<Select isMulti options={options} />
</div>;

Note: All the above mentioned combinations Eg. Searchable, Cleareable, Disabled etc...are also present with MultiSelect

Props Reference

AttributesValuesDefault ValueOptional ?
placeholderstringPick oneYes
labelstringYes
optionsArray of Options ObjectNo
valueOptions Object
when isMulti is true then value is
Array of Options Object
Yes
isMultibooleanfalseYes
colorstring#2F80EDYes
widthstring100%Yes
isSearchablebooleanfalseYes
errorbooleanfalseYes
maxDropDownHeightstringautoYes
minHeightstring40pxYes
zIndexstring1Yes
borderRadiusstring0Yes
onChange(selectedOption,event)=>void()=>{}Yes
isDisabledbooleanfalseYes
isClearablebooleanfalseYes
nothingFoundLabelstring | JSX ElementNothing Found!Yes
DropIconJSX ElementYes
onDropDownOpen()=> void Yes
onDropDownClose()=> void Yes
isLoadingbooleanfalseYes
useDropdownPortalbooleanfalseYes
closeDropdownPortalOnScrollbooleanfalseYes
useSerialSearchbooleanfalseYes
loadingOptionsLoading OptionsfalseYes

Option Object

KeytypeOptional ?
labelstringNo
valuestring | numberNo
disabledbooleanYes
refMutableRefObject<HTMLDivElement>Yes

Loading Option

KeytypeOptional ?
loadingContentReactNodeYes
loaderReactNodeYes

Keyboard Controls

Keyboard controls will only work when the Select is focused (selected)

Keytype
SpaceOpens Options List
ArrowDownNext Option
ArrowUpPrevious Option
Home if not disabled
First Option
End if not disabled
Last Option
Backspace if isMulti
Clears the last selected pill