# Account menu

> Avatar-triggered popover with signed-in identity, account links, and a slot for actions such as signing out.

- Kind: ui · Category: Overlays · Interactivity: script
- Install: `npx shadcn@latest add @haze/account-menu`
- File: `src/components/haze/ui/account-menu.astro`
- npm dependencies: @lucide/astro
- Registry dependencies: @haze/avatar, @haze/dropdown-menu, @haze/utils
- Docs page: https://hazeui.com/ui/account-menu

## Use when
- A shell needs one place for personal settings and help links
- A narrow toolbar needs a compact avatar trigger with an accessible name

## Avoid when
- The menu controls an item unrelated to the current account. Use dropdown-menu.

## Alternatives
- [dropdown-menu](https://hazeui.com/ui/dropdown-menu.md)
- [popover](https://hazeui.com/ui/popover.md)
- [sidebar](https://hazeui.com/ui/sidebar.md)
- [avatar](https://hazeui.com/ui/avatar.md)

## Props

| Name | Type | Default | Required | Description |
|---|---|---|---|---|
| id | `string` |  | yes | Unique popover ID and CSS anchor name. |
| name | `string` |  | yes | Display name for the account and source of initials. |
| identifier | `string` |  | no | Optional account detail, such as an email address or handle. |
| avatarSrc | `string` |  | no | Optional avatar image URL. Without an image, the trigger shows an account icon and the panel shows initials. |
| items | `{ label: string; href: string; icon?: AstroComponent }[]` |  | yes | Links to account-related destinations. |
| compact | `boolean` | false | no | Hide the name in the trigger while keeping it inside the popover. |
| label | `string` | "Account menu" | no | Localized description announced after the account holder's name. |
| align | `"start" \| "end"` | "end" | no | Edge of the trigger to align with the popover. |
| side | `"bottom" \| "top"` | "bottom" | no | Preferred placement. Use top for a sidebar footer. |
| class | `string` |  | no | Additional classes on the wrapper. |

## Accessibility
- The trigger has a textual accessible name even in compact mode.
- Account links are native anchors and the popover preserves standard tab order.
- The actions slot can hold your application's authenticated sign-out form.
- Key Enter / Space: Toggle the account popover.
- Key Tab: Focus links and any supplied actions.
- Key Arrow keys / Home / End / Letters: Move among the account links or jump to one by name.
- Key Escape: Close the popover.

## Agent prompts

### Install and use

Install the Haze UI component "Account menu" with `npx shadcn@latest add @haze/account-menu`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "https://hazeui.com/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import AccountMenu from "@/components/haze/ui/account-menu.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: https://hazeui.com/ui/account-menu.md

### Customize with real content

Adapt the Haze account-menu ui for our product. Replace the demo values of these props with our real content: id, name, identifier, avatarSrc, items, compact, label, align, side, class. Keep the layout, the heading level rules and these accessibility details: The trigger has a textual accessible name even in compact mode. Account links are native anchors and the popover preserves standard tab order. The actions slot can hold your application's authenticated sign-out form. Do not add raw color classes; use the Haze tokens.

### Choose the right block

Before using account-menu, check it fits: use it when a shell needs one place for personal settings and help links; a narrow toolbar needs a compact avatar trigger with an accessible name. Avoid it when the menu controls an item unrelated to the current account. use dropdown-menu.. Alternatives: @haze/dropdown-menu, @haze/popover, @haze/sidebar, @haze/avatar.

## Example requests that should lead here
- Add an avatar menu with profile settings and help in the top bar
- Put a compact account menu at the bottom of the sidebar and pass a sign-out form

## Source

```astro
---
import { ChevronsUpDown, UserRound } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
import Avatar from "./avatar.astro";
import DropdownMenu from "./dropdown-menu.astro";

interface AccountLink { label: string; href: string; icon?: (props: Record<string, unknown>) => unknown }
interface Props {
  id: string;
  name: string;
  identifier?: string;
  avatarSrc?: string;
  items: AccountLink[];
  compact?: boolean;
  label?: string;
  align?: "start" | "end";
  side?: "bottom" | "top";
  class?: string;
}

const { id, name, identifier, avatarSrc, items, compact = false, label = "Account menu", align = "end", side = "bottom", class: className } = Astro.props;
---

<div class={cn("inline-block max-w-full", className)}>
  <DropdownMenu id={id} items={items} ariaLabel={`${name}, ${label}`} align={align} side={side} variant="ghost" class="w-60">
    <Fragment slot="trigger">
      {avatarSrc
        ? <span aria-hidden="true"><Avatar name={name} src={avatarSrc} size="sm" /></span>
        : <span class="grid size-6 shrink-0 place-items-center rounded-full border border-frame bg-muted text-muted-foreground" aria-hidden="true"><UserRound /></span>}
      {!compact && <span class="max-w-36 truncate text-[0.8125rem]/5">{name}</span>}
      <ChevronsUpDown aria-hidden="true" class="text-muted-foreground" />
    </Fragment>
    <div slot="header" class="mb-1 flex min-w-0 items-center gap-2.5 border-b border-border px-3 py-2.5">
      <span aria-hidden="true"><Avatar name={name} src={avatarSrc} /></span>
      <div class="min-w-0 wrap-anywhere">
        <p class="text-[0.8125rem]/5 font-medium">{name}</p>
        {identifier && <p class="text-[0.8125rem]/5 text-muted-foreground">{identifier}</p>}
      </div>
    </div>
    {Astro.slots.has("actions") && <div slot="actions" class="mt-1 border-t border-border pt-1"><slot name="actions" /></div>}
  </DropdownMenu>
</div>
```
