Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private getListItemIndex_(evt: Event) {
const eventTarget = evt.target as Element;
const nearestParent = closest(eventTarget, `.${cssClasses.LIST_ITEM_CLASS}, .${cssClasses.ROOT}`);
// Get the index of the element if it is a list item.
if (nearestParent && matches(nearestParent, `.${cssClasses.LIST_ITEM_CLASS}`)) {
return this.listElements.indexOf(nearestParent);
}
return -1;
}
isSelectableItemAtIndex: index =>
!!closest(this.items[index], `.${cssClasses.MENU_SELECTION_GROUP}`),
getSelectedSiblingOfItemAtIndex: index => {
getRowIndexByChildElement: (el: Element) => {
return this.getRows().indexOf((closest(el, strings.ROW_SELECTOR) as HTMLElement));
},
getSelectedRowCount: () => this.root_.querySelectorAll(strings.ROW_SELECTED_SELECTOR).length,
isActionIcon_(target) {
return Boolean(
closest(target, MDCSnackbarFoundation.strings.DISMISS_SELECTOR),
);
},
private isActionIcon_(target: Element): boolean {
return Boolean(closest(target, DISMISS_SELECTOR));
}
}
getSelectedSiblingOfItemAtIndex: index => {
const selectionGroupEl = closest(
this.items[index],
`.${cssClasses.MENU_SELECTION_GROUP}`,
);
const selectedItemEl = selectionGroupEl.querySelector(
`.${cssClasses.MENU_SELECTED_LIST_ITEM}`,
);
return selectedItemEl ? this.items.indexOf(selectedItemEl) : -1;
},
notifySelected: evtData => {
isSelectableItemAtIndex: (index: number) =>
!!closest(this.listItems.toArray()[index].getListItemElement(), `.${cssClasses.MENU_SELECTION_GROUP}`),
getSelectedSiblingOfItemAtIndex: (index: number) => {
private isActionButton_(target: Element): boolean {
return Boolean(closest(target, ACTION_SELECTOR));
}
getActionFromEvent: (evt: Event) => {
if (!evt.target) {
return '';
}
const element = closest(evt.target as Element, `[${strings.ACTION_ATTRIBUTE}]`);
return element && element.getAttribute(strings.ACTION_ATTRIBUTE);
},
hasClass: (className) => this.root_.classList.contains(className),
getSelectedSiblingOfItemAtIndex: (index) => {
if (!this.listElement) {
return -1;
}
const elementAtIndex =
mwcList.getElementAtIndex(this.listElement, index);
if (!elementAtIndex) {
return -1;
}
const selectionGroupEl =
closest(elementAtIndex, '.mdc-menu__selection-group');
if (!selectionGroupEl) {
return -1;
}
const selectedItemEl =
selectionGroupEl.querySelector('.mdc-menu-item--selected');
if (!selectedItemEl) {
return -1;
}
const elements = mwcList.listElements(this.listElement);
return elements.indexOf(selectedItemEl);
},