# User Menu

> Source: https://design.nanatec.co.ke/components/user-menu/
> The signed-in person's avatar, opening their account menu: who they are, their links and actions, and sign out.

The user menu is the account corner of an app: the signed-in person's
[avatar](/components/avatar/) in the [top bar](/components/top-bar/), opening a menu that
starts with their name and email, lists their links and actions in groups, and ends with
sign out. It is a [menu button](/components/menu-button/) with that shape already given;
for any other list of commands, use the menu button itself.

## Preview

## Installation

```html
<nana-user-menu name="Wanjiru Kamau" email="wanjiru@example.com"></nana-user-menu>

<script type="module">
  const menu = document.querySelector('nana-user-menu');
  menu.groups = [
    {
      items: [
        { id: 'profile', label: 'Profile', href: '/profile' },
        { id: 'settings', label: 'Settings', href: '/settings' },
      ],
    },
    { heading: 'Help', items: [{ id: 'support', label: 'Contact support' }] },
  ];
  menu.addEventListener('nana-select', (event) => {
    if (event.detail.value === 'sign-out') location.assign('/sign-out');
  });
</script>
```

`groups` is a property, not an attribute. `nana-select` fires for every chosen item, links
included, with its `id` as `detail.value` and the item as `detail.item`.

## Showing the name

The trigger shows only the avatar. Set `show-name` (`showName` in Svelte) to put the name
and an arrow beside it, for a wide top bar where there is room.

## Keyboard

| Key | Does |
| --- | --- |
| Enter, Space or Down arrow on the trigger | Opens the menu on the first item |
| Up arrow on the trigger | Opens the menu on the last item |
| Up and Down arrows | Move between items, skipping disabled ones |
| Home and End | Go to the first or last item |
| Enter or Space | Chooses the item |
| Escape | Closes the menu and returns to the trigger |
| Tab | Closes the menu and moves on |

A press outside the menu also closes it.

## Accessibility

- The trigger is named by `label` and the person's name: "Account, Wanjiru Kamau". The
  avatar and the name shown beside it are hidden from screen readers, so the name is not
  read twice.
- The menu is named by `label`, "Account" by default.
- Linked items are links with the menu item role; a disabled one is not a link at all.

## API
