Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 00f2ef1

Browse files
태재영Matt Goo
태재영
authored and
Matt Goo
committed
feat(list): Implement getAttributeForElementIndex (#948)
1 parent e95ff65 commit 00f2ef1

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

packages/list/index.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,16 @@ export default class List extends React.Component<ListProps, ListState> {
217217
getListItemCount: () => this.listElements.length,
218218
getFocusedElementIndex: () =>
219219
this.listElements.indexOf(document.activeElement as HTMLLIElement),
220+
getAttributeForElementIndex: (index, attr) => {
221+
const listItem = this.listElements[index];
222+
return listItem.getAttribute(attr);
223+
},
220224
setAttributeForElementIndex: (index, attr, value) => {
221225
const listItem = this.listElements[index];
222226
if (listItem) {
223227
listItem.setAttribute(attr, value);
224228
}
225229
},
226-
// TODO: implement
227-
// https://github.com/material-components/material-components-web-react/issues/822
228-
getAttributeForElementIndex: () => '',
229230
/**
230231
* Pushes class name to state.listItemClassNames[listItemIndex] if it doesn't yet exist.
231232
*/

test/unit/list/index.test.tsx

+8
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,14 @@ test('#adapter.getListItemCount returns correct number of list items if List has
161161
assert.equal(wrapper.instance().adapter.getListItemCount(), 3);
162162
});
163163

164+
test('#adapter.getAttributeForElementIndex can get value of attribute', () => {
165+
const wrapper = mount<List>(<List>{children()}</List>);
166+
const adapter = wrapper.instance().adapter;
167+
assert.equal(null, adapter.getAttributeForElementIndex(0, 'role'));
168+
adapter.setAttributeForElementIndex(0, 'role', 'menu');
169+
assert.equal('menu', adapter.getAttributeForElementIndex(0, 'role'));
170+
});
171+
164172
test('#adapter.setAttributeForElementIndex calls setAttribute on listItem', () => {
165173
const wrapper = mount<List>(<List>{children()}</List>);
166174
wrapper.instance().listElements[0].setAttribute = coerceForTesting<

0 commit comments

Comments
 (0)