Skip to content

Commit

Permalink
feat(list): Implement getAttributeForElementIndex (#948)
Browse files Browse the repository at this point in the history
  • Loading branch information
태재영 authored and Matt Goo committed Jun 26, 2019
1 parent e95ff65 commit 00f2ef1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,16 @@ export default class List extends React.Component<ListProps, ListState> {
getListItemCount: () => this.listElements.length,
getFocusedElementIndex: () =>
this.listElements.indexOf(document.activeElement as HTMLLIElement),
getAttributeForElementIndex: (index, attr) => {
const listItem = this.listElements[index];
return listItem.getAttribute(attr);
},
setAttributeForElementIndex: (index, attr, value) => {
const listItem = this.listElements[index];
if (listItem) {
listItem.setAttribute(attr, value);
}
},
// TODO: implement
// https://github.com/material-components/material-components-web-react/issues/822
getAttributeForElementIndex: () => '',
/**
* Pushes class name to state.listItemClassNames[listItemIndex] if it doesn't yet exist.
*/
Expand Down
8 changes: 8 additions & 0 deletions test/unit/list/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,14 @@ test('#adapter.getListItemCount returns correct number of list items if List has
assert.equal(wrapper.instance().adapter.getListItemCount(), 3);
});

test('#adapter.getAttributeForElementIndex can get value of attribute', () => {
const wrapper = mount<List>(<List>{children()}</List>);
const adapter = wrapper.instance().adapter;
assert.equal(null, adapter.getAttributeForElementIndex(0, 'role'));
adapter.setAttributeForElementIndex(0, 'role', 'menu');
assert.equal('menu', adapter.getAttributeForElementIndex(0, 'role'));
});

test('#adapter.setAttributeForElementIndex calls setAttribute on listItem', () => {
const wrapper = mount<List>(<List>{children()}</List>);
wrapper.instance().listElements[0].setAttribute = coerceForTesting<
Expand Down

0 comments on commit 00f2ef1

Please sign in to comment.