addClass(className: string) => void | Adds a class to the root element. |
removeClass(className: string) => void | Removes a class from the root element. |
hasClass(className: string) => boolean | Returns a boolean indicating whether the root element has a given class. |
hasNecessaryDom() => boolean | Returns boolean indicating whether the necessary DOM is present (namely, the mdc-menu__items container). |
getAttributeForEventTarget(target: EventTarget, attributeName: string) => string | Returns the value of a given attribute on an event target. |
getInnerDimensions() => {width: number, height: number} | Returns an object with the items container width and height. |
hasAnchor: () => boolean | Returns whether the menu has an anchor for positioning. |
getAnchorDimensions() => {width: number, height: number, top: number, right: number, bottom: number, left: number} | Returns an object with the dimensions and position of the anchor (same semantics as DOMRect ). |
getWindowDimensions() => {width: number, height: number} | Returns an object with width and height of the page, in pixels. |
getNumberOfItems() => number | Returns the number of item elements inside the items container. In our vanilla component, we determine this by counting the number of list items whose role attribute corresponds to the correct child role of the role present on the menu list element. For example, if the list element has a role of menu this queries for all elements that have a role of menuitem . |
registerInteractionHandler(type: string, handler: EventListener) => void | Adds an event listener handler for event type type . |
deregisterInteractionHandler(type: string, handler: EventListener) => void | Removes an event listener handler for event type type . |
registerBodyClickHandler(handler: EventListener) => void | Adds an event listener handler for event type click . |
deregisterBodyClickHandler(handler: EventListener) => void | Removes an event listener handler for event type click . |
getIndexForEventTarget(target: EventTarget) => number | Checks to see if the target of an event pertains to one of the menu items, and if so returns the index of that item. Returns -1 if the target is not one of the menu items. |
notifySelected(evtData: {index: number}) => void | Dispatches an event notifying listeners that a menu item has been selected. The function should accept an evtData parameter containing an object with an index property representing the index of the selected item. Implementations may choose to supplement this data with additional data, such as the item itself. |
notifyCancel() => void | Dispatches an event notifying listeners that the menu has been closed with no selection made. |
saveFocus() => void | Stores the currently focused element on the document, for restoring with restoreFocus . |
restoreFocus() => void | Restores the previously saved focus state, by making the previously focused element the active focus again. |
isFocused() => boolean | Returns a boolean value indicating whether the root element of the menu is focused. |
focus() => void | Focuses the root element of the menu. |
getFocusedItemIndex() => number | Returns the index of the currently focused menu item (-1 if none). |
focusItemAtIndex(index: number) => void | Focuses the menu item with the provided index. |
isRtl() => boolean | Returns boolean indicating whether the current environment is RTL. |
setTransformOrigin(value: string) => void | Sets the transform origin for the menu element. |
setPosition(position: {top: string, right: string, bottom: string, left: string}) => void | Sets the position of the menu element. |
setMaxHeight(value: string) => void | Sets max-height style for the menu element. |