Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(evt: React.MouseEvent) => {
props.onClick?.(evt);
const index = getListItemIndex(evt);
// Toggle the checkbox only if it's not the target of the event, or the checkbox will have 2 change events.
const toggleCheckbox = !matches(
evt.target as HTMLElement,
MDCListFoundation.strings.CHECKBOX_RADIO_SELECTOR
);
foundation.handleClick(index, toggleCheckbox);
},
[getListItemIndex, foundation, props.onClick]
handleClick(evt: React.MouseEvent) {
this.props.onClick && this.props.onClick(evt);
const index = this.getListItemIndex(evt);
// Toggle the checkbox only if it's not the target of the event, or the checkbox will have 2 change events.
const toggleCheckbox = !matches(
evt.target as HTMLElement,
MDCListFoundation.strings.CHECKBOX_RADIO_SELECTOR
);
this.foundation.handleClick(index, toggleCheckbox);
}
isCheckboxCheckedAtIndex: (index: number) => {
const listItem = this.listElements[index];
const toggleEl = listItem.querySelector(
MDCListFoundation.strings.CHECKBOX_SELECTOR
) as HTMLInputElement | null;
return toggleEl ? toggleEl.checked : false;
},
setCheckedCheckboxOrRadioAtIndex: (
setTabIndexForListItemChildren: (
listItemIndex: number,
tabIndexValue: string | number
) => {
const element = listElements(rootEl.ref)[listItemIndex];
const listItemChildren: Element[] = [].slice.call(
element.querySelectorAll(
MDCListFoundation.strings.CHILD_ELEMENTS_TO_TOGGLE_TABINDEX
)
);
listItemChildren.forEach(ele =>
ele.setAttribute('tabindex', String(tabIndexValue))
);
},
hasCheckboxAtIndex: (index: number) => {