Searching Puzzle Pieces

Type to search Puzzle Pieces.

Dropdown Panel

The shared base for every trigger-and-panel overlay in the registry: a hover or click disclosure whose panel is positioned entirely in CSS, with nested submenus, full-width mega panels, one-open-at-a-time arbitration, and a complete arrow-key and Escape model.

This piece is a wrapper, not a port: it renders the real <dropdown-component>, <dropdown-trigger> and <dropdown-panel> custom elements from @magic-spells/dropdown-panel and binds attributes to them. The value down there is interaction — hover intent, the invisible hover bridge that keeps the pointer inside while it crosses to the panel, the latch from hover-open to click-open, and a keyboard model that answers only in the innermost open panel. None of it is worth forking. Nothing visual is down there at all: the component's stylesheet declares no colours and no custom properties, so every pixel of chrome on this page is Tailwind on our side.

It is a family: one import, three members invoked with dot notation. Other pieces build on it rather than repeating it — Navigation Menu is the first.

Installation

Copy the family into your app — it compiles with your build and the code is yours:

puzzle add piece dropdown-panel

It has a runtime dependency: the web component it wraps.

npm install @magic-spells/dropdown-panel

Then merge its stylesheets into your app's style entry (app/styles/styles.css). The first is required — the positioning, the open and closed states and the hover bridge all live there, so the piece does nothing without it. The second is optional: it adds the five entrance effects and draws the trigger arrow, and without it effect, arrow and arrowShape are no-ops.

/* app/styles/styles.css */
@import "tailwindcss";
@import "@magic-spells/dropdown-panel/css" layer(components);         /* required */
@import "@magic-spells/dropdown-panel/css/effects" layer(components); /* optional */

layer(components) is not decoration. Both sheets style plain element selectors, so an unlayered import would outrank every Tailwind utility you put on these elements. In the components layer the normal mental model holds: your utilities win, the component's defaults fill in the rest.

Requires the pieces.css tokens merged into your app styles (see Introduction).

Usage

import DropdownPanel from '@/components/ui/DropdownPanel';
<DropdownPanel>
  <DropdownPanel.Trigger class="rounded-md px-3 py-2 text-sm font-medium">
    Menu<span data-dropdown-arrow aria-hidden="true"></span>
  </DropdownPanel.Trigger>
  <DropdownPanel.Panel>
    <a href="/one" class="block rounded-md px-3 py-2 text-sm hover:bg-surface-sunken">One</a>
    <a href="/two" class="block rounded-md px-3 py-2 text-sm hover:bg-surface-sunken">Two</a>
  </DropdownPanel.Panel>
</DropdownPanel>

The trigger and the panel must be direct children. The component resolves them with a child selector, so never wrap either one in a div, and never put an {#if} around one at that level — move the condition inside the member instead. A Puzzle component renders its own single root and adds no wrapper, which is exactly why the members compose cleanly.

The arrow is a real child element.<span data-dropdown-arrow aria-hidden="true"></span>, closed tight — the effects sheet draws the glyph only when the hook is :empty, and whitespace counts as content. It can never be a ::before on the trigger: that pseudo-element is the package's hover bridge, and overwriting it breaks pointer travel to the panel.

Derived output, never authored. role, tabindex, aria-haspopup, aria-expanded and aria-controls on the trigger, and aria-hidden and inert on the panel, are written by the component and will overwrite anything you put there.

Alignment and effects

align="end" is the package's own right-align recipe (left: auto; right: 0) as two utilities. There is no measuring pass and nothing to re-run on resize. The second menu is trigger="click", so hovering it does nothing.

Controlled open

AccountProfileBillingSign outshow: 0 · hide: 0

open is optional-controlled and edge-triggered: leave it off and the component owns its own state, which is the normal case. Pass it and only a change acts, so an unrelated re-render can never re-open a panel the user just dismissed. The dropdown still closes itself on Escape, an outside press or another dropdown opening, and reports it through @hide — flip your flag back there so the next open is a fresh edge.

Reference

Every attribute prop renders no attribute at all when unset, so the component's own default applies.

DropdownPanel

trigger'hover' | 'click' | 'both' (default). hover falls back to click where (hover: hover) does not match, so a menu is never unopenable on a phone.
arrow'flip' (default) | 'static' | 'none' — how the drawn trigger arrow behaves. Effects stylesheet only.
arrowShape'chevron' (default) | 'triangle'. Drawn only when the [data-dropdown-arrow] hook is empty. Effects stylesheet only.
effectDurationCSS time for the entrance effect and the arrow flip. Reaches only panels that carry an effect — the core fade is a fixed 200ms.
effectEasingCSS easing for the same.
openOptional-controlled and edge-triggered. Omit it and the component owns its own state.
@show / @hideFired when THIS dropdown opens or closes. The component’s events bubble, so a nested submenu’s are filtered out by target.
classMerged onto <dropdown-component>.

DropdownPanel.Trigger

classMerged onto <dropdown-trigger>. There are no other props — role, tabindex, aria-haspopup, aria-expanded and aria-controls are written by the component.

DropdownPanel.Panel

wideA full-width mega panel. The host goes position: static, so the panel spans the nearest POSITIONED ANCESTOR — give the bar it should span position: relative.
opens'down' (default) | 'right'. right puts the panel beside its trigger and rotates the hover bridge onto the horizontal axis — what a submenu wants.
effect'fade' | 'slide' | 'scale' | 'blur' | 'swing'. Needs the effects stylesheet; degrades to a plain fade under prefers-reduced-motion.
align'start' (default) | 'end'. end is left-auto right-0 — pure CSS, no measuring pass. Ignored on a wide panel and on opens="right", where it is meaningless.
classMerged onto the panel. Merging is not precedence: use the ! suffix (mt-1!) to override a default. Never overflow-hidden — it clips a Sub.

Keyboard

Enter / SpaceOn the trigger: toggle.
ArrowDown / ArrowUpOn a closed trigger: open and focus the first (or last) item. Inside an open panel: move item focus, wrapping at the ends.
Home / EndInside an open panel: first / last item.
ArrowRightOn a submenu trigger with opens="right": open it and focus the first item.
ArrowLeftInside an opens="right" panel: close it and return focus to its trigger.
EscapeClose this level only, and focus its trigger. Only the innermost open dropdown answers.
TabNormal tab order. A closed panel is inert, so its contents are skipped.

All of it is upstream. This piece adds no key handling, no timers and no document listeners of its own.