UNPKG

3.6 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 */
23/**
24 * Defines the shape of the adapter expected by the foundation.
25 * Implement this adapter for your framework of choice to delegate updates to
26 * the component in your framework of choice. See architecture documentation
27 * for more details.
28 * https://github.com/material-components/material-components-web/blob/master/docs/code/architecture.md
29 */
30export interface MDCListAdapter {
31 /**
32 * Returns the attribute value of list item at given `index`.
33 */
34 getAttributeForElementIndex(index: number, attr: string): string | null;
35 getListItemCount(): number;
36 getFocusedElementIndex(): number;
37 setAttributeForElementIndex(index: number, attribute: string, value: string): void;
38 addClassForElementIndex(index: number, className: string): void;
39 removeClassForElementIndex(index: number, className: string): void;
40 /**
41 * Focuses list item at the index specified.
42 */
43 focusItemAtIndex(index: number): void;
44 /**
45 * Sets the tabindex to the value specified for all button/a element children of
46 * the list item at the index specified.
47 */
48 setTabIndexForListItemChildren(listItemIndex: number, tabIndexValue: string): void;
49 /**
50 * @return true if radio button is present at given list item index.
51 */
52 hasRadioAtIndex(index: number): boolean;
53 /**
54 * @return true if checkbox is present at given list item index.
55 */
56 hasCheckboxAtIndex(index: number): boolean;
57 /**
58 * @return true if checkbox inside a list item is checked.
59 */
60 isCheckboxCheckedAtIndex(index: number): boolean;
61 /**
62 * @return true if root element is focused.
63 */
64 isRootFocused(): boolean;
65 /**
66 * @param index list item index.
67 * @param className the name of the class whose presence is to be checked.
68 * @return true if list item at `index` has class `className`.
69 */
70 listItemAtIndexHasClass(index: number, className: string): boolean;
71 /**
72 * Sets the checked status of checkbox or radio at given list item index.
73 */
74 setCheckedCheckboxOrRadioAtIndex(index: number, isChecked: boolean): void;
75 /**
76 * Notifies user action on list item.
77 */
78 notifyAction(index: number): void;
79 /**
80 * @return true when the current focused element is inside list root.
81 */
82 isFocusInsideList(): boolean;
83 /**
84 * @return the primary text content of the list item at index.
85 */
86 getPrimaryTextAtIndex(index: number): string;
87}