1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 | import { MDCFoundation } from '@material/base/foundation';
|
24 | import { MDCListAdapter } from './adapter';
|
25 | import { MDCListIndex } from './types';
|
26 | declare type SelectionUpdateOptions = {
|
27 |
|
28 | isUserInteraction?: boolean;
|
29 | |
30 |
|
31 |
|
32 |
|
33 |
|
34 | forceUpdate?: boolean;
|
35 | };
|
36 | export 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 | }
|
244 | export default MDCListFoundation;
|