Skip to content

Commit

Permalink
Revert custom back button behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
tellthemachines committed May 26, 2023
1 parent 186af35 commit 91f49c5
Show file tree
Hide file tree
Showing 8 changed files with 8 additions and 31 deletions.
1 change: 0 additions & 1 deletion packages/components/src/navigator/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@ const initialContextValue: NavigatorContextType = {
addScreen: () => {},
removeScreen: () => {},
params: {},
backToPreviousScreen: false,
};
export const NavigatorContext = createContext( initialContextValue );
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,8 @@ function UnconnectedNavigatorProvider(
props: WordPressComponentProps< NavigatorProviderProps, 'div' >,
forwardedRef: ForwardedRef< any >
) {
const {
initialPath,
children,
className,
backToPreviousScreen,
...otherProps
} = useContextSystem( props, 'NavigatorProvider' );
const { initialPath, children, className, ...otherProps } =
useContextSystem( props, 'NavigatorProvider' );

const [ locationHistory, setLocationHistory ] = useState<
NavigatorLocation[]
Expand Down Expand Up @@ -235,7 +230,6 @@ function UnconnectedNavigatorProvider(
goToParent,
addScreen,
removeScreen,
backToPreviousScreen,
} ),
[
locationHistory,
Expand All @@ -245,7 +239,6 @@ function UnconnectedNavigatorProvider(
goToParent,
addScreen,
removeScreen,
backToPreviousScreen,
]
);

Expand Down
8 changes: 0 additions & 8 deletions packages/components/src/navigator/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ export type Navigator = {
goTo: ( path: string, options?: NavigateOptions ) => void;
goBack: () => void;
goToParent: () => void;
backToPreviousScreen?: boolean;
};

export type NavigatorContext = Navigator & {
Expand All @@ -47,13 +46,6 @@ export type NavigatorProviderProps = {
* The children elements.
*/
children: ReactNode;
/**
* Whether the navigator should restore focus to the previous screen when
* navigating back.
*
* @default false
*/
backToPreviousScreen?: boolean;
};

export type NavigatorScreenProps = {
Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/navigator/use-navigator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import type { Navigator } from './types';
* Retrieves a `navigator` instance.
*/
function useNavigator(): Navigator {
const { location, params, goTo, goBack, goToParent, backToPreviousScreen } =
const { location, params, goTo, goBack, goToParent } =
useContext( NavigatorContext );

return {
location,
goTo,
goBack,
goToParent,
params,
backToPreviousScreen,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const PageItem = ( { postType = 'page', postId, ...props } ) => {
const linkInfo = useLink( {
postType,
postId,
backToPreviousScreen: true,
} );
return <SidebarNavigationItem { ...linkInfo } { ...props } />;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function useTemplateTitleAndDescription( postType, postId ) {
}

export default function SidebarNavigationScreenTemplate() {
const { params, backToPreviousScreen } = useNavigator();
const { params } = useNavigator();
const { postType, postId } = params;
const { setCanvasMode } = unlock( useDispatch( editSiteStore ) );
const { title, description } = useTemplateTitleAndDescription(
Expand All @@ -106,7 +106,6 @@ export default function SidebarNavigationScreenTemplate() {
/>
}
description={ description }
backToPreviousScreen={ backToPreviousScreen }
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
__experimentalHStack as HStack,
__experimentalVStack as VStack,
__experimentalNavigatorToParentButton as NavigatorToParentButton,
__experimentalNavigatorBackButton as NavigatorBackButton,
__experimentalHeading as Heading,
} from '@wordpress/components';
import { isRTL, __, sprintf } from '@wordpress/i18n';
Expand All @@ -30,7 +29,6 @@ export default function SidebarNavigationScreen( {
actions,
content,
description,
backToPreviousScreen = false,
} ) {
const { dashboardLink } = useSelect( ( select ) => {
const { getSettings } = unlock( select( editSiteStore ) );
Expand All @@ -40,9 +38,7 @@ export default function SidebarNavigationScreen( {
}, [] );
const { getTheme } = useSelect( coreStore );
const theme = getTheme( currentlyPreviewingTheme() );
const NavigatorReturnButton = backToPreviousScreen
? NavigatorBackButton
: NavigatorToParentButton;

return (
<VStack spacing={ 2 }>
<HStack
Expand All @@ -51,7 +47,7 @@ export default function SidebarNavigationScreen( {
className="edit-site-sidebar-navigation-screen__title-icon"
>
{ ! isRoot ? (
<NavigatorReturnButton
<NavigatorToParentButton
as={ SidebarButton }
icon={ isRTL() ? chevronRight : chevronLeft }
label={ __( 'Back' ) }
Expand Down
3 changes: 1 addition & 2 deletions packages/edit-site/src/components/sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,12 @@ function SidebarScreens() {
function Sidebar() {
const { params: urlParams } = useLocation();
const initialPath = useRef( getPathFromURL( urlParams ) );
const { backToPreviousScreen } = urlParams;

return (
<>
<NavigatorProvider
className="edit-site-sidebar__content"
initialPath={ initialPath.current }
backToPreviousScreen={ backToPreviousScreen }
>
<SidebarScreens />
</NavigatorProvider>
Expand Down

0 comments on commit 91f49c5

Please sign in to comment.