From 68604e3505360f3badc316dd0029cfff1232c13f Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Thu, 2 Dec 2021 10:24:55 +0000 Subject: [PATCH] Tweak roving tab index focus behaviour (#7254) --- src/accessibility/RovingTabIndex.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/accessibility/RovingTabIndex.tsx b/src/accessibility/RovingTabIndex.tsx index a7f8f735ce..0ef4617294 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