Skip to main content

fast-menu

As defined by the W3C:

A menu is a widget that offers a list of choices to the user, such as a set of actions or functions. Menu widgets behave like native operating system menus, such as the menus that pull down from the menubars commonly found at the top of many desktop application windows. A menu is usually opened, or made visible, by activating a menu button, choosing an item in a menu that opens a sub menu, or by invoking a command, such as Shift + F10 in Windows, that opens a context specific menu. When a user activates a choice in a menu, the menu usually closes unless the choice opened a submenu.

While any DOM content is permissible as a child of the menu, only fast-menu-item's and slotted content with a role of menuitem, menuitemcheckbox, or menuitemradio will receive keyboard support.

fast-menu applies fast-menu-item's startColumnCount property based on an evaluation of all of the fast-menu-items so the content text vertically aligns across all fast-menu-items. If any fast-menu-item does not have a roll of checkbox or radio or the start slot is not passed, startColumnCount is set to 0 which applies a indent-0 class to all the fast-menu-items. If any fast-menu-item has a roll of checkbox or radio or the start slot exists, startColumnCount is set to 1 which applies a indent-1 class to all the fast-menu-items. Or if any fast-menu-item has a roll of checkbox or radio and the start slot exists, startColumnCount is set to 2 which applies a indent-2 class to all the fast-menu-items.

Setup#

Basic Setup#

import {    provideFASTDesignSystem,    fastMenu,    fastMenuItem} from "@microsoft/fast-components";
provideFASTDesignSystem()    .register(        fastMenu(),        fastMenuItem()    );

Customizing Indicators and Glyphs#

import {    provideFASTDesignSystem,    fastMenu,    fastMenuItem} from "@microsoft/fast-components";
provideFASTDesignSystem()    .register(        fastMenu(),        fastMenuItem({            expandCollapseGlyph: `...your expand/collapse glyph...`,            checkboxIndicator: `...your checkbox indicator...`,            radioIndicator: `...your radio indicator...`,        })    );

Usage#

Basic Usage#

Live Editor
Result
SyntaxError: Unexpected token (1:8)
1 : return ()
            ^

Nested Menus#

Live Editor
Result
SyntaxError: Unexpected token (1:8)
1 : return ()
            ^

Create your own design#

Menu#

import { Menu, menuTemplate as template } from "@microsoft/fast-foundation";import { menuStyles as styles } from "./my-menu.styles";
export const myMenu = Menu.compose({    baseName: "menu",    template,    styles,});

MenuItem#

import {    MenuItem,    MenuItemOptions,    menuItemTemplate as template,} from "@microsoft/fast-foundation";import { menuItemStyles as styles } from "./my-menu-item.styles";
export const myMenuItem = MenuItem.compose<MenuItemOptions>({    baseName: "menu-item",    template,    styles,    expandCollapseGlyph: `...default expand/collapse glyph...`,    checkboxIndicator: `...default checkbox indicator...`,    radioIndicator: `...default radio indicator...`,});

Additional resources#