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
Next Next commit
Fix region navigation in the site editor
  • Loading branch information
youknowriad committed Dec 15, 2022
commit 58421c4922839bad5c7e580106f0ee9e9116bc6b
17 changes: 1 addition & 16 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
EntitiesSavedStates,
} from '@wordpress/editor';
import { __ } from '@wordpress/i18n';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';

/**
* Internal dependencies
Expand Down Expand Up @@ -64,8 +63,6 @@ export default function Editor() {
isInserterOpen,
isListViewOpen,
isSaveViewOpen,
previousShortcut,
nextShortcut,
showIconLabels,
} = useSelect( ( select ) => {
const {
Expand All @@ -80,9 +77,6 @@ export default function Editor() {
} = select( editSiteStore );
const { hasFinishedResolution, getEntityRecord } = select( coreStore );
const { __unstableGetEditorMode } = select( blockEditorStore );
const { getAllShortcutKeyCombinations } = select(
keyboardShortcutsStore
);
const { getActiveComplementaryArea } = select( interfaceStore );
const postType = getEditedPostType();
const postId = getEditedPostId();
Expand Down Expand Up @@ -112,12 +106,6 @@ export default function Editor() {
isRightSidebarOpen: getActiveComplementaryArea(
editSiteStore.name
),
previousShortcut: getAllShortcutKeyCombinations(
'core/edit-site/previous-region'
),
nextShortcut: getAllShortcutKeyCombinations(
'core/edit-site/next-region'
),
showIconLabels: select( preferencesStore ).get(
'core/edit-site',
'showIconLabels'
Expand Down Expand Up @@ -178,6 +166,7 @@ export default function Editor() {
<BlockContextProvider value={ blockContext }>
<SidebarComplementaryAreaFills />
<InterfaceSkeleton
enableRegionNavigation={ false }
className={
showIconLabels && 'show-icon-labels'
}
Expand Down Expand Up @@ -258,10 +247,6 @@ export default function Editor() {
/>
)
}
shortcuts={ {
previous: previousShortcut,
next: nextShortcut,
} }
labels={ {
...interfaceLabels,
secondarySidebar: secondarySidebarLabel,
Expand Down
59 changes: 41 additions & 18 deletions packages/edit-site/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
__experimentalHStack as HStack,
__unstableMotion as motion,
__unstableAnimatePresence as AnimatePresence,
__unstableUseNavigateRegions as useNavigateRegions,
} from '@wordpress/components';
import {
useReducedMotion,
Expand All @@ -22,6 +23,7 @@ import { __ } from '@wordpress/i18n';
import { store as blockEditorStore } from '@wordpress/block-editor';
import { useState, useEffect } from '@wordpress/element';
import { NavigableRegion } from '@wordpress/interface';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';

/**
* Internal dependencies
Expand All @@ -47,15 +49,28 @@ export default function Layout( { onError } ) {
const { params } = useLocation();
const isListPage = getIsListPage( params );
const isEditorPage = ! isListPage;
const { canvasMode, dashboardLink } = useSelect(
( select ) => ( {
canvasMode: select( editSiteStore ).__unstableGetCanvasMode(),
dashboardLink:
select( editSiteStore ).getSettings()
.__experimentalDashboardLink,
} ),
[]
);
const { canvasMode, dashboardLink, previousShortcut, nextShortcut } =
useSelect( ( select ) => {
const { getAllShortcutKeyCombinations } = select(
keyboardShortcutsStore
);
const { __unstableGetCanvasMode, getSettings } =
select( editSiteStore );
return {
canvasMode: __unstableGetCanvasMode(),
dashboardLink: getSettings().__experimentalDashboardLink,
previousShortcut: getAllShortcutKeyCombinations(
'core/edit-site/previous-region'
),
nextShortcut: getAllShortcutKeyCombinations(
'core/edit-site/next-region'
),
};
}, [] );
const navigateRegionsProps = useNavigateRegions( {
previous: previousShortcut,
next: nextShortcut,
} );
const { __unstableSetCanvasMode } = useDispatch( editSiteStore );
const { clearSelectedBlock } = useDispatch( blockEditorStore );
const disableMotion = useReducedMotion();
Expand Down Expand Up @@ -108,13 +123,19 @@ export default function Layout( { onError } ) {
<>
{ fullResizer }
<div
className={ classnames( 'edit-site-layout', {
'is-full-canvas':
( isEditorPage &&
canvasMode === 'edit' &&
! isMobileViewport ) ||
isMobileCanvasVisible,
} ) }
{ ...navigateRegionsProps }
ref={ navigateRegionsProps.ref }
className={ classnames(
'edit-site-layout',
navigateRegionsProps.className,
{
'is-full-canvas':
( isEditorPage &&
canvasMode === 'edit' &&
! isMobileViewport ) ||
isMobileCanvasVisible,
}
) }
>
<div className="edit-site-layout__header">
<div className="edit-site-layout__logo">
Expand Down Expand Up @@ -196,7 +217,8 @@ export default function Layout( { onError } ) {

<AnimatePresence initial={ false }>
{ showSidebar && (
<motion.div
<NavigableRegion
as={ motion.div }
initial={ {
opacity: 0,
} }
Expand All @@ -214,9 +236,10 @@ export default function Layout( { onError } ) {
ease: 'easeOut',
} }
className="edit-site-layout__sidebar"
ariaLabel={ __( 'Navigation sidebar' ) }
>
<Sidebar />
</motion.div>
</NavigableRegion>
) }
</AnimatePresence>

Expand Down
8 changes: 6 additions & 2 deletions packages/interface/src/components/interface-skeleton/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function InterfaceSkeleton(
actions,
labels,
className,
enableRegionNavigation = true,
// Todo: does this need to be a prop.
// Can we use a dependency to keyboard-shortcuts directly?
shortcuts,
Expand Down Expand Up @@ -83,8 +84,11 @@ function InterfaceSkeleton(

return (
<div
{ ...navigateRegionsProps }
ref={ useMergeRefs( [ ref, navigateRegionsProps.ref ] ) }
{ ...( enableRegionNavigation ? navigateRegionsProps : {} ) }
ref={ useMergeRefs( [
ref,
enableRegionNavigation ? navigateRegionsProps.ref : undefined,
] ) }
className={ classnames(
className,
'interface-interface-skeleton',
Expand Down