I have a data grid that on right arrow key, it needs to check that it has both the last child in the header and that the last child has class focus-visible
applied to it on keydown. I'm able to find both the last child and the active element with focus-visible
, but having an issue with my logic finding that the last child has focus-visible
when the user hits the arrow key to set focus on the last child.
This is my logic so far, but not sure where I'm going wrong on checking the class is on the last child:
//
//ON ARROW RIGHT, IF FOCUS IS ON LAST HEADER, SET FOCUS TO FIRST BODY CELL
//
if(e.key === "ArrowRight") {
let headerId = document.activeElement.parentElement.parentElement.getAttribute("col-id");
//Get last child
const headerCell = document.querySelector('.ag-header-cell:last-child').children[1].children[1];
//focus visible class on nav element
const hasFocusVisible = document.activeElement.classList.contains('focus-visible');
console.log("last child: ", headerCell);
console.log("has focus visible: ", hasFocusVisible);
if(headerCell.classList.contains('focus-visible')) {
//if headerCell and hasFocusVisible, set focus to first cell in body
document.querySelector('.ag-cell').focus();
}
}
Current state of issue: Plnkr Link