Search the documentation

Type to search page titles, component names and descriptions.

    Navigation

    Menu

    A disclosed list of links and commands.

    import { ActionMenu, Menu } from 'faifo-design'

    Menu opens a panel of items from a trigger; items may be links, submit actions or disabled entries with a description. ActionMenu is the menu of secondary commands of a record or a row, with named groups.

    #When to use

    • Use it for actions that are available but not primary.
    • Keep the one primary action outside the menu.
    • Group related commands and name the groups; assistive technology reads the names.

    #Examples

    Each example is a specimen of the package catalogue, rendered on the server exactly as shown in its code.

    #Menu and action menu

    Native disclosure supports links, submit actions, descriptions and disabled state.

    Record actions
    More actions ···
    Show codeHide code
    import { ActionMenu, Avatar, Inline, Menu } from 'faifo-design'
    
    export const Example = () => (
      <Inline
        items={[
          <Menu
            id="record-menu"
            label="Record actions"
            open
            items={[
              { id: 'record-label', kind: 'label', label: 'Record' },
              { id: 'empty', kind: 'label', label: 'No matching actions', hidden: true },
              { id: 'open', label: 'Open record', href: '#record-page' },
              { id: 'watch', label: 'Watch changes', value: 'watch', checked: true, shortcut: 'W' },
              { id: 'pin', label: 'Pin to sidebar', value: 'pin', checked: false },
              {
                id: 'notify-followers',
                label: 'Notify followers',
                value: 'notify-followers',
                checked: true,
                disabled: true,
                description: 'Only the owner can change this',
              },
              { id: 'separator', kind: 'separator' },
              {
                id: 'duplicate',
                label: 'Duplicate',
                value: 'duplicate',
                description: 'Create a new draft',
              },
              { id: 'archive', label: 'Archive', value: 'archive', destructive: true },
            ]}
          />,
          <ActionMenu
            id="more-actions"
            label="More actions"
            items={[{ id: 'export', label: 'Export report', href: '#data-table' }]}
          />,
          <Menu
            id="account-menu"
            label="Account"
            triggerAppearance="plain"
            trigger={<Avatar name="Ngọc Linh" size="small" />}
            align="end"
            items={[{ id: 'profile', label: 'Profile', href: '#record-page' }]}
          />,
        ]}
      />
    )

    #Grouped action menu

    Groups name related commands for assistive technology; a separator precedes every group after the first.

    More actions ···
    Show codeHide code
    import { ActionMenu } from 'faifo-design'
    
    export const Example = () => (
      <ActionMenu
        id="stay-actions"
        label="More actions"
        open
        items={[
          {
            id: 'stay',
            kind: 'group',
            label: 'In-house guest',
            items: [
              { id: 'move-room', label: 'Move room', value: 'move-room' },
              { id: 'extend-stay', label: 'Extend stay', value: 'extend-stay' },
            ],
          },
          {
            id: 'cashier',
            kind: 'group',
            label: 'Cashier',
            items: [
              { id: 'payment', label: 'Take payment', value: 'payment' },
              { id: 'charge', label: 'Post charge', value: 'charge' },
            ],
          },
          {
            id: 'room',
            kind: 'group',
            label: 'Room',
            items: [
              {
                id: 'out-of-service',
                label: 'Take out of service',
                value: 'out-of-service',
                destructive: true,
              },
            ],
          },
        ]}
      />
    )

    #Contract

    A menu panel opens from its trigger's start or end (align, mobileAlign). Where that carries it past an edge of the viewport, as from a trigger in the middle of a phone row, the runtime slides the open panel along the row until it is 8px inside, its leading edge on a whole pixel; a panel the viewport holds stays where its trigger put it, and closing forgets the move. The runtime hears every menu's toggle on its root as the event is captured, so a menu an island draws after the runtime attached is placed too, and an open panel is placed again when the viewport is resized. Consumers do not move panels with CSS.

    placement="right" opens beside a side-rail trigger, aligned to its bottom edge; shared runtime geometry keeps the panel inside its viewport and clipping parent.

    A trigger replaces the label inside the summary, and the label still names the menu. Where the trigger shows the choice in effect, as a filter or a period does, the label names both, Cơ sở: Holiday Inn, as DatePresetPicker names its own: a name without the choice the reader sees is one they cannot say to reach it (WCAG 2.5.3).

    #API

    Generated from the package source. A property without a description has none in the source yet.

    #ActionMenuComponent

    PropertyDescriptionTypeDefault
    idrequired–string–
    labelrequired–string–
    itemsrequired–readonly MenuEntry[]–
    selectionModeChecked items represent one selection when single; default preserves checkbox menus.'single' | 'multiple'–
    triggerAppearanceplain leaves the trigger without a frame, padding or fill: a bare hit area whose trigger content draws the face, such as an avatar or a tile matching its neighbours. Focus, open state and the panel stay the menu's.'button' | 'plain'–
    open–boolean–
    align–'start' | 'end''end'
    mobileAlignOptional alignment below 768px when page actions wrap to the leading edge.'start' | 'end'–
    sizecompact sits in a row of list facets at their height.'default' | 'compact'–
    countHow many choices are in effect, shown on the trigger. Zero shows nothing.number–
    search–MenuSearch–
    placementbottom (default) opens below the trigger. top opens above it, for a trigger near the bottom of a container that clips overflow — a fixed modal footer, say — where the panel would otherwise render past the container's edge and be cut off rather than merely overlapping content. right opens beside a rail trigger, aligned to its bottom edge.'top' | 'bottom' | 'right'–
    triggerLabel–string–

    #MenuComponent

    PropertyDescriptionTypeDefault
    idrequired–string–
    labelrequired–string–
    itemsrequired–readonly MenuEntry[]–
    selectionModeChecked items represent one selection when single; default preserves checkbox menus.'single' | 'multiple'–
    triggerReplaces the label inside the trigger — an icon, say. The label still names it.JSXChild–
    triggerAppearanceplain leaves the trigger without a frame, padding or fill: a bare hit area whose trigger content draws the face, such as an avatar or a tile matching its neighbours. Focus, open state and the panel stay the menu's.'button' | 'plain'–
    open–boolean–
    align–'start' | 'end''start'
    mobileAlignOptional alignment below 768px when page actions wrap to the leading edge.'start' | 'end'–
    sizecompact sits in a row of list facets at their height.'default' | 'compact'–
    countHow many choices are in effect, shown on the trigger. Zero shows nothing.number–
    search–MenuSearch–
    placementbottom (default) opens below the trigger. top opens above it, for a trigger near the bottom of a container that clips overflow — a fixed modal footer, say — where the panel would otherwise render past the container's edge and be cut off rather than merely overlapping content. right opens beside a rail trigger, aligned to its bottom edge.'top' | 'bottom' | 'right''bottom'

    #Types

    #MenuEntry

    type MenuEntry = MenuItem | MenuLabel | MenuSeparator | MenuGroup

    #MenuGroup

    A named set of related commands — what a guest in the house needs, what the cashier does. It renders role="group" named by its visible heading, so a screen reader announces the set and not only a line of text, and a separator is drawn before every group that follows another entry, so callers do not place one by hand.

    PropertyDescriptionTypeDefault
    idrequired–string–
    kindrequired–'group'–
    labelrequired–string–
    itemsrequired–readonly MenuItem[]–

    #MenuItem

    PropertyDescriptionTypeDefault
    idrequired–string–
    kind–'item'–
    labelrequired–string–
    href–string–
    name–string–
    value–string–
    form–string–
    leading–JSXChild–
    description–string–
    disabled–boolean–
    destructive–boolean–
    checkedTurns the command into a menuitemcheckbox while preserving server-owned state.boolean–
    shortcutVisible keyboard hint; the browser interaction remains owned by the application.string–
    viewportShows the item at one width only, as an action's viewport does.'phone' | 'wide'–

    #MenuLabel

    PropertyDescriptionTypeDefault
    idrequired–string–
    kindrequired–'label'–
    labelrequired–string–
    hidden–boolean–

    #MenuProps

    The properties of Menu, listed above.

    #MenuSeparator

    PropertyDescriptionTypeDefault
    idrequired–string–
    kindrequired–'separator'–

    #Hooks

    The data-ui values these components render. Select them in tests and behaviour; their look belongs to the design system. See Contract.

    • menu
    • menu-trigger
    • menu-trigger-count
    • menu-panel
    • menu-search
    • menu-search-input
    • menu-group
    • menu-label
    • menu-separator
    • menu-item
    • menu-item-leading
    • menu-item-copy
    • menu-item-check
    • menu-item-shortcut