Menu
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&MenuPropsMenuItem&MenuItemPropsMenuPopover&MenuPopoverPropsMenuSection&MenuSectionPropsSeparator&SeparatorPropsMenuTrigger&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
Menu
| Name | Type | Default | Description |
|---|---|---|---|
size | Size | large | Component size (large: height 40px, medium: height 32px) |
className | ClassNameOrFunction<MenuRenderProps> | 'react-aria-Menu' | The CSS className for the element. A function may be provided to compute the class based on component state. |
renderEmptyState | (() => ReactNode) | - | Provides content to display when there are no items in the list. |
escapeKeyBehavior | "clearSelection" | "none" | '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 | boolean | FocusStrategy | - | Where the focus should be set. |
shouldFocusWrap | boolean | - | Whether keyboard navigation is circular. |
items | Iterable<T> | - | Item objects in the collection. |
disabledKeys | Iterable<Key> | - | The item keys that are disabled. These items cannot be selected, focused, or otherwise interacted with. |
selectionMode | SelectionMode | - | The type of selection that is allowed in the collection. |
disallowEmptySelection | boolean | - | Whether the collection allows empty selection. |
selectedKeys | Iterable<Key> | "all" | - | The currently selected keys in the collection (controlled). |
defaultSelectedKeys | Iterable<Key> | "all" | - | The initial selected keys in the collection (uncontrolled). |
dependencies | readonly any[] | - | Values that should invalidate the item cache when using dynamic collections. |
style | StyleOrFunction<MenuRenderProps> | - | The inline style for the element. A function may be provided to compute the style based on component state. |
slot | string | null | - | A slot name for the component. Slots allow the component to receive props from a parent component.
An explicit |