From 00f2ef1865e3f3528797ab2429e2553e314641a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=ED=83=9C=EC=9E=AC=EC=98=81?= Date: Thu, 27 Jun 2019 02:37:40 +0900 Subject: [PATCH] feat(list): Implement getAttributeForElementIndex (#948) --- packages/list/index.tsx | 7 ++++--- test/unit/list/index.test.tsx | 8 ++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/list/index.tsx b/packages/list/index.tsx index 06adaf530..1439e6d44 100644 --- a/packages/list/index.tsx +++ b/packages/list/index.tsx @@ -217,15 +217,16 @@ export default class List extends React.Component { 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. */ diff --git a/test/unit/list/index.test.tsx b/test/unit/list/index.test.tsx index 80d87d109..3b6335aa6 100644 --- a/test/unit/list/index.test.tsx +++ b/test/unit/list/index.test.tsx @@ -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({children()}); + 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({children()}); wrapper.instance().listElements[0].setAttribute = coerceForTesting<