Consider refactoring "ariaPressedState()" function
Opened this issue · 0 comments
rmenner commented
The function args is not even used in the function it is passed into. It just gets passed in and returned right back out without any mutations.
ariaPressedState(ariaPressed) {
const ariaToggle = function (event) {
const ariaPressedNode = this.shadowRoot.querySelector('[aria-pressed]');
ariaPressedNode.setAttribute("aria-pressed", 'false');
if (event.type === 'mousedown') {
ariaPressedNode.ariaPressed = true;
} else {
ariaPressedNode.ariaPressed = false;
}
if (event.type === 'keydown') {
if (event.code === 'Enter' || event.code === 'Space') {
ariaPressedNode.ariaPressed = true;
} else {
ariaPressedNode.ariaPressed = false;
}
}
};
// Add event listeners
this.addEventListener('mousedown', ariaToggle);
this.addEventListener('mouseup', ariaToggle);
this.addEventListener('keydown', ariaToggle);
this.addEventListener('keyup', ariaToggle);
return ariaPressed;
}