UNPKG

6.17 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 { MDCComponent } from '@material/base/component';
24import { MDCListFactory } from '@material/list/component';
25import { MDCListIndex } from '@material/list/types';
26import { MDCMenuSurfaceFactory } from '@material/menu-surface/component';
27import { Corner } from '@material/menu-surface/constants';
28import { MDCMenuDistance } from '@material/menu-surface/types';
29import { DefaultFocusState } from './constants';
30import { MDCMenuFoundation } from './foundation';
31export declare type MDCMenuFactory = (el: Element, foundation?: MDCMenuFoundation) => MDCMenu;
32export declare class MDCMenu extends MDCComponent<MDCMenuFoundation> {
33 static attachTo(root: Element): MDCMenu;
34 private menuSurfaceFactory;
35 private listFactory;
36 private menuSurface;
37 private list;
38 private handleKeydown;
39 private handleItemAction;
40 private handleMenuSurfaceOpened;
41 initialize(menuSurfaceFactory?: MDCMenuSurfaceFactory, listFactory?: MDCListFactory): void;
42 initialSyncWithDOM(): void;
43 destroy(): void;
44 get open(): boolean;
45 set open(value: boolean);
46 get wrapFocus(): boolean;
47 set wrapFocus(value: boolean);
48 /**
49 * Sets whether the menu has typeahead functionality.
50 * @param value Whether typeahead is enabled.
51 */
52 set hasTypeahead(value: boolean);
53 /**
54 * @return Whether typeahead logic is currently matching some user prefix.
55 */
56 get typeaheadInProgress(): boolean;
57 /**
58 * Given the next desired character from the user, adds it to the typeahead
59 * buffer. Then, attempts to find the next option matching the buffer. Wraps
60 * around if at the end of options.
61 *
62 * @param nextChar The next character to add to the prefix buffer.
63 * @param startingIndex The index from which to start matching. Only relevant
64 * when starting a new match sequence. To start a new match sequence,
65 * clear the buffer using `clearTypeaheadBuffer`, or wait for the buffer
66 * to clear after a set interval defined in list foundation. Defaults to
67 * the currently focused index.
68 * @return The index of the matched item, or -1 if no match.
69 */
70 typeaheadMatchItem(nextChar: string, startingIndex?: number): number;
71 /**
72 * Layout the underlying list element in the case of any dynamic updates
73 * to its structure.
74 */
75 layout(): void;
76 /**
77 * Return the items within the menu. Note that this only contains the set of elements within
78 * the items container that are proper list items, and not supplemental / presentational DOM
79 * elements.
80 */
81 get items(): Element[];
82 /**
83 * Turns on/off the underlying list's single selection mode. Used mainly
84 * by select menu.
85 *
86 * @param singleSelection Whether to enable single selection mode.
87 */
88 set singleSelection(singleSelection: boolean);
89 /**
90 * Retrieves the selected index. Only applicable to select menus.
91 * @return The selected index, which is a number for single selection and
92 * radio lists, and an array of numbers for checkbox lists.
93 */
94 get selectedIndex(): MDCListIndex;
95 /**
96 * Sets the selected index of the list. Only applicable to select menus.
97 * @param index The selected index, which is a number for single selection and
98 * radio lists, and an array of numbers for checkbox lists.
99 */
100 set selectedIndex(index: MDCListIndex);
101 set quickOpen(quickOpen: boolean);
102 /**
103 * Sets default focus state where the menu should focus every time when menu
104 * is opened. Focuses the list root (`DefaultFocusState.LIST_ROOT`) element by
105 * default.
106 * @param focusState Default focus state.
107 */
108 setDefaultFocusState(focusState: DefaultFocusState): void;
109 /**
110 * @param corner Default anchor corner alignment of top-left menu corner.
111 */
112 setAnchorCorner(corner: Corner): void;
113 setAnchorMargin(margin: Partial<MDCMenuDistance>): void;
114 /**
115 * Sets the list item as the selected row at the specified index.
116 * @param index Index of list item within menu.
117 */
118 setSelectedIndex(index: number): void;
119 /**
120 * Sets the enabled state to isEnabled for the menu item at the given index.
121 * @param index Index of the menu item
122 * @param isEnabled The desired enabled state of the menu item.
123 */
124 setEnabled(index: number, isEnabled: boolean): void;
125 /**
126 * @return The item within the menu at the index specified.
127 */
128 getOptionByIndex(index: number): Element | null;
129 /**
130 * @param index A menu item's index.
131 * @return The primary text within the menu at the index specified.
132 */
133 getPrimaryTextAtIndex(index: number): string;
134 setFixedPosition(isFixed: boolean): void;
135 setIsHoisted(isHoisted: boolean): void;
136 setAbsolutePosition(x: number, y: number): void;
137 /**
138 * Sets the element that the menu-surface is anchored to.
139 */
140 setAnchorElement(element: Element): void;
141 getDefaultFoundation(): MDCMenuFoundation;
142}