Select

A Select or ComboBox component is a UI element that allows users to choose one or more options from a dropdown list. It typically displays a default value or prompt, and when clicked, it expands to show a list of available choices. Users can either select an option from the list or, in the case of a ComboBox, input custom values. This component is ideal for conserving space in forms and making it easy for users to make selections quickly.

Demo

Rendered live, with the same build of the library you install.

Usage

Select.tsx
import { useEffect, useState } from 'react';
import { NSelect } from '@nayan-ui/react';
const options = [
{ value: 'startup', label: 'Startup' },
{ value: 'business', label: 'Business' },
{ value: 'enterprise', label: 'Enterprise' }
];
const Select = () => {
const [selected, setSelected] = useState<{ value: string; label: string } | null>(options[0]);
// Client-only: react-select reads a null emotion cache during SSR and takes the page to a 500.
const [mounted, setMounted] = useState(false);
useEffect(() => setMounted(true), []);
return (
<div>
{mounted ? (
<NSelect label="Business Type" placeholder="Select plan" options={options} value={selected} onChange={val => setSelected(val)} />
) : (
<div className="h-[68px] animate-pulse rounded-lg border border-default bg-surface" aria-hidden />
)}
</div>
);
};
export default Select;

Attributes

21 props
NameTypeDefaultDetails
isMultibooleanfalseYou can pass isMulti option to switch between single / multi select.
labelstringOptionalLabel for the select field.
placeholderstringOptionalPlaceholder text for the select.
isLoadingbooleanfalseWhether the select is in loading state.
isCreatablebooleanfalseWhether new options can be created.
isClearablebooleanfalseWhether the selection can be cleared.
isSearchablebooleantrueWhether the select is searchable.
disabledbooleanfalseWhether the select is disabled.
classNamestring' 'You can customise by passing tailwind classes.
labelClassNamestring' 'You can customise by passing tailwind classes.
selectClassNamestring' 'You can customise by passing tailwind classes.
valueOptionType | OptionType[] | nullRequiredSelected value(s).
optionsOptionType[]RequiredArray of available options.
onCreateOption(inputValue: string) => voidOptionalCallback when new option is created.
onChange(value: OptionType | OptionType[] | null) => voidOptionalCallback when selection changes.
onChangeOptions(value: OptionType | OptionType[] | null) => voidOptionalAlternative change callback.
getOptionLabel(option: OptionType) => stringOptionalFunction to get option label.
getOptionValue(option: OptionType) => stringOptionalFunction to get option value.
inputIdstringOptionalID for the input element.
namestringOptionalName attribute for the select.
menuPortalTargetHTMLElementOptionalTarget element for menu portal.

Tags

Other components solving nearby problems.