Skip to content

Commit

Permalink
fix: change to validateIndex_
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Goo committed Apr 29, 2019
1 parent b828770 commit 03bb86e
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions packages/mdc-menu/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ export class MDCMenuFoundation extends MDCFoundation<MDCMenuAdapter> {
* @param index Index of list item within the menu.
*/
setSelectedIndex(index: number) {
if (!this.isIndexValid_(index)) {
return;
}
this.validatedIndex_(index);

if (!this.adapter_.isSelectableItemAtIndex(index)) {
throw new Error('MDCMenuFoundation: No selection group at specified index.');
Expand All @@ -152,13 +150,11 @@ export class MDCMenuFoundation extends MDCFoundation<MDCMenuAdapter> {
this.adapter_.addAttributeToElementAtIndex(index, strings.ARIA_SELECTED_ATTR, 'true');
}

private isIndexValid_(index: number): boolean {
private validatedIndex_(index: number): void {
const menuSize = this.adapter_.getMenuItemCount();
const isIndexInRange = index >= 0 && index < menuSize;

if (isIndexInRange) {
return true;
} else {
if (!isIndexInRange) {
throw new Error('MDCMenuFoundation: No list item at specified index.');
}
}
Expand Down

0 comments on commit 03bb86e

Please sign in to comment.