Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix region navigation in the site editor #46525

Merged
merged 4 commits into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
5 changes: 3 additions & 2 deletions packages/base-styles/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ $z-layers: (
".skip-to-selected-block": 100000,
".interface-interface-skeleton__actions": 100000,

// The focus styles of the region navigation containers should be above their content.
".is-focusing-regions {region} :focus::after": 1000000

// Show NUX tips above popovers, wp-admin menus, submenus, and sidebar:
".nux-dot-tip": 1000001,

Expand Down Expand Up @@ -177,8 +180,6 @@ $z-layers: (

// Appear under the topbar.
".customize-widgets__block-toolbar": 7,

".is-focusing-regions [role='region']:focus .interface-navigable-region__stacker": -1,
);

@function z-index( $key ) {
Expand Down
52 changes: 13 additions & 39 deletions packages/components/src/higher-order/navigate-regions/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
}

.is-focusing-regions {
[role="region"]:focus {
[role="region"]:focus::after {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
content: "";
pointer-events: none;
outline: 4px solid $components-color-accent;
outline-offset: -4px;

.interface-navigable-region__stacker {
position: relative;
z-index: z-index(".is-focusing-regions [role='region']:focus .interface-navigable-region__stacker");
}
z-index: z-index(".is-focusing-regions {region} :focus::after");
}

// Fixes for edge cases.
Expand All @@ -25,40 +28,11 @@
// regardles of the CSS used on other components.

// Header top bar when Distraction free mode is on.
&.is-distraction-free .interface-interface-skeleton__header {
.interface-navigable-region__stacker,
.edit-post-header {
outline: inherit;
outline-offset: inherit;
}
}

// Sidebar toggle button shown when navigating regions.
.interface-interface-skeleton__sidebar {
.interface-navigable-region__stacker,
.edit-post-layout__toggle-sidebar-panel {
outline: inherit;
outline-offset: inherit;
}
}

// Publish sidebar toggle button shown when navigating regions.
.interface-interface-skeleton__actions {
.interface-navigable-region__stacker,
.edit-post-layout__toggle-publish-panel {
outline: inherit;
outline-offset: inherit;
}
}

// Publish sidebar.
[role="region"].interface-interface-skeleton__actions:focus .editor-post-publish-panel {
&.is-distraction-free .interface-interface-skeleton__header .edit-post-header,
.interface-interface-skeleton__sidebar .edit-post-layout__toggle-sidebar-panel,
.interface-interface-skeleton__actions .edit-post-layout__toggle-publish-panel,
.editor-post-publish-panel {
outline: 4px solid $components-color-accent;
outline-offset: -4px;
}
}

.interface-navigable-region__stacker {
height: 100%;
width: 100%;
}
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
9 changes: 1 addition & 8 deletions packages/edit-site/src/components/list/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,11 @@
.interface-interface-skeleton__content {
background: $white;
padding: $grid-unit-20;

.interface-navigable-region__stacker {
align-items: center;
}
align-items: center;

@include break-medium() {
padding: $grid-unit * 9;
}

& > .interface-navigable-region__stacker {
height: auto;
}
}
}
}
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
14 changes: 0 additions & 14 deletions packages/interface/src/components/interface-skeleton/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,6 @@ html.interface-interface-skeleton__html-container {
}

.interface-interface-skeleton__content {
.interface-navigable-region__stacker {
// It's a flex item within a flex container with flex-direction column.
// Make sure it takes all the available height.
flex-grow: 1;
// Allow its flex items (the visual editor area) to take all the available
// height by making it also a flex container.
display: flex;
flex-direction: column;
}

flex-grow: 1;

// Treat as flex container to allow children to grow to occupy full
Expand Down Expand Up @@ -135,10 +125,6 @@ html.interface-interface-skeleton__html-container {
}

.interface-interface-skeleton__secondary-sidebar {
.interface-navigable-region__stacker {
height: 100%;
}

@include break-medium() {
border-right: $border-width solid $gray-200;
}
Expand Down
4 changes: 1 addition & 3 deletions packages/interface/src/components/navigable-region/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ export default function NavigableRegion( {
tabIndex="-1"
{ ...props }
>
<div className="interface-navigable-region__stacker">
{ children }
</div>
{ children }
</Tag>
);
}