Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/utils/focusManager/focusManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,19 @@ export default class FocusManager {
}

this.tabbableNodes = tabbable(this.container);
const currentIndex = this.tabbableNodes.indexOf(e.target);
let currentIndex = this.tabbableNodes.indexOf(e.target);
if (currentIndex === -1 ) {
// if the event target is not within the tabbable nodes, then
// chances are it is a nested descendent of one of the tabbable node.
// For example, it could be button within a grid cell, where that grid cell is tabbable
// Hence we should check if any of the tabbable nodes contain our target.
this.tabbableNodes.forEach((eachNode, index) => {
if (eachNode?.contains(e.target)) {
// if a tabbable node contains our target, that was the node with the current index.
currentIndex = index;
}
});
}
const lastNode = this.tabbableNodes[this.tabbableNodes.length - 1];
const firstNode = this.tabbableNodes[0];

Expand Down