UNPKG

7.88 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 { MDCFoundation } from '@material/base/foundation';
24import { MDCListAdapter } from './adapter';
25import { MDCListIndex } from './types';
26export declare class MDCListFoundation extends MDCFoundation<MDCListAdapter> {
27 static get strings(): {
28 ACTION_EVENT: string;
29 ARIA_CHECKED: string;
30 ARIA_CHECKED_CHECKBOX_SELECTOR: string;
31 ARIA_CHECKED_RADIO_SELECTOR: string;
32 ARIA_CURRENT: string;
33 ARIA_DISABLED: string;
34 ARIA_ORIENTATION: string;
35 ARIA_ORIENTATION_HORIZONTAL: string;
36 ARIA_ROLE_CHECKBOX_SELECTOR: string;
37 ARIA_SELECTED: string;
38 ARIA_INTERACTIVE_ROLES_SELECTOR: string;
39 ARIA_MULTI_SELECTABLE_SELECTOR: string;
40 CHECKBOX_RADIO_SELECTOR: string;
41 CHECKBOX_SELECTOR: string;
42 CHILD_ELEMENTS_TO_TOGGLE_TABINDEX: string;
43 DEPRECATED_SELECTOR: string;
44 FOCUSABLE_CHILD_ELEMENTS: string;
45 RADIO_SELECTOR: string;
46 SELECTED_ITEM_SELECTOR: string;
47 };
48 static get cssClasses(): {
49 LIST_ITEM_ACTIVATED_CLASS: string;
50 LIST_ITEM_CLASS: string;
51 LIST_ITEM_DISABLED_CLASS: string;
52 LIST_ITEM_SELECTED_CLASS: string;
53 LIST_ITEM_TEXT_CLASS: string;
54 LIST_ITEM_PRIMARY_TEXT_CLASS: string;
55 ROOT: string;
56 };
57 static get numbers(): {
58 UNSET_INDEX: number;
59 TYPEAHEAD_BUFFER_CLEAR_TIMEOUT_MS: number;
60 };
61 static get defaultAdapter(): MDCListAdapter;
62 private wrapFocus;
63 private isVertical;
64 private isSingleSelectionList;
65 private selectedIndex;
66 private focusedItemIndex;
67 private useActivatedClass;
68 private useSelectedAttr;
69 private ariaCurrentAttrValue;
70 private isCheckboxList;
71 private isRadioList;
72 private hasTypeahead;
73 private readonly typeaheadState;
74 private sortedIndexByFirstChar;
75 constructor(adapter?: Partial<MDCListAdapter>);
76 layout(): void;
77 /** Returns the index of the item that was last focused. */
78 getFocusedItemIndex(): number;
79 /** Toggles focus wrapping with keyboard navigation. */
80 setWrapFocus(value: boolean): void;
81 /**
82 * Toggles orientation direction for keyboard navigation (true for vertical,
83 * false for horizontal).
84 */
85 setVerticalOrientation(value: boolean): void;
86 /** Toggles single-selection behavior. */
87 setSingleSelection(value: boolean): void;
88 /**
89 * Automatically determines whether the list is single selection list. If so,
90 * initializes the internal state to match the selected item.
91 */
92 private maybeInitializeSingleSelection;
93 /** @return Index of the first selected item based on the DOM state. */
94 private getSelectedIndexFromDOM;
95 /**
96 * Sets whether typeahead is enabled on the list.
97 * @param hasTypeahead Whether typeahead is enabled.
98 */
99 setHasTypeahead(hasTypeahead: boolean): void;
100 /**
101 * @return Whether typeahead is currently matching a user-specified prefix.
102 */
103 isTypeaheadInProgress(): boolean;
104 /** Toggle use of the "activated" CSS class. */
105 setUseActivatedClass(useActivated: boolean): void;
106 /**
107 * Toggles use of the selected attribute (true for aria-selected, false for
108 * aria-checked).
109 */
110 setUseSelectedAttribute(useSelected: boolean): void;
111 getSelectedIndex(): MDCListIndex;
112 setSelectedIndex(index: MDCListIndex, { forceUpdate }?: {
113 forceUpdate?: boolean;
114 }): void;
115 /**
116 * Focus in handler for the list items.
117 */
118 handleFocusIn(listItemIndex: number): void;
119 /**
120 * Focus out handler for the list items.
121 */
122 handleFocusOut(listItemIndex: number): void;
123 /**
124 * Key handler for the list.
125 */
126 handleKeydown(event: KeyboardEvent, isRootListItem: boolean, listItemIndex: number): void;
127 /**
128 * Click handler for the list.
129 */
130 handleClick(index: number, toggleCheckbox: boolean): void;
131 /**
132 * Focuses the next element on the list.
133 */
134 focusNextElement(index: number): number;
135 /**
136 * Focuses the previous element on the list.
137 */
138 focusPrevElement(index: number): number;
139 focusFirstElement(): number;
140 focusLastElement(): number;
141 focusInitialElement(): number;
142 /**
143 * @param itemIndex Index of the list item
144 * @param isEnabled Sets the list item to enabled or disabled.
145 */
146 setEnabled(itemIndex: number, isEnabled: boolean): void;
147 private setSingleSelectionAtIndex;
148 /**
149 * Sets aria attribute for single selection at given index.
150 */
151 private setAriaForSingleSelectionAtIndex;
152 /**
153 * Returns the attribute to use for indicating selection status.
154 */
155 private getSelectionAttribute;
156 /**
157 * Toggles radio at give index. Radio doesn't change the checked state if it
158 * is already checked.
159 */
160 private setRadioAtIndex;
161 private setCheckboxAtIndex;
162 private setTabindexAtIndex;
163 /**
164 * @return Return true if it is single selectin list, checkbox list or radio
165 * list.
166 */
167 private isSelectableList;
168 private setTabindexToFirstSelectedOrFocusedItem;
169 private getFirstSelectedOrFocusedItemIndex;
170 private isIndexValid;
171 private isIndexInRange;
172 /**
173 * Sets selected index on user action, toggles checkbox / radio based on
174 * toggleCheckbox value. User interaction should not toggle list item(s) when
175 * disabled.
176 */
177 private setSelectedIndexOnAction;
178 private toggleCheckboxAtIndex;
179 private focusItemAtIndex;
180 private toggleAll;
181 /**
182 * Given the next desired character from the user, adds it to the typeahead
183 * buffer. Then, attempts to find the next option matching the buffer. Wraps
184 * around if at the end of options.
185 *
186 * @param nextChar The next character to add to the prefix buffer.
187 * @param startingIndex The index from which to start matching. Only relevant
188 * when starting a new match sequence. To start a new match sequence,
189 * clear the buffer using `clearTypeaheadBuffer`, or wait for the buffer
190 * to clear after a set interval defined in list foundation. Defaults to
191 * the currently focused index.
192 * @return The index of the matched item, or -1 if no match.
193 */
194 typeaheadMatchItem(nextChar: string, startingIndex?: number, skipFocus?: boolean): number;
195 /**
196 * Initializes the MDCListTextAndIndex data structure by indexing the current
197 * list items by primary text.
198 *
199 * @return The primary texts of all the list items sorted by first character.
200 */
201 private typeaheadInitSortedIndex;
202 /**
203 * Clears the typeahead buffer.
204 */
205 clearTypeaheadBuffer(): void;
206}
207export default MDCListFoundation;