Skip to content

Commit

Permalink
Don't refocus if the activeElement is still on the page
Browse files Browse the repository at this point in the history
  • Loading branch information
kevin940726 committed Feb 22, 2022
1 parent 0212be2 commit 191b2af
Showing 1 changed file with 6 additions and 1 deletion.
Expand Up @@ -35,6 +35,11 @@ export default function useResetFocusOnRouteChange( targetRef ) {
}
}

targetRef.current?.focus();
const activeElement = targetRef.current?.ownerDocument.activeElement;

// Don't refocus if the activeElement is still on the page (like NavLink).
if ( ! activeElement || activeElement === document.body ) {
targetRef.current?.focus();
}
}, [ location, targetRef, history ] );
}

0 comments on commit 191b2af

Please sign in to comment.