Skip to content

Commit

Permalink
Fixes #44191. Site Editor: Fix bug where focus moved back erroneously…
Browse files Browse the repository at this point in the history
… to the Navigation Back Button after an input onChange event fired. Now focus remains with the focused input.
  • Loading branch information
BE-Webdesign committed Sep 17, 2022
1 parent 533e0b7 commit d594c1d
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ function NavigatorScreen( props: Props, forwardedRef: ForwardedRef< any > ) {
return;
}

const activeElement = wrapperRef.current.ownerDocument.activeElement;

// If an element is already focused within the wrapper do not focus the
// element. This prevents inputs or buttons from losing focus unecessarily.
if ( wrapperRef.current.contains( activeElement ) ) {
return;
}

let elementToFocus: HTMLElement | null = null;

// When navigating back, if a selector is provided, use it to look for the
Expand All @@ -99,7 +107,6 @@ function NavigatorScreen( props: Props, forwardedRef: ForwardedRef< any > ) {
const firstTabbable = (
focus.tabbable.find( wrapperRef.current ) as HTMLElement[]
)[ 0 ];

elementToFocus = firstTabbable ?? wrapperRef.current;
}

Expand Down

0 comments on commit d594c1d

Please sign in to comment.