Skip to main content

Select

The Select component provides a customizable dropdown menu for choosing one option from a list. It supports searchable options, error display, disabled state, embedded style, and integration with React Hook Form.

import { Select } from "tawuniya/components";

👉 View in Storybook


Props​

PropTypeDefaultDescription
labelstring—Placeholder text when no option is selected.
options{ value: string; label: string | ReactNode }[]—Array of options to display.
valuestring—Selected value (controlled).
size"sm" | "md" | "lg""md"Size of the select button.
searchableboolean—Enable search input inside the dropdown.
searchTextstring—Placeholder text for the search input.
emptyTextstring—Message to show when no options match the search.
errorstring—Error message displayed below the select.
embeddedbooleanfalseIf true, makes the select background transparent.
disabledbooleanfalseDisables the select input.
classNamestring—Additional Tailwind classes for the select button.
bodyClassstring—Additional Tailwind classes for the dropdown content.
wrapperClassNamestring—Additional Tailwind classes for the wrapper.
onChange(value: string) => void—Callback triggered when an option is selected.
form{ controller: any; control: any; name: string }—React Hook Form integration using Controller.
modalbooleantrueThe modality of the popover. When set to false, users can interact with elements outside the popover, and the popover content does not restrict focus or visibility.
getOptionsLabelstring—Key for option label.
getOptionsValuestring—Key for option value.
displayValuebooleanfalseIf true, displays the selected value instead of the label.

Usage​

With Controlled Form​

export default function BasicExample() {
const [value, setValue] = useState<string>("");

return (
<Select
label="Select an option"
options={[
{ label: "Option 1", value: "1" },
{ label: "Option 2", value: "2" },
]}
value={value}
onChange={setValue}
/>
);
}

Searchable Dropdown​

<Select
label="Searchable Select"
searchable
options={[
{ label: "Option 1", value: "1" },
{ label: "Option 2", value: "2" },
]}
/>

With Error Message​

<Select
label="Select an option"
options={[
{ label: "Option 1", value: "1" },
{ label: "Option 2", value: "2" },
]}
error="This field is required"
/>

Disabled State​

<Select
label="Disabled"
options={[
{ label: "Option 1", value: "1" },
{ label: "Option 2", value: "2" },
]}
disabled
/>

Without Portal​

<Sheet>
<SheetTrigger>Open</SheetTrigger>
<SheetContent>
<Select
label="Disabled"
options={[
{ label: "Option 1", value: "1" },
{ label: "Option 2", value: "2" },
]}
withoutPortal
/>
</SheetContent>
</SheetTrigger>

With React Hook Form​

import { useForm, Controller } from "react-hook-form";
import { Select } from "tawuniya/components";

export default function FormExample() {
const { control, handleSubmit } = useForm({
defaultValues: { option: "" },
});

const onSubmit = (data: any) => console.log(data);

return (
<form onSubmit={handleSubmit(onSubmit)}>
<Select
form={{ controller: Controller, control, name: "option" }}
options={[
{ label: "Option 1", value: "1" },
{ label: "Option 2", value: "2" },
]}
/>
<button type="submit">Submit</button>
</form>
);
}

With Custom Keys​

<Select
label="Select an option"
options={[
{ name: "Option 1", id: "1" },
{ name: "Option 2", id: "2" },
]}
value="2"
getOptionsLabel="name"
getOptionsValue="id"
/>

Notes​

  • Works as a controlled component with value + onChange, or with React Hook Form via the form prop.
  • Supports searchable dropdown with dynamic filtering.
  • Automatically displays error messages below the select.