Dropdown can open a menu or any other element when clicking or hovering.
Basic Example
Dropdown with menu items
await import('/components/actions/dropdown.js');
const { tags, $ } = Lightview;
const { div, Dropdown } = tags;
// Basic dropdown
const dropdown = Dropdown({},
Dropdown.Trigger({}, 'Click me'),
Dropdown.Content({},
Dropdown.Item({}, 'Profile'),
Dropdown.Item({}, 'Settings'),
Dropdown.Item({}, 'Logout')
)
);
$('#example').content(div({ style: 'height: 10rem;' }, dropdown));
Dynamic Menu
Dropdown with reactive menu items
await import('/components/actions/dropdown.js');
const { signal, tags, $ } = Lightview;
const { div, span, Dropdown } = tags;
const selected = signal('Select an option');
const options = ['🍎 Apple', '🍌 Banana', '🍊 Orange', '🍇 Grape'];
const dropdown = Dropdown({},
Dropdown.Trigger({ class: 'btn-primary' },
() => selected.value
),
Dropdown.Content({},
...options.map(opt =>
Dropdown.Item({
onclick: () => { selected.value = opt; }
}, opt)
)
)
);
const demo = div({ style: 'display: flex; gap: 1rem; align-items: center; height: 12rem;' },
dropdown,
span({ style: 'font-size: 0.875rem; opacity: 0.7;' },
() => `Selected: ${selected.value}`
)
);
$('#example').content(demo);
Props
| Prop | Type | Default | Description |
|---|---|---|---|
position |
string | - | 'top' | 'bottom' | 'left' | 'right' | 'end' |
hover |
boolean | false | Open on hover instead of click |
open |
boolean | false | Force open state |
Sub-components
| Component | Description |
|---|---|
Dropdown.Trigger |
The clickable element that toggles the dropdown |
Dropdown.Content |
The menu/content container |
Dropdown.Item |
Individual menu item |
Positions
Bottom
Top
Left
Right
Hover
Hover me