UNPKG

4.49 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 { MDCListFoundation } from './foundation';
25import { MDCListIndex } from './types';
26export declare type MDCListFactory = (el: Element, foundation?: MDCListFoundation) => MDCList;
27export declare class MDCList extends MDCComponent<MDCListFoundation> {
28 set vertical(value: boolean);
29 get listElements(): Element[];
30 set wrapFocus(value: boolean);
31 /**
32 * @return Whether typeahead is currently matching a user-specified prefix.
33 */
34 get typeaheadInProgress(): boolean;
35 /**
36 * Sets whether typeahead functionality is enabled on the list.
37 * @param hasTypeahead Whether typeahead is enabled.
38 */
39 set hasTypeahead(hasTypeahead: boolean);
40 set singleSelection(isSingleSelectionList: boolean);
41 get selectedIndex(): MDCListIndex;
42 set selectedIndex(index: MDCListIndex);
43 static attachTo(root: Element): MDCList;
44 private handleKeydown;
45 private handleClick;
46 private focusInEventListener;
47 private focusOutEventListener;
48 private classNameMap;
49 private isEvolutionEnabled;
50 private isInteractive;
51 initialSyncWithDOM(): void;
52 destroy(): void;
53 layout(): void;
54 /**
55 * Extracts the primary text from a list item.
56 * @param item The list item element.
57 * @return The primary text in the element.
58 */
59 getPrimaryText(item: Element): string;
60 /**
61 * Initialize selectedIndex value based on pre-selected list items.
62 */
63 initializeListType(): void;
64 /**
65 * Updates the list item at itemIndex to the desired isEnabled state.
66 * @param itemIndex Index of the list item
67 * @param isEnabled Sets the list item to enabled or disabled.
68 */
69 setEnabled(itemIndex: number, isEnabled: boolean): void;
70 /**
71 * Given the next desired character from the user, adds it to the typeahead
72 * buffer. Then, attempts to find the next option matching the buffer. Wraps
73 * around if at the end of options.
74 *
75 * @param nextChar The next character to add to the prefix buffer.
76 * @param startingIndex The index from which to start matching. Defaults to
77 * the currently focused index.
78 * @return The index of the matched item.
79 */
80 typeaheadMatchItem(nextChar: string, startingIndex?: number): number;
81 getDefaultFoundation(): MDCListFoundation;
82 /**
83 * Ensures that at least one item is focusable if the list is interactive and
84 * doesn't specify a suitable tabindex.
85 */
86 private ensureFocusable;
87 private initialFocusIndex;
88 /**
89 * Used to figure out which list item this event is targetting. Or returns -1
90 * if there is no list item
91 */
92 private getListItemIndex;
93 /**
94 * Used to figure out which element was clicked before sending the event to
95 * the foundation.
96 */
97 private handleFocusInEvent;
98 /**
99 * Used to figure out which element was clicked before sending the event to
100 * the foundation.
101 */
102 private handleFocusOutEvent;
103 /**
104 * Used to figure out which element was focused when keydown event occurred
105 * before sending the event to the foundation.
106 */
107 private handleKeydownEvent;
108 /**
109 * Used to figure out which element was clicked before sending the event to
110 * the foundation.
111 */
112 private handleClickEvent;
113}