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 | */
|
30 | export 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 | * Notifies that items at the given indices have changed its
|
81 | * selection state through user interaction (e.g. click).
|
82 | *
|
83 | * This is invoked only for changes caused by user interaction
|
84 | * to match with the native `change` event semantics.
|
85 | */
|
86 | notifySelectionChange(changedIndices: number[]): void;
|
87 | /**
|
88 | * @return true when the current focused element is inside list root.
|
89 | */
|
90 | isFocusInsideList(): boolean;
|
91 | /**
|
92 | * @return the primary text content of the list item at index.
|
93 | */
|
94 | getPrimaryTextAtIndex(index: number): string;
|
95 | }
|