Dropdown
Versatile dropdown menus for navigation, actions, and selections with smooth animations - rebuilt with HeroUI architecture.
HeroUI Dropdown Variants
Standard Dropdown
Basic dropdown with text items
Dropdown with Icons
Enhanced dropdown with icon indicators
Multi-Select Dropdown
Dropdown with checkbox selection
Real Estate Use Cases
User Menu
Implementation Guide
HTML Structure
<!-- Standard Dropdown -->
<div class="lyd-dropdown">
<button class="lyd-dropdown-trigger" onclick="LYDDropdown.toggle('myDropdown')">
<span>Options</span>
<svg class="lyd-dropdown-icon">...</svg>
</button>
<div class="lyd-dropdown-menu" id="myDropdown">
<a href="#" class="lyd-dropdown-item">Option 1</a>
<a href="#" class="lyd-dropdown-item">Option 2</a>
<div class="lyd-dropdown-divider"></div>
<a href="#" class="lyd-dropdown-item">Option 3</a>
</div>
</div>
React/Next.js Component
import { useState, useRef, useEffect } from 'react';
interface DropdownProps {
trigger: React.ReactNode;
children: React.ReactNode;
align?: 'left' | 'right';
}
export const Dropdown = ({ trigger, children, align = 'left' }: DropdownProps) => {
const [isOpen, setIsOpen] = useState(false);
const dropdownRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) {
setIsOpen(false);
}
};
document.addEventListener('mousedown', handleClickOutside);
return () => document.removeEventListener('mousedown', handleClickOutside);
}, []);
return (
<div className="lyd-dropdown" ref={dropdownRef}>
<button
className={`lyd-dropdown-trigger ${isOpen ? 'active' : ''}`}
onClick={() => setIsOpen(!isOpen)}
>
{trigger}
</button>
<div className={`lyd-dropdown-menu ${align} ${isOpen ? 'active' : ''}`}>
{children}
</div>
</div>
);
};
API Reference
| Class | Description |
|---|---|
.lyd-dropdown |
Container for dropdown component |
.lyd-dropdown-trigger |
Button that opens the dropdown |
.lyd-dropdown-menu |
Dropdown menu container |
.lyd-dropdown-item |
Individual menu item |
.lyd-dropdown-divider |
Horizontal separator |
.lyd-dropdown-header |
Section header in dropdown |
.checkbox |
Checkbox style item |
.selected |
Selected state for checkbox items |
.active |
Open state for dropdown |
.right |
Right-aligned dropdown menu |
Accessibility & Best Practices
Keyboard Navigation
- Enter/Space to open dropdown
- Arrow keys to navigate items
- Escape to close dropdown
- Tab to move focus
Screen Reader Support
- Use aria-expanded on trigger
- Add role="menu" to dropdown
- Include aria-haspopup
- Announce selection changes
Best Practices
- Close on outside click
- Prevent viewport overflow
- Clear visual feedback
- Smooth animations
- Mobile-friendly touch targets