Skip to content
Merged
Show file tree
Hide file tree
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
Revert custom back button behaviour
  • Loading branch information
tellthemachines committed May 29, 2023
commit a107162929cacdd984617b7fd7b0ae3a5949c830
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 @@ -24,7 +24,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 @@ -32,7 +31,6 @@ export default function SidebarNavigationScreen( {
content,
footer,
description,
backToPreviousScreen = false,
} ) {
const { dashboardLink } = useSelect( ( select ) => {
const { getSettings } = unlock( select( editSiteStore ) );
Expand All @@ -42,9 +40,7 @@ export default function SidebarNavigationScreen( {
}, [] );
const { getTheme } = useSelect( coreStore );
const theme = getTheme( currentlyPreviewingTheme() );
const NavigatorReturnButton = backToPreviousScreen
? NavigatorBackButton
: NavigatorToParentButton;

return (
<VStack spacing={ 0 }>
<HStack
Expand All @@ -53,7 +49,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