UNPKG

9.91 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';
26declare type SelectionUpdateOptions = {
27 /** Whether the update was triggered by a user interaction. */
28 isUserInteraction?: boolean;
29 /**
30 * Whether the UI should be updated regardless of whether the
31 * selection would be a noop according to the foundation state.
32 * https://github.com/material-components/material-components-web/commit/5d060518804437aa1ae3152562f1bb78b1af4aa6.
33 */
34 forceUpdate?: boolean;
35};
36export declare class MDCListFoundation extends MDCFoundation<MDCListAdapter> {
37 static get strings(): {
38 ACTION_EVENT: string;
39 SELECTION_CHANGE_EVENT: string;
40 ARIA_CHECKED: string;
41 ARIA_CHECKED_CHECKBOX_SELECTOR: string;
42 ARIA_CHECKED_RADIO_SELECTOR: string;
43 ARIA_CURRENT: string;
44 ARIA_DISABLED: string;
45 ARIA_ORIENTATION: string;
46 ARIA_ORIENTATION_HORIZONTAL: string;
47 ARIA_ROLE_CHECKBOX_SELECTOR: string;
48 ARIA_SELECTED: string;
49 ARIA_INTERACTIVE_ROLES_SELECTOR: string;
50 ARIA_MULTI_SELECTABLE_SELECTOR: string;
51 CHECKBOX_RADIO_SELECTOR: string;
52 CHECKBOX_SELECTOR: string;
53 CHILD_ELEMENTS_TO_TOGGLE_TABINDEX: string;
54 DEPRECATED_SELECTOR: string;
55 FOCUSABLE_CHILD_ELEMENTS: string;
56 RADIO_SELECTOR: string;
57 SELECTED_ITEM_SELECTOR: string;
58 };
59 static get cssClasses(): {
60 LIST_ITEM_ACTIVATED_CLASS: string;
61 LIST_ITEM_CLASS: string;
62 LIST_ITEM_DISABLED_CLASS: string;
63 LIST_ITEM_SELECTED_CLASS: string;
64 LIST_ITEM_TEXT_CLASS: string;
65 LIST_ITEM_PRIMARY_TEXT_CLASS: string;
66 ROOT: string;
67 };
68 static get numbers(): {
69 UNSET_INDEX: number;
70 TYPEAHEAD_BUFFER_CLEAR_TIMEOUT_MS: number;
71 };
72 static get defaultAdapter(): MDCListAdapter;
73 private wrapFocus;
74 private isVertical;
75 private isSingleSelectionList;
76 private areDisabledItemsFocusable;
77 private selectedIndex;
78 private focusedItemIndex;
79 private useActivatedClass;
80 private useSelectedAttr;
81 private ariaCurrentAttrValue;
82 private isCheckboxList;
83 private isRadioList;
84 private lastSelectedIndex;
85 private hasTypeahead;
86 private readonly typeaheadState;
87 private sortedIndexByFirstChar;
88 constructor(adapter?: Partial<MDCListAdapter>);
89 layout(): void;
90 /** Returns the index of the item that was last focused. */
91 getFocusedItemIndex(): number;
92 /** Toggles focus wrapping with keyboard navigation. */
93 setWrapFocus(value: boolean): void;
94 /**
95 * Toggles orientation direction for keyboard navigation (true for vertical,
96 * false for horizontal).
97 */
98 setVerticalOrientation(value: boolean): void;
99 /** Toggles single-selection behavior. */
100 setSingleSelection(value: boolean): void;
101 setDisabledItemsFocusable(value: boolean): void;
102 /**
103 * Automatically determines whether the list is single selection list. If so,
104 * initializes the internal state to match the selected item.
105 */
106 private maybeInitializeSingleSelection;
107 /** @return Index of the first selected item based on the DOM state. */
108 private getSelectedIndexFromDOM;
109 /**
110 * Sets whether typeahead is enabled on the list.
111 * @param hasTypeahead Whether typeahead is enabled.
112 */
113 setHasTypeahead(hasTypeahead: boolean): void;
114 /**
115 * @return Whether typeahead is currently matching a user-specified prefix.
116 */
117 isTypeaheadInProgress(): boolean;
118 /** Toggle use of the "activated" CSS class. */
119 setUseActivatedClass(useActivated: boolean): void;
120 /**
121 * Toggles use of the selected attribute (true for aria-selected, false for
122 * aria-checked).
123 */
124 setUseSelectedAttribute(useSelected: boolean): void;
125 getSelectedIndex(): MDCListIndex;
126 setSelectedIndex(index: MDCListIndex, options?: SelectionUpdateOptions): void;
127 /**
128 * Focus in handler for the list items.
129 */
130 handleFocusIn(listItemIndex: number): void;
131 /**
132 * Focus out handler for the list items.
133 */
134 handleFocusOut(listItemIndex: number): void;
135 private isIndexDisabled;
136 /**
137 * Key handler for the list.
138 */
139 handleKeydown(event: KeyboardEvent, isRootListItem: boolean, listItemIndex: number): void;
140 /**
141 * Click handler for the list.
142 *
143 * @param index Index for the item that has been clicked.
144 * @param isCheckboxAlreadyUpdatedInAdapter Whether the checkbox for
145 * the list item has already been updated in the adapter. This attribute
146 * should be set to `true` when e.g. the click event directly landed on
147 * the underlying native checkbox element which would cause the checked
148 * state to be already toggled within `adapter.isCheckboxCheckedAtIndex`.
149 */
150 handleClick(index: number, isCheckboxAlreadyUpdatedInAdapter: boolean, event?: MouseEvent): void;
151 /**
152 * Focuses the next element on the list.
153 */
154 focusNextElement(index: number): number;
155 /**
156 * Focuses the previous element on the list.
157 */
158 focusPrevElement(index: number): number;
159 focusFirstElement(): number;
160 focusLastElement(): number;
161 focusInitialElement(): number;
162 /**
163 * @param itemIndex Index of the list item
164 * @param isEnabled Sets the list item to enabled or disabled.
165 */
166 setEnabled(itemIndex: number, isEnabled: boolean): void;
167 private setSingleSelectionAtIndex;
168 /**
169 * Sets aria attribute for single selection at given index.
170 */
171 private setAriaForSingleSelectionAtIndex;
172 /**
173 * Returns the attribute to use for indicating selection status.
174 */
175 private getSelectionAttribute;
176 /**
177 * Toggles radio at give index. Radio doesn't change the checked state if it
178 * is already checked.
179 */
180 private setRadioAtIndex;
181 private setCheckboxAtIndex;
182 /**
183 * Toggles the state of all checkboxes in the given range (inclusive) based on
184 * the state of the checkbox at the `toggleIndex`. To determine whether to set
185 * the given range to checked or unchecked, read the value of the checkbox at
186 * the `toggleIndex` and negate it. Then apply that new checked state to all
187 * checkboxes in the range.
188 * @param fromIndex The start of the range of checkboxes to toggle
189 * @param toIndex The end of the range of checkboxes to toggle
190 * @param toggleIndex The index that will be used to determine the new state
191 * of the given checkbox range.
192 */
193 private toggleCheckboxRange;
194 private setTabindexAtIndex;
195 /**
196 * @return Return true if it is single selectin list, checkbox list or radio
197 * list.
198 */
199 private isSelectableList;
200 private setTabindexToFirstSelectedOrFocusedItem;
201 private getFirstSelectedOrFocusedItemIndex;
202 private isIndexValid;
203 private isIndexInRange;
204 /**
205 * Sets selected index on user action, toggles checkboxes in checkbox lists
206 * by default, unless `isCheckboxAlreadyUpdatedInAdapter` is set to `true`.
207 *
208 * In cases where `isCheckboxAlreadyUpdatedInAdapter` is set to `true`, the
209 * UI is just updated to reflect the value returned by the adapter.
210 *
211 * When calling this, make sure user interaction does not toggle disabled
212 * list items.
213 */
214 private setSelectedIndexOnAction;
215 private toggleCheckboxAtIndex;
216 private focusItemAtIndex;
217 private checkboxListToggleAll;
218 /**
219 * Given the next desired character from the user, adds it to the typeahead
220 * buffer. Then, attempts to find the next option matching the buffer. Wraps
221 * around if at the end of options.
222 *
223 * @param nextChar The next character to add to the prefix buffer.
224 * @param startingIndex The index from which to start matching. Only relevant
225 * when starting a new match sequence. To start a new match sequence,
226 * clear the buffer using `clearTypeaheadBuffer`, or wait for the buffer
227 * to clear after a set interval defined in list foundation. Defaults to
228 * the currently focused index.
229 * @return The index of the matched item, or -1 if no match.
230 */
231 typeaheadMatchItem(nextChar: string, startingIndex?: number, skipFocus?: boolean): number;
232 /**
233 * Initializes the MDCListTextAndIndex data structure by indexing the current
234 * list items by primary text.
235 *
236 * @return The primary texts of all the list items sorted by first character.
237 */
238 private typeaheadInitSortedIndex;
239 /**
240 * Clears the typeahead buffer.
241 */
242 clearTypeaheadBuffer(): void;
243}
244export default MDCListFoundation;