# Select Component API A dropdown select component for choosing from a list of options. --- ## Installation ```toml # Cargo.toml [dependencies] shadcn-ui-leptos-select = "0.7" ``` ```rust use shadcn_ui_leptos_select::Select; ``` --- ## Import ```rust use shadcn_ui_leptos_select::{ Select, SelectTrigger, SelectContent, SelectItem, SelectValue, SelectLabel, SelectGroup, SelectSeparator }; ``` --- ## Component API ### Select Root component for the select dropdown. | Prop | Type | Default | Description | |------|------|---------|-------------| | `value` | `Signal` | **Required** | Selected value | | `on_change` | `Option>` | `None` | Change handler | | `disabled` | `Signal` | `false` | Disable select | | `placeholder` | `MaybeProp` | `"Select..."` | Placeholder text | | `children` | `Option` | `None` | Select content | ### SelectTrigger Button that opens the dropdown. | Prop | Type | Default | Description | |------|------|---------|-------------| | `class` | `MaybeProp` | `None` | Additional CSS classes | | `disabled` | `Signal` | `false` | Disable trigger | ### SelectContent Dropdown content container. | Prop | Type | Default | Description | |------|------|---------|-------------| | `class` | `MaybeProp` | `None` | Additional CSS classes | | `position` | `MaybeProp` | `Bottom` | Dropdown position | ### SelectItem Individual selectable option. | Prop | Type | Default | Description | |------|------|---------|-------------| | `value` | `String` | **Required** | Option value | | `disabled` | `Signal` | `false` | Disable option | ### SelectValue Display area for selected value. | Prop | Type | Default | Description | |------|------|---------|-------------| | `placeholder` | `MaybeProp` | `None` | Placeholder text | --- ## Usage Examples ### Basic Select ```rust use leptos::prelude::*; use shadcn_ui_leptos_select::*; #[component] pub fn MyComponent() -> impl IntoView { let (selected, set_selected) = signal("apple".to_string()); view! { } } ``` --- ## CSS Classes ```css .select-trigger { flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 } .select-content { relative z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md } .select-item { relative flex w-full cursor-pointer select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground } ``` --- ## Accessibility ### Keyboard Navigation | Key | Action | |-----|--------| | **Arrow Down** | Next option | | **Arrow Up** | Previous option | | **Enter** | Select option | | **Escape** | Close dropdown | --- ## TypeScript API ```typescript interface SelectProps { value: string; onChange?: (value: string) => void; disabled?: boolean; placeholder?: string; children?: React.ReactNode; } export const Select: React.FC; export const SelectTrigger: React.FC; export const SelectContent: React.FC; export const SelectItem: React.FC<{ value: string; disabled?: boolean; children: React.ReactNode }>; export const SelectValue: React.FC<{ placeholder?: string }>; ``` --- *Source: [packages/leptos/select/src/default.rs](https://github.com/yourusername/leptos-shadcn-ui/blob/main/packages/leptos/select/src/default.rs)*