Aller au contenu principal

Select Component

Description

The Select component provides a dropdown for selecting options, with support for filtering, free text input, and clearing the selected value.

Props

PropTypeDefaultDescription
idstring-Unique identifier for the input.
labelstring-Label for the input field.
optionsany[][]Array of options for selection.
loadingbooleanfalseDisplays a loading indicator if true.
freeSolobooleanfalseAllows free text input.
disabledbooleanfalseDisables the select input.
fullWidthbooleanfalseIf true, the input takes up the full width of its container.
valueany-The current selected value.
onChange(event, value) => void-Callback when an option is selected.
onInputChange(event, value, reason) => void-Callback when the input value changes.
getOptionLabel(option: any) => stringExtracts label from optionFunction to determine how options are displayed.
onOpen() => void-Callback when the dropdown opens.
onBlur(event) => void-Callback when the input loses focus.
onFocus(event) => void-Callback when the input gains focus.
variant"outlined" | "filled" | "standard""outlined"Defines the visual style of the input.
disablePortalbooleanfalseRenders the dropdown inline instead of inside a portal.
showClearButtonbooleantrueDisplays a button to clear the selection.
selectOnlybooleanfalseDisables typing and allows selection only.

Example Usage

import { useState } from "react";
import { Select, MenuItem } from "@nomana-it/liberty-core"

export const SelectExample = () => {
const [value, setValue] = useState(null);

const options = [
{ value: 1, label: "Option 1" },
{ value: 2, label: "Option 2" },
{ value: 3, label: "Option 3" }
];

return (
<Select
id="example-select"
label="Select an Option"
options={options}
value={value}
onChange={(event, newValue) => setValue(newValue)}
/>
);
};

🔗 GitHub Repository (Core): Liberty Core
🔗 GitHub Repository (Test Project): Liberty Test
📖 Live Documentation: Liberty Core Docs
💖 Sponsor & Support: Sponsor Liberty Core