@material/menu

  • Version 13.0.0
  • Published
  • 734 kB
  • 10 dependencies
  • MIT license

Install

npm i @material/menu
yarn add @material/menu
pnpm add @material/menu

Overview

The Material Components for the web menu component

Index

Variables

variable cssClasses

const cssClasses: {
MENU_SELECTED_LIST_ITEM: string;
MENU_SELECTION_GROUP: string;
ROOT: string;
};
  • Copyright 2018 Google Inc.

    Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

variable numbers

const numbers: { FOCUS_ROOT_INDEX: number };

    variable strings

    const strings: {
    ARIA_CHECKED_ATTR: string;
    ARIA_DISABLED_ATTR: string;
    CHECKBOX_SELECTOR: string;
    LIST_SELECTOR: string;
    SELECTED_EVENT: string;
    SKIP_RESTORE_FOCUS: string;
    };

      Classes

      class MDCMenu

      class MDCMenu extends MDCComponent<MDCMenuFoundation> {}

        property items

        readonly items: Element[];
        • Return the items within the menu. Note that this only contains the set of elements within the items container that are proper list items, and not supplemental / presentational DOM elements.

        property open

        open: boolean;

          property selectedIndex

          selectedIndex: any;
          • Retrieves the selected index. Only applicable to select menus. The selected index, which is a number for single selection and radio lists, and an array of numbers for checkbox lists.

          property typeaheadInProgress

          readonly typeaheadInProgress: boolean;
          • Whether typeahead logic is currently matching some user prefix.

          property wrapFocus

          wrapFocus: boolean;

            method attachTo

            static attachTo: (root: Element) => MDCMenu;

              method destroy

              destroy: () => void;

                method getDefaultFoundation

                getDefaultFoundation: () => MDCMenuFoundation;

                  method getOptionByIndex

                  getOptionByIndex: (index: number) => Element | null;
                  • The item within the menu at the index specified.

                  method getPrimaryTextAtIndex

                  getPrimaryTextAtIndex: (index: number) => string;
                  • Parameter index

                    A menu item's index. The primary text within the menu at the index specified.

                  method initialize

                  initialize: (menuSurfaceFactory?: any, listFactory?: any) => void;

                    method initialSyncWithDOM

                    initialSyncWithDOM: () => void;

                      method layout

                      layout: () => void;
                      • Layout the underlying list element in the case of any dynamic updates to its structure.

                      method setAbsolutePosition

                      setAbsolutePosition: (x: number, y: number) => void;

                        method setAnchorCorner

                        setAnchorCorner: (corner: any) => void;
                        • Parameter corner

                          Default anchor corner alignment of top-left menu corner.

                        method setAnchorElement

                        setAnchorElement: (element: Element) => void;
                        • Sets the element that the menu-surface is anchored to.

                        method setAnchorMargin

                        setAnchorMargin: (margin: any) => void;

                          method setDefaultFocusState

                          setDefaultFocusState: (focusState: DefaultFocusState) => void;
                          • Sets default focus state where the menu should focus every time when menu is opened. Focuses the list root (DefaultFocusState.LIST_ROOT) element by default.

                            Parameter focusState

                            Default focus state.

                          method setEnabled

                          setEnabled: (index: number, isEnabled: boolean) => void;
                          • Sets the enabled state to isEnabled for the menu item at the given index.

                            Parameter index

                            Index of the menu item

                            Parameter isEnabled

                            The desired enabled state of the menu item.

                          method setFixedPosition

                          setFixedPosition: (isFixed: boolean) => void;

                            method setIsHoisted

                            setIsHoisted: (isHoisted: boolean) => void;

                              method setSelectedIndex

                              setSelectedIndex: (index: number) => void;
                              • Sets the list item as the selected row at the specified index.

                                Parameter index

                                Index of list item within menu.

                              method typeaheadMatchItem

                              typeaheadMatchItem: (nextChar: string, startingIndex?: number) => number;
                              • Given the next desired character from the user, adds it to the typeahead buffer. Then, attempts to find the next option matching the buffer. Wraps around if at the end of options.

                                Parameter nextChar

                                The next character to add to the prefix buffer.

                                Parameter startingIndex

                                The index from which to start matching. Only relevant when starting a new match sequence. To start a new match sequence, clear the buffer using clearTypeaheadBuffer, or wait for the buffer to clear after a set interval defined in list foundation. Defaults to the currently focused index. The index of the matched item, or -1 if no match.

                              class MDCMenuFoundation

                              class MDCMenuFoundation extends MDCFoundation<MDCMenuAdapter> {}

                                constructor

                                constructor(adapter?: Partial<MDCMenuAdapter>);

                                  property cssClasses

                                  static readonly cssClasses: {
                                  MENU_SELECTED_LIST_ITEM: string;
                                  MENU_SELECTION_GROUP: string;
                                  ROOT: string;
                                  };

                                    property defaultAdapter

                                    static readonly defaultAdapter: MDCMenuAdapter;
                                    • See Also

                                    property numbers

                                    static readonly numbers: { FOCUS_ROOT_INDEX: number };

                                      property strings

                                      static readonly strings: {
                                      ARIA_CHECKED_ATTR: string;
                                      ARIA_DISABLED_ATTR: string;
                                      CHECKBOX_SELECTOR: string;
                                      LIST_SELECTOR: string;
                                      SELECTED_EVENT: string;
                                      SKIP_RESTORE_FOCUS: string;
                                      };

                                        method destroy

                                        destroy: () => void;

                                          method getSelectedIndex

                                          getSelectedIndex: () => number;
                                          • Index of the currently selected list item within the menu.

                                          method handleItemAction

                                          handleItemAction: (listItem: Element) => void;

                                            method handleKeydown

                                            handleKeydown: (evt: KeyboardEvent) => void;

                                              method handleMenuSurfaceOpened

                                              handleMenuSurfaceOpened: () => void;

                                                method setDefaultFocusState

                                                setDefaultFocusState: (focusState: DefaultFocusState) => void;
                                                • Sets default focus state where the menu should focus every time when menu is opened. Focuses the list root (DefaultFocusState.LIST_ROOT) element by default.

                                                method setEnabled

                                                setEnabled: (index: number, isEnabled: boolean) => void;
                                                • Sets the enabled state to isEnabled for the menu item at the given index.

                                                  Parameter index

                                                  Index of the menu item

                                                  Parameter isEnabled

                                                  The desired enabled state of the menu item.

                                                method setSelectedIndex

                                                setSelectedIndex: (index: number) => void;
                                                • Selects the list item at index within the menu.

                                                  Parameter index

                                                  Index of list item within the menu.

                                                Interfaces

                                                interface MDCMenuAdapter

                                                interface MDCMenuAdapter {}
                                                • Implement this adapter for your framework of choice to delegate updates to the component in your framework of choice. See architecture documentation for more details. https://github.com/material-components/material-components-web/blob/master/docs/code/architecture.md

                                                method addAttributeToElementAtIndex

                                                addAttributeToElementAtIndex: (
                                                index: number,
                                                attr: string,
                                                value: string
                                                ) => void;
                                                • Adds an attribute, with value, to the element at the index provided.

                                                method addClassToElementAtIndex

                                                addClassToElementAtIndex: (index: number, className: string) => void;
                                                • Adds a class to the element at the index provided.

                                                method closeSurface

                                                closeSurface: (skipRestoreFocus?: boolean) => void;
                                                • Closes the menu-surface.

                                                  Parameter skipRestoreFocus

                                                  Whether to skip restoring focus to the previously focused element after the surface has been closed.

                                                method elementContainsClass

                                                elementContainsClass: (element: Element, className: string) => boolean;
                                                • true if the element contains the className.

                                                method focusItemAtIndex

                                                focusItemAtIndex: (index: number) => void;
                                                • Focuses the menu item at given index.

                                                  Parameter index

                                                  Index of the menu item that will be focused every time the menu opens.

                                                method focusListRoot

                                                focusListRoot: () => void;
                                                • Focuses the list root element.

                                                method getAttributeFromElementAtIndex

                                                getAttributeFromElementAtIndex: (index: number, attr: string) => string | null;
                                                • the attribute string if present on an element at the index provided, null otherwise.

                                                method getElementIndex

                                                getElementIndex: (element: Element) => number;
                                                • Index of the element in the list or -1 if it is not in the list.

                                                method getMenuItemCount

                                                getMenuItemCount: () => number;
                                                • Returns the menu item count.

                                                method getSelectedSiblingOfItemAtIndex

                                                getSelectedSiblingOfItemAtIndex: (index: number) => number;
                                                • Returns selected list item index within the same selection group which is a sibling of item at given index.

                                                  Parameter index

                                                  Index of the menu item with possible selected sibling.

                                                method isSelectableItemAtIndex

                                                isSelectableItemAtIndex: (index: number) => boolean;
                                                • Returns true if item at specified index is contained within an .mdc-menu__selection-group element.

                                                  Parameter index

                                                  Index of the selectable menu item.

                                                method notifySelected

                                                notifySelected: (evtData: MDCMenuItemEventDetail) => void;
                                                • Emit an event when a menu item is selected.

                                                method removeAttributeFromElementAtIndex

                                                removeAttributeFromElementAtIndex: (index: number, attr: string) => void;
                                                • Removes an attribute from an element at the index provided.

                                                method removeClassFromElementAtIndex

                                                removeClassFromElementAtIndex: (index: number, className: string) => void;
                                                • Removes a class from the element at the index provided

                                                interface MDCMenuItemComponentEvent

                                                interface MDCMenuItemComponentEvent extends Event {}

                                                  property detail

                                                  readonly detail: MDCMenuItemComponentEventDetail;

                                                    interface MDCMenuItemComponentEventDetail

                                                    interface MDCMenuItemComponentEventDetail extends MDCMenuItemEventDetail {}
                                                    • Event properties specific to the default component implementation.

                                                    property item

                                                    item: Element;

                                                      interface MDCMenuItemEvent

                                                      interface MDCMenuItemEvent extends Event {}

                                                        property detail

                                                        readonly detail: MDCMenuItemEventDetail;

                                                          interface MDCMenuItemEventDetail

                                                          interface MDCMenuItemEventDetail {}
                                                          • Event properties used by the adapter and foundation.

                                                          property index

                                                          index: number;

                                                            Enums

                                                            enum DefaultFocusState

                                                            enum DefaultFocusState {
                                                            NONE = 0,
                                                            LIST_ROOT = 1,
                                                            FIRST_ITEM = 2,
                                                            LAST_ITEM = 3,
                                                            }

                                                              member FIRST_ITEM

                                                              FIRST_ITEM = 2

                                                                member LAST_ITEM

                                                                LAST_ITEM = 3

                                                                  member LIST_ROOT

                                                                  LIST_ROOT = 1

                                                                    member NONE

                                                                    NONE = 0

                                                                      Type Aliases

                                                                      type MDCMenuFactory

                                                                      type MDCMenuFactory = (el: Element, foundation?: MDCMenuFoundation) => MDCMenu;

                                                                        Package Files (6)

                                                                        Dependencies (10)

                                                                        Dev Dependencies (0)

                                                                        No dev dependencies.

                                                                        Peer Dependencies (0)

                                                                        No peer dependencies.

                                                                        Badge

                                                                        To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                        You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@material/menu.

                                                                        • Markdown
                                                                          [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@material/menu)
                                                                        • HTML
                                                                          <a href="https://www.jsdocs.io/package/@material/menu"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>