Hoppa till huvudinnehåll

Menu

Meny, menylist, kontextmeny

En meny kan användas för att samla ihop funktioner som sällan används eller som kompletterar nuvarande funktion.

import { Button, Menu, MenuItem, MenuPopover, MenuTrigger } from '@midas-ds/components'
import { MenuIcon } from 'lucide-react'
<MenuTrigger>
<Button
aria-label='Menu'
variant='icon'
>
<MenuIcon size={20} />
</Button>
<MenuPopover>
<Menu>
<MenuItem>Open</MenuItem>
<MenuItem>Rename...</MenuItem>
<MenuItem>Duplicate</MenuItem>
<MenuItem>Share...</MenuItem>
<MenuItem>Delete...</MenuItem>
</Menu>
</MenuPopover>
</MenuTrigger>

Beskrivning

Komponenten bygger på React Aria Menu, kodexempel i React Arias dokumentation är applicerbara genom att importera komponeterna från @midas-ds/components.

Midas exporterar följande komponenter och typer:

  • Menu & MenuProps
  • MenuItem & MenuItemProps
  • MenuPopover & MenuPopoverProps
  • MenuSection & MenuSectionProps
  • Separator & SeparatorProps
  • MenuTrigger & MenuTriggerProps

Länkar

React Arias dokumentation visar exempel på hur menyn kan innehålla länkar. Länkar i en meny är tillåtna så länge menyns syfte är tydligt för användaren, exempelvis en meny som blandar handlingar med kontextuella länkar som "Öppna i nytt fönster" eller "Gå till inställningar".

Om menyn enbart består av navigationslänkar bör du istället använda en dedikerad navigationskomponent, då menu-rollen i ARIA är avsedd för handlingar och kan vara missvisande för skärmläsare.

Riktlinjer

  • Använd endast till sekundära handlingar som inte är högt prioriterade.
  • Knappen ska helst ha en titel, annars bör en aria-label användas.

API

NameTypeDefaultDescription
sizelarge

Component size (large: height 40px, medium: height 32px)

className'react-aria-Menu'

The CSS className for the element. A function may be provided to compute the class based on component state.

renderEmptyState-

Provides content to display when there are no items in the list.

escapeKeyBehavior'clearSelection'

Whether pressing the escape key should clear selection in the menu or not.

Most experiences should not modify this option as it eliminates a keyboard user's ability to easily clear selection. Only use if the escape key is being handled externally or should not trigger selection clearing contextually.

autoFocus-

Where the focus should be set.

shouldFocusWrap-

Whether keyboard navigation is circular.

items-

Item objects in the collection.

disabledKeys-

The item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with.

selectionMode-

The type of selection that is allowed in the collection.

disallowEmptySelection-

Whether the collection allows empty selection.

selectedKeys-

The currently selected keys in the collection (controlled).

defaultSelectedKeys-

The initial selected keys in the collection (uncontrolled).

dependencies-

Values that should invalidate the item cache when using dynamic collections.

style-

The inline style for the element. A function may be provided to compute the style based on component state.

slot-

A slot name for the component. Slots allow the component to receive props from a parent component. An explicit null value indicates that the local props completely override all props received from a parent.

Separator