User menu
The app shell's account menu: a composition of ds::dropdown, ds::avatar, ds::dropdown-item, ds::badge and, in its slot, ds::theme-switcher.
Anatomy
┌─────────────────────────┐
│ (AL) Ada Lovelace ⌄ │ ← trigger: button[data-ds-user-menu-trigger]
│ [email protected] │ avatar (decorative), name, meta, icon-swap
└─────────────────────────┘
┌───────────────────────┐
│ (AL) Ada Lovelace Pro│ ← header [id=…-who]: avatar, name, email, badge
├───────────────────────┤
│ Profile │ ← default slot; adjacent role=group children
│ Settings │ parted by a hairline
├───────────────────────┤
│ Theme [☀][☾][▣] │ ← `theme` slot: theme-switcher variant=menu
├───────────────────────┤
│ ⇥ Sign out │ ← form[method=POST][data-ds-user-menu-sign-out]
└───────────────────────┘ > dropdown-item as=button (type=submit)
- Trigger: a plain
button, the dropdown's trigger. Full:w-full,p-1.5, a hover fill, ansmavatar, name andmeta ?? emailtruncated, and achevron-downds::icon-swap (rotate) that turns on the trigger'saria-expanded. Compact: the avatar alone,rounded-full,aria-label=name. - Ids: the header's is
{id}-who, whereidis the one passed in (it stays on the dropdown's root) or a hash of the name and email. Passing one is what lets a shell draw the menu in its rail and its phone drawer (SwitcherIdTest holds both, and the output without an id unchanged). - Panel: one
div[role=group]labelled by the header,w-64, capped at100vw - 1rem. - Groups:
*:[[role=group]+[role=group]]:addsmt-1 pt-1 border-tto a group that follows a group; the host writesrole="group"and a name. - Sign-out: a real POST form.
_tokenfromcsrf_token()(wrapped inrescue(), so a host with no session renders none), or the host'scsrfslot instead.
States
| State | Treatment |
|---|---|
| closed, open | The dropdown's: x-show, the menu transition, the chevron turned |
| hover, focus-visible | Trigger: bg-fg/5; the ring with outline-offset-2. Items: the dropdown's |
no signOutAction | No form, no sign-out item |
| compact | The avatar alone, rounded-full, the name in aria-label |
compactWhen | Both looks on one trigger: the server draws compact's, the expression swaps them (object-form x-bind:class, x-show on the name and chevron, a bound aria-label). Inside a collapsible ds::sidebar, its collapsed |
Phones
The brief asked for a ds::sheet below sm, rendered once. ds::dropdown and
ds::sheet are separate overlays with their own markup, state and focus code;
switching one set of items between them by breakpoint would mean rendering the
items twice, and the items hold a form, which must exist once. So it stays a
dropdown on phones, its panel capped to the viewport and placed by x-ds-anchor,
which flips and shifts it on screen.
Accessibility
| Trigger | button, aria-haspopup="menu", aria-expanded (the dropdown's) |
| Name | Full: its text, the name and line (the avatar is aria-hidden). Compact: aria-label = name |
| Menu | role=menu; items menuitem; the theme row menuitemradio + aria-checked |
| Group | Named by the header (aria-labelledby): name, email, plan |
| Keyboard | The dropdown's: arrows over every [role^=menuitem] not aria-disabled, wrapping; Home, End; Escape back to the trigger; Tab closes |
| Sign-out | A submit button in a POST form |
Do not
- Do not sign out with a link. A GET is followed by prefetchers and crawlers.
- Do not render the items twice for a second presentation.
- Do not nest menus.
- Do not put fields in it. Sign-out is a form with no fields; a dropdown discards what someone typed on Escape.
From the package repo: edit this page on GitHub.