Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Don't refocus if the activeElement is still on the page
  • Loading branch information
kevin940726 committed Mar 1, 2022
commit 3067f9abf1f0c8fc6f737a13616c32c495c0ac62
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 ] );
}