Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 68604e3

Browse files
authored
Tweak roving tab index focus behaviour (#7254)
1 parent 0afe141 commit 68604e3

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/accessibility/RovingTabIndex.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ export const reducer = (state: IState, action: IAction) => {
130130
state.activeRef = findSiblingElement(state.refs, oldIndex)
131131
|| findSiblingElement(state.refs, oldIndex, true);
132132
}
133-
state.activeRef?.current?.focus();
133+
if (document.activeElement === document.body) {
134+
// if the focus got reverted to the body then the user was likely focused on the unmounted element
135+
state.activeRef?.current?.focus();
136+
}
134137
}
135138

136139
// update the refs list

0 commit comments

Comments
 (0)