Skip to content

Commit 4946020

Browse files
authored
fix: focus manager use with grid manager (#1228)
fix: In this change, we fix an issue with the focus manager which prevented focus from traveling into a tabbable element positioned after a focus-manged grid inside a popover. Using a grid, with controls in its cells, inside a popover (DatePicker) caused tabbable nodes expected by the focus manager to be changed by the grid manager. This is seen in Datepicker where it was not possible to navigate to the today footer button with keyboard tabbing.
1 parent 26e8fb0 commit 4946020

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/utils/focusManager/focusManager.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,19 @@ export default class FocusManager {
3838
}
3939

4040
this.tabbableNodes = tabbable(this.container);
41-
const currentIndex = this.tabbableNodes.indexOf(e.target);
41+
let currentIndex = this.tabbableNodes.indexOf(e.target);
42+
if (currentIndex === -1 ) {
43+
// if the event target is not within the tabbable nodes, then
44+
// chances are it is a nested descendent of one of the tabbable node.
45+
// For example, it could be button within a grid cell, where that grid cell is tabbable
46+
// Hence we should check if any of the tabbable nodes contain our target.
47+
this.tabbableNodes.forEach((eachNode, index) => {
48+
if (eachNode?.contains(e.target)) {
49+
// if a tabbable node contains our target, that was the node with the current index.
50+
currentIndex = index;
51+
}
52+
});
53+
}
4254
const lastNode = this.tabbableNodes[this.tabbableNodes.length - 1];
4355
const firstNode = this.tabbableNodes[0];
4456

0 commit comments

Comments
 (0)