Skip to content

Commit

Permalink
fix(list): Change private getter method to public (#3473)
Browse files Browse the repository at this point in the history
Changes private method listElements_ to listElements.
  • Loading branch information
williamernest authored Aug 29, 2018
1 parent 453b5c5 commit f57c731
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
24 changes: 12 additions & 12 deletions packages/mdc-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -153,7 +153,7 @@ class MDCList extends MDCComponent {
}

this.singleSelection = true;
this.selectedIndex = this.listElements_.indexOf(preselectedElement);
this.selectedIndex = this.listElements.indexOf(preselectedElement);
}
}

Expand All @@ -163,7 +163,7 @@ class MDCList extends MDCComponent {
}

/** @return Array<!Element>*/
get listElements_() {
get listElements() {
return [].slice.call(this.root_.querySelectorAll(strings.ENABLED_ITEMS_SELECTOR));
}

Expand Down Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/mdc-menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class MDCMenu extends MDCComponent {
* @return {!Array<!HTMLElement>}
*/
get items() {
return this.list_.listElements_;
return this.list_.listElements;
}

/**
Expand Down
12 changes: 6 additions & 6 deletions test/unit/mdc-menu/mdc-menu.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
}

Expand Down Expand Up @@ -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));
});

Expand Down Expand Up @@ -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(() => {
Expand Down

0 comments on commit f57c731

Please sign in to comment.