Overview
HuxDropdown
is a versatile dropdown/select component that provides multiple visual variants, sizes, and supports custom item rendering with icons. It adapts seamlessly to light and dark themes.
Basic Usage
Variants
HuxDropdown supports four visual variants through theHuxButtonVariant
enum:
Primary
The default variant with a filled background using the primary color.
Secondary
A subtle variant with a light background and border.
Outline
A transparent dropdown with only a border outline.
Ghost
A minimal transparent dropdown without borders.
States
Default
Shows the placeholder text when no value is selected.
Expanded
Shows the dropdown panel with options.
Selected
Shows the selected option.
Disabled
Prevents user interaction.
Sizes
HuxDropdown supports three size variants through theHuxButtonSize
enum:
Small
Compact size for tight spaces (32px height).
Medium
Default size for most use cases (40px height).
Large
Prominent size for important selections (48px height).
With Icons
Enhance dropdown items with icons.
Custom Colors
Override the primary color of the dropdown.
API Reference
HuxDropdown Properties
Property | Type | Default | Description |
---|---|---|---|
items | List<HuxDropdownItem<T>> | required | List of dropdown items |
value | T? | null | Currently selected value |
onChanged | ValueChanged<T>? | null | Called when selection changes |
placeholder | String | 'Select' | Text shown when no value is selected |
variant | HuxButtonVariant | outline | Visual style of the dropdown |
size | HuxButtonSize | medium | Size of the dropdown |
primaryColor | Color? | null | Optional primary color override |
enabled | bool | true | Whether the dropdown is enabled |
maxHeight | double | 200 | Maximum height of the dropdown panel |
HuxDropdownItem Properties
Property | Type | Default | Description |
---|---|---|---|
value | T | required | The value associated with this item |
child | Widget | required | The widget to display for this item |
Accessibility
HuxDropdown includes several accessibility features:Automatic Contrast
Text color is automatically calculated to ensure WCAG AA compliance (4.5:1 contrast ratio) against any background color.Keyboard Navigation
- Arrow keys to navigate items
- Enter/Space to open/close and select
- Escape to close dropdown
Focus States
Proper focus management and visible focus indicators.Semantic Labels
Clear labels and roles for screen readers.Best Practices
Choose the Right Size
Choose the Right Size
- Use Large for primary selection fields
- Use Medium for most standard forms
- Use Small for compact interfaces or filters
Clear Labels
Clear Labels
- Use descriptive placeholders
- Group related dropdowns logically
- Consider adding helper text for complex selections
Item Organization
Item Organization
- Keep items concise
- Use icons to enhance visual scanning
- Order items logically (e.g., alphabetically)