Dropdown Panel
An accessible anchored dropdown panel — the positioning primitive, under 1 KB of CSS.
v2.1.1@magic-spells/dropdown-panel
Live demo
An anchored menu: open it with a click or the arrow keys, Escape closes it.
About
A lightweight, accessible dropdown, popover and mega menu web component.
Features
- 🪶 Dependency-free - 4.9 kB min + gzip (4.4 kB JS, 0.5 kB core CSS; the opt-in effects sheet adds 0.9 kB)
- 🎨 Minimal styling - the package sets positioning and open/closed state, and stops
- 🖱️ Hover, click, or both, per dropdown - trigger="hover|click|both", with optional hover intent delays
- 🔗 Nested submenus with opens="right"
- 📐 Full-width mega menus with wide
- ⌨️ Keyboard navigation - arrows, Home/End, and Escape one level at a time
Usage
<link rel="stylesheet" href="/node_modules/@magic-spells/dropdown-panel/dist/dropdown-panel.min.css" /> <script defer src="/node_modules/@magic-spells/dropdown-panel/dist/dropdown-panel.min.js"></script>
Attributes
| Attribute | Element | Default | Description |
|---|---|---|---|
| visible | absent | Open state. Reflected and observed - add or remove it and the panel follows. | |
| menu | absent | Application-menu semantics: menu roles, roving tabindex, typeahead, Tab to close, select events. See below. | |
| trigger | both | hover, click, both or contextmenu. | |
| open-delay | 0 | Milliseconds pointerenter waits before opening. Leaving first cancels it. Hover only. | |
| close-delay | 0 | Milliseconds pointerleave waits before closing a hover-opened panel. Re-entering cancels it. | |
| wide | absent | Full-width mega menu. width: 100%, host goes position: static. | |
| opens | down | right opens the panel beside the trigger instead of below it. For submenus. | |
| align | start | start or end. Which edge of a downward panel lines up with the trigger. Pure CSS; opens="right" ignores it. | |
| flip | absent | Opens the panel upward when it would run past the bottom of the viewport. Measured once per open. | |
| effect | none | fade, slide, scale, blur or swing. Requires the effects stylesheet; a no-op without it. | |
| arrow | flip | flip mirrors the trigger arrow on open, static leaves it alone, none hides it. Requires the effects stylesheet. | |
| arrow-shape | chevron | chevron or triangle. Drawn only when the arrow hook is empty. Requires the effects stylesheet. |
About, features, usage and options are taken from the package README.