UNPKG

3.86 kBTypeScriptView Raw
1/**
2 * @license
3 * Copyright 2018 Google Inc.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 */
23import { MDCMenuItemEventDetail } from './types';
24/**
25 * Implement this adapter for your framework of choice to delegate updates to
26 * the component in your framework of choice. See architecture documentation
27 * for more details.
28 * https://github.com/material-components/material-components-web/blob/master/docs/code/architecture.md
29 */
30export interface MDCMenuAdapter {
31 /**
32 * Adds a class to the element at the index provided.
33 */
34 addClassToElementAtIndex(index: number, className: string): void;
35 /**
36 * Removes a class from the element at the index provided
37 */
38 removeClassFromElementAtIndex(index: number, className: string): void;
39 /**
40 * Adds an attribute, with value, to the element at the index provided.
41 */
42 addAttributeToElementAtIndex(index: number, attr: string, value: string): void;
43 /**
44 * Removes an attribute from an element at the index provided.
45 */
46 removeAttributeFromElementAtIndex(index: number, attr: string): void;
47 /**
48 * @return the attribute string if present on an element at the index
49 * provided, null otherwise.
50 */
51 getAttributeFromElementAtIndex(index: number, attr: string): string | null;
52 /**
53 * @return true if the element contains the className.
54 */
55 elementContainsClass(element: Element, className: string): boolean;
56 /**
57 * Closes the menu-surface.
58 * @param skipRestoreFocus Whether to skip restoring focus to the previously
59 * focused element after the surface has been closed.
60 */
61 closeSurface(skipRestoreFocus?: boolean): void;
62 /**
63 * @return Index of the element in the list or -1 if it is not in the list.
64 */
65 getElementIndex(element: Element): number;
66 /**
67 * Emit an event when a menu item is selected.
68 */
69 notifySelected(evtData: MDCMenuItemEventDetail): void;
70 /** @return Returns the menu item count. */
71 getMenuItemCount(): number;
72 /**
73 * Focuses the menu item at given index.
74 * @param index Index of the menu item that will be focused every time the menu opens.
75 */
76 focusItemAtIndex(index: number): void;
77 /** Focuses the list root element. */
78 focusListRoot(): void;
79 /**
80 * @return Returns selected list item index within the same selection group which is
81 * a sibling of item at given `index`.
82 * @param index Index of the menu item with possible selected sibling.
83 */
84 getSelectedSiblingOfItemAtIndex(index: number): number;
85 /**
86 * @return Returns true if item at specified index is contained within an `.mdc-menu__selection-group` element.
87 * @param index Index of the selectable menu item.
88 */
89 isSelectableItemAtIndex(index: number): boolean;
90}