primitives
primitives copied to clipboard
Select
-
Accessibility (a11y) • Keyboard navigation: Support arrow keys, Enter, Space, Escape, and Tab for seamless navigation. • ARIA attributes: Properly set aria-expanded, aria-controls, aria-activedescendant, and aria-labelledby. • Focus management: Ensure correct focus handling when opening and closing the dropdown. • Screen reader support: The selected item and menu state should be clearly conveyed.
-
Headless & Unstyled Design • No built-in styles: Allow full customization through user-defined styles. • Slot or render prop pattern: Enable flexible UI customization.
-
Strong Type Safety (TypeScript Support) • Generic types: Use T extends string | number | symbol for type safety. • Well-defined TypeScript interfaces: Ensure proper typings for props and events.
-
Composable Architecture
The component should be modular and split into smaller parts: • <SelectRoot> – Wrapper component • <SelectTrigger> – The button that opens the dropdown • <SelectContent> – The dropdown list container • <SelectItem> – Individual selectable items • <SelectLabel> – Label for grouped items • <SelectGroup> – Used for grouping items • <SelectSeparator> – Divider between sections
-
Controlled & Uncontrolled Usage • Support v-model (for Vue users). • Provide internal state management for uncontrolled usage (useVModel or similar).
-
High Performance • Virtual scrolling: Optimize rendering when dealing with large option lists. • Debounced filtering: Prevent unnecessary re-renders when searching.
-
Animations & Positioning • Use a positioning library: Floating UI or Popper.js for proper menu placement. • Support Vue’s Transition API for smooth animations.
-
Asynchronous Data Handling • Lazy loading: Fetch options dynamically when needed. • Loading state: Display a loading indicator when fetching data.