diff --git a/src/accessibility/RovingTabIndex.tsx b/src/accessibility/RovingTabIndex.tsx index a7f8f735cec..0ef46172940 100644 --- a/src/accessibility/RovingTabIndex.tsx +++ b/src/accessibility/RovingTabIndex.tsx @@ -130,7 +130,10 @@ export const reducer = (state: IState, action: IAction) => { state.activeRef = findSiblingElement(state.refs, oldIndex) || findSiblingElement(state.refs, oldIndex, true); } - state.activeRef?.current?.focus(); + if (document.activeElement === document.body) { + // if the focus got reverted to the body then the user was likely focused on the unmounted element + state.activeRef?.current?.focus(); + } } // update the refs list