Skip to content

Commit

Permalink
Update navigation sidebar responsiveness (#36638)
Browse files Browse the repository at this point in the history
* Close and open the nav sidebar in the list page

* Remove superflouous prop

* Tidy up effect
  • Loading branch information
talldan authored Nov 23, 2021
1 parent 200ab5a commit 69db0e3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
6 changes: 1 addition & 5 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,7 @@ function Editor( { initialSettings, onError } ) {
<ComplementaryArea.Slot scope="core/edit-site" />
)
}
drawer={
<NavigationSidebar
defaultIsOpen={ false }
/>
}
drawer={ <NavigationSidebar /> }
header={
<Header
openEntitiesSavedStates={
Expand Down
4 changes: 1 addition & 3 deletions packages/edit-site/src/components/list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { store as coreStore } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
import { InterfaceSkeleton } from '@wordpress/interface';
import { __, sprintf } from '@wordpress/i18n';
import { useViewportMatch } from '@wordpress/compose';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';

/**
Expand All @@ -18,7 +17,6 @@ import Table from './table';

export default function List( { templateType } ) {
useRegisterShortcuts();
const isDesktopViewport = useViewportMatch( 'medium' );

const { previousShortcut, nextShortcut } = useSelect( ( select ) => {
return {
Expand Down Expand Up @@ -64,8 +62,8 @@ export default function List( { templateType } ) {
header={ <Header templateType={ templateType } /> }
drawer={
<NavigationSidebar
defaultIsOpen={ isDesktopViewport }
activeTemplateType={ templateType }
isDefaultOpen
/>
}
content={
Expand Down
22 changes: 19 additions & 3 deletions packages/edit-site/src/components/navigation-sidebar/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';
import { useEffect, useState } from '@wordpress/element';
import { createSlotFill } from '@wordpress/components';
import { useViewportMatch } from '@wordpress/compose';

/**
* Internal dependencies
Expand All @@ -16,10 +17,25 @@ export const {
} = createSlotFill( 'EditSiteNavigationPanelPreview' );

export default function NavigationSidebar( {
defaultIsOpen = false,
isDefaultOpen = false,
activeTemplateType,
} ) {
const [ isNavigationOpen, setIsNavigationOpen ] = useState( defaultIsOpen );
const isDesktopViewport = useViewportMatch( 'medium' );
const [ isNavigationOpen, setIsNavigationOpen ] = useState(
isDefaultOpen && isDesktopViewport
);

useEffect( () => {
// When transitioning to desktop open the navigation if `isDefaultOpen` is true.
if ( isDefaultOpen && isDesktopViewport ) {
setIsNavigationOpen( true );
}

// When transitioning to mobile/tablet, close the navigation.
if ( ! isDesktopViewport ) {
setIsNavigationOpen( false );
}
}, [ isDefaultOpen, isDesktopViewport ] );

return (
<>
Expand Down

0 comments on commit 69db0e3

Please sign in to comment.