Searching Open Sourcery

Type to search Open Sourcery.

Overlays & Panels

Dropdown Panel

An accessible anchored dropdown panel — the positioning primitive, under 1 KB of CSS.

v2.1.1@magic-spells/dropdown-panel

$ npm i @magic-spells/dropdown-panel

GitHubnpm

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

AttributeElementDefaultDescription
visibleabsentOpen state. Reflected and observed - add or remove it and the panel follows.
menuabsentApplication-menu semantics: menu roles, roving tabindex, typeahead, Tab to close, select events. See below.
triggerbothhover, click, both or contextmenu.
open-delay0Milliseconds pointerenter waits before opening. Leaving first cancels it. Hover only.
close-delay0Milliseconds pointerleave waits before closing a hover-opened panel. Re-entering cancels it.
wideabsentFull-width mega menu. width: 100%, host goes position: static.
opensdownright opens the panel beside the trigger instead of below it. For submenus.
alignstartstart or end. Which edge of a downward panel lines up with the trigger. Pure CSS; opens="right" ignores it.
flipabsentOpens the panel upward when it would run past the bottom of the viewport. Measured once per open.
effectnonefade, slide, scale, blur or swing. Requires the effects stylesheet; a no-op without it.
arrowflipflip mirrors the trigger arrow on open, static leaves it alone, none hides it. Requires the effects stylesheet.
arrow-shapechevronchevron 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.