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 Dec 14, 2021
1 parent 1b50ad1 commit d60ce2a
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
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 d60ce2a

Please sign in to comment.