From f57c7318bd1cb9fd56206b7657a139ac225bb274 Mon Sep 17 00:00:00 2001 From: Will Ernest <34519388+williamernest@users.noreply.github.com> Date: Wed, 29 Aug 2018 15:19:47 -0700 Subject: [PATCH] fix(list): Change private getter method to public (#3473) Changes private method listElements_ to listElements. --- packages/mdc-list/index.js | 24 ++++++++++++------------ packages/mdc-menu/index.js | 2 +- test/unit/mdc-menu/mdc-menu.test.js | 12 ++++++------ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/mdc-list/index.js b/packages/mdc-list/index.js index 7e19fa93b1a..4c6d3abae9a 100644 --- a/packages/mdc-list/index.js +++ b/packages/mdc-list/index.js @@ -103,7 +103,7 @@ class MDCList extends MDCComponent { // Get the index of the element if it is a list item. if (eventTarget.classList.contains(cssClasses.LIST_ITEM_CLASS)) { - index = this.listElements_.indexOf(eventTarget); + index = this.listElements.indexOf(eventTarget); } return index; @@ -153,7 +153,7 @@ class MDCList extends MDCComponent { } this.singleSelection = true; - this.selectedIndex = this.listElements_.indexOf(preselectedElement); + this.selectedIndex = this.listElements.indexOf(preselectedElement); } } @@ -163,7 +163,7 @@ class MDCList extends MDCComponent { } /** @return Array*/ - get listElements_() { + get listElements() { return [].slice.call(this.root_.querySelectorAll(strings.ENABLED_ITEMS_SELECTOR)); } @@ -191,45 +191,45 @@ class MDCList extends MDCComponent { /** @return {!MDCListFoundation} */ getDefaultFoundation() { return new MDCListFoundation(/** @type {!MDCListAdapter} */ (Object.assign({ - getListItemCount: () => this.listElements_.length, - getFocusedElementIndex: () => this.listElements_.indexOf(document.activeElement), + getListItemCount: () => this.listElements.length, + getFocusedElementIndex: () => this.listElements.indexOf(document.activeElement), setAttributeForElementIndex: (index, attr, value) => { - const element = this.listElements_[index]; + const element = this.listElements[index]; if (element) { element.setAttribute(attr, value); } }, removeAttributeForElementIndex: (index, attr) => { - const element = this.listElements_[index]; + const element = this.listElements[index]; if (element) { element.removeAttribute(attr); } }, addClassForElementIndex: (index, className) => { - const element = this.listElements_[index]; + const element = this.listElements[index]; if (element) { element.classList.add(className); } }, removeClassForElementIndex: (index, className) => { - const element = this.listElements_[index]; + const element = this.listElements[index]; if (element) { element.classList.remove(className); } }, focusItemAtIndex: (index) => { - const element = this.listElements_[index]; + const element = this.listElements[index]; if (element) { element.focus(); } }, setTabIndexForListItemChildren: (listItemIndex, tabIndexValue) => { - const element = this.listElements_[listItemIndex]; + const element = this.listElements[listItemIndex]; const listItemChildren = [].slice.call(element.querySelectorAll(strings.FOCUSABLE_CHILD_ELEMENTS)); listItemChildren.forEach((ele) => ele.setAttribute('tabindex', tabIndexValue)); }, followHref: (index) => { - const listItem = this.listElements_[index]; + const listItem = this.listElements[index]; if (listItem && listItem.href) { listItem.click(); } diff --git a/packages/mdc-menu/index.js b/packages/mdc-menu/index.js index 23e2f9ca41d..6b592a6d46e 100644 --- a/packages/mdc-menu/index.js +++ b/packages/mdc-menu/index.js @@ -121,7 +121,7 @@ class MDCMenu extends MDCComponent { * @return {!Array} */ get items() { - return this.list_.listElements_; + return this.list_.listElements; } /** diff --git a/test/unit/mdc-menu/mdc-menu.test.js b/test/unit/mdc-menu/mdc-menu.test.js index 608dae597d2..240f96acfaf 100644 --- a/test/unit/mdc-menu/mdc-menu.test.js +++ b/test/unit/mdc-menu/mdc-menu.test.js @@ -52,7 +52,7 @@ class FakeList { this.root = root; this.destroy = td.func('.destroy'); this.itemsContainer = td.func('.root_'); - this.listElements_ = [].slice.call(root.querySelectorAll('.mdc-list-item')); + this.listElements = [].slice.call(root.querySelectorAll('.mdc-list-item')); } } @@ -179,28 +179,28 @@ test('setQuickOpen', () => { test('items returns all menu items', () => { const {root, component, list} = setupTestWithFakes(); const items = [].slice.call(root.querySelectorAll('[role="menuitem"]')); - list.listElements_ = items; + list.listElements = items; assert.deepEqual(component.items, items); }); test('items returns nothing if list is not defined', () => { const {root, component, list} = setupTestWithFakes(); const items = [].slice.call(root.querySelectorAll('[role="menuitem"]')); - list.listElements_ = items; + list.listElements = items; assert.deepEqual(component.items, items); }); test('getOptionByIndex', () => { const {root, component, list} = setupTestWithFakes(); const items = [].slice.call(root.querySelectorAll('[role="menuitem"]')); - list.listElements_ = items; + list.listElements = items; assert.deepEqual(component.getOptionByIndex(0), items[0]); }); test('getOptionByIndex returns null if index is > list length', () => { const {root, component, list} = setupTestWithFakes(); const items = [].slice.call(root.querySelectorAll('[role="menuitem"]')); - list.listElements_ = items; + list.listElements = items; assert.isNull(component.getOptionByIndex(items.length)); }); @@ -268,7 +268,7 @@ test('menu surface opened event causes no element to be focused if the list is e test('open=true does not throw an error if there are no items in the list to focus', () => { const {component, root, list} = setupTestWithFakes(); - list.listElements_ = []; + list.listElements = []; document.body.appendChild(root); root.querySelector('.mdc-list-item'); assert.doesNotThrow(() => {