The Select component provides a dropdown selection interface that allows users to choose from a list of options. It's designed for forms and settings where users need to select from predefined options.
import { Select } from '@dashflowx/core'export default function SelectExample() {const items = [{ id: 'option1', itemElement: 'Option 1' },{ id: 'option2', itemElement: 'Option 2' },{ id: 'option3', itemElement: 'Option 3' }];return (<Selectitems={items}selected="option1"isOpen={false}onClose={() => {}}/>)}
Preview:
| Prop | Type | Default | Description |
|---|---|---|---|
items | Array<iSelectItems> | [] | Array of select items |
selected | string | - | Currently selected item ID |
isOpen | boolean | false | Whether the dropdown is open |
onClose | function | - | Function to close the dropdown |
interface iSelectItems {id: string;itemElement: JSX.Element;}
import { Select } from '@dashflowx/core'export default function BasicSelect() {const items = [{ id: 'option1', itemElement: 'Option 1' },{ id: 'option2', itemElement: 'Option 2' },{ id: 'option3', itemElement: 'Option 3' }];return (<Selectitems={items}selected="option1"isOpen={false}onClose={() => {}}/>)}
Preview:
import { Select } from '@dashflowx/core'export default function CustomStyledSelect() {const items = [{ id: 'option1', itemElement: 'Option 1' },{ id: 'option2', itemElement: 'Option 2' },{ id: 'option3', itemElement: 'Option 3' }];return (<Selectitems={items}selected="option1"isOpen={false}onClose={() => {}}className="border border-blue-500 rounded-lg p-4"/>)}
Preview:
import { Select } from '@dashflowx/core'export default function FormSelect() {const items = [{ id: 'male', itemElement: 'Male' },{ id: 'female', itemElement: 'Female' },{ id: 'other', itemElement: 'Other' }];return (<Selectitems={items}selected="male"isOpen={false}onClose={() => {}}/>)}
Preview:
import { Select } from '@dashflowx/core'export default function SettingsSelect() {const items = [{ id: 'light', itemElement: 'Light Theme' },{ id: 'dark', itemElement: 'Dark Theme' },{ id: 'auto', itemElement: 'Auto' }];return (<Selectitems={items}selected="auto"isOpen={false}onClose={() => {}}/>)}
Preview:
import { Select } from '@dashflowx/core'export default function LanguageSelection() {const items = [{ id: 'en', itemElement: 'English' },{ id: 'es', itemElement: 'Spanish' },{ id: 'fr', itemElement: 'French' },{ id: 'de', itemElement: 'German' }];return (<Selectitems={items}selected="en"isOpen={false}onClose={() => {}}/>)}
Preview:
const genderSelection = (<Selectitems={[{ id: 'male', itemElement: 'Male' },{ id: 'female', itemElement: 'Female' },{ id: 'other', itemElement: 'Other' }]}selected="male"isOpen={false}onClose={() => {}}/>);
const themeSelection = (<Selectitems={[{ id: 'light', itemElement: 'Light' },{ id: 'dark', itemElement: 'Dark' },{ id: 'auto', itemElement: 'Auto' }]}selected="auto"isOpen={false}onClose={() => {}}/>);
const languageSelection = (<Selectitems={[{ id: 'en', itemElement: 'English' },{ id: 'es', itemElement: 'Spanish' },{ id: 'fr', itemElement: 'French' }]}selected="en"isOpen={false}onClose={() => {}}/>);
const sizeSelection = (<Selectitems={[{ id: 'small', itemElement: 'Small' },{ id: 'medium', itemElement: 'Medium' },{ id: 'large', itemElement: 'Large' }]}selected="medium"isOpen={false}onClose={() => {}}/>);
Use clear and descriptive options for select items.
// ✅ Good - Clear optionsconst items = [{ id: 'light', itemElement: 'Light Theme' },{ id: 'dark', itemElement: 'Dark Theme' }];// ❌ Avoid - Unclear optionsconst items = [{ id: 'opt1', itemElement: 'Option 1' },{ id: 'opt2', itemElement: 'Option 2' }];
Set logical default values based on context.
// ✅ Good - Logical default<Select selected="auto" />// ❌ Avoid - Random default<Select selected="option2" />
Maintain consistent styling across select components.
// ✅ Good - Consistent styling<Select className="standard-select-style" />// ❌ Avoid - Inconsistent styling<Select className="random-styles" />
Ensure all select options are accessible.
// ✅ Good - Accessible optionsconst items = [{ id: 'option1', itemElement: 'Option 1' }];// ❌ Avoid - Inaccessible optionsconst items = [{ id: 'option1', itemElement: '' }];
Use unique IDs for each select option.
// ✅ Good - Unique IDsconst items = [{ id: 'theme-light', itemElement: 'Light' },{ id: 'theme-dark', itemElement: 'Dark' }];// ❌ Avoid - Duplicate IDsconst items = [{ id: 'option', itemElement: 'Light' },{ id: 'option', itemElement: 'Dark' }];
You can customize the select appearance using CSS classes:
<Selectitems={items}selected="option1"isOpen={false}onClose={() => {}}className="border border-gray-300 rounded-lg p-4"/>
Use different themes for different contexts:
// Light theme<Select className="bg-white border-gray-200" />// Dark theme<Select className="bg-gray-900 border-gray-700 text-white" />// Brand theme<Select className="bg-blue-50 border-blue-200" />
Use different sizes for different emphasis levels:
// Small select<Select className="text-sm" />// Standard select<Select className="text-base" />// Large select<Select className="text-lg" />
Load select options dynamically:
const [selectOptions, setSelectOptions] = useState([]);useEffect(() => {// Load options based on user permissionsloadSelectOptions().then(setSelectOptions);}, []);
Show/hide select options based on conditions:
const getSelectOptions = (userRole) => {const baseOptions = [{ id: 'basic', itemElement: 'Basic' }];if (userRole === 'admin') {baseOptions.push({ id: 'admin', itemElement: 'Admin' });}return baseOptions;};
Handle select state:
const [selectedValue, setSelectedValue] = useState('option1');const handleSelectChange = (value) => {setSelectedValue(value);// Handle value change};
- RadioGroup: For single selections
- Checkbox: For multiple selections
- Switch: For toggle options
- Form: For form containers
- Label: For form labels
For the complete API reference and advanced usage patterns, see the Select API documentation.
