diff --git a/packages/components/CHANGELOG.md b/packages/components/CHANGELOG.md index db4f80eb5f7fed..bb5597178f0de9 100644 --- a/packages/components/CHANGELOG.md +++ b/packages/components/CHANGELOG.md @@ -2,7 +2,10 @@ ## Unreleased +### Enhancements + - `DropZone`: Smooth animation ([#49517](https://github.com/WordPress/gutenberg/pull/49517)). +- `Navigator`: Add `skipFocus` property in `NavigateOptions`. ([#49350](https://github.com/WordPress/gutenberg/pull/49350)). ## 23.7.0 (2023-03-29) diff --git a/packages/components/src/navigator/navigator-provider/component.tsx b/packages/components/src/navigator/navigator-provider/component.tsx index 28e710fa577b2d..4c98db5b1a4d18 100644 --- a/packages/components/src/navigator/navigator-provider/component.tsx +++ b/packages/components/src/navigator/navigator-provider/component.tsx @@ -147,6 +147,7 @@ function UnconnectedNavigatorProvider( const { focusTargetSelector, isBack = false, + skipFocus = false, ...restOptions } = options; @@ -168,6 +169,7 @@ function UnconnectedNavigatorProvider( path, isBack, hasRestoredFocus: false, + skipFocus, }; if ( prevLocationHistory.length < 1 ) { diff --git a/packages/components/src/navigator/navigator-screen/component.tsx b/packages/components/src/navigator/navigator-screen/component.tsx index 2d4588d91b14d6..47b37ab65e96df 100644 --- a/packages/components/src/navigator/navigator-screen/component.tsx +++ b/packages/components/src/navigator/navigator-screen/component.tsx @@ -43,7 +43,7 @@ const animationExitDelay = 0; // as some of them would overlap with HTML props (e.g. `onAnimationStart`, ...) type Props = Omit< WordPressComponentProps< NavigatorScreenProps, 'div', false >, - keyof MotionProps + Exclude< keyof MotionProps, 'style' > >; function UnconnectedNavigatorScreen( @@ -100,11 +100,13 @@ function UnconnectedNavigatorScreen( // - when the screen becomes visible // - if the wrapper ref has been assigned // - if focus hasn't already been restored for the current location + // - if the `skipFocus` option is not set to `true`. This is useful when we trigger the navigation outside of NavigatorScreen. if ( isInitialLocation || ! isMatch || ! wrapperRef.current || - locationRef.current.hasRestoredFocus + locationRef.current.hasRestoredFocus || + location.skipFocus ) { return; } @@ -143,6 +145,7 @@ function UnconnectedNavigatorScreen( isMatch, location.isBack, location.focusTargetSelector, + location.skipFocus, ] ); const mergedWrapperRef = useMergeRefs( [ forwardedRef, wrapperRef ] ); diff --git a/packages/components/src/navigator/stories/index.tsx b/packages/components/src/navigator/stories/index.tsx index 4c8a968e881f19..fb353a354d5446 100644 --- a/packages/components/src/navigator/stories/index.tsx +++ b/packages/components/src/navigator/stories/index.tsx @@ -298,3 +298,71 @@ export const NestedNavigator: ComponentStory< typeof NavigatorProvider > = NestedNavigator.args = { initialPath: '/child2/grandchild', }; + +const NavigatorButtonWithSkipFocus = ( { + path, + onClick, + ...props +}: React.ComponentProps< typeof NavigatorButton > ) => { + const { goTo } = useNavigator(); + + return ( +