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 template footer click to focus canvas #62290

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions packages/base-styles/_mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -597,3 +597,17 @@
}
}
}

@mixin selected-block-outline() {
content: "";
position: absolute;
pointer-events: none;
top: 0;
right: 0;
bottom: 0;
left: 0;
outline-color: var(--wp-admin-theme-color);
outline-style: solid;
outline-width: calc(var(--wp-admin-border-width-focus) / var(--wp-block-editor-iframe-zoom-out-scale, 1));
outline-offset: calc((-1 * var(--wp-admin-border-width-focus)) / var(--wp-block-editor-iframe-zoom-out-scale, 1));
}
1 change: 1 addition & 0 deletions packages/block-editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ _Parameters_

- _props_ `Object`: Component props.
- _props.rootLabelText_ `string`: Translated label for the root element of the breadcrumb trail.
- _props.focusableWrapperRef_ `Object`: Ref of the element to focus when the breadcrumb is clicked.

_Returns_

Expand Down
16 changes: 11 additions & 5 deletions packages/block-editor/src/components/block-breadcrumb/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ import { unlock } from '../../lock-unlock';
/**
* Block breadcrumb component, displaying the hierarchy of the current block selection as a breadcrumb.
*
* @param {Object} props Component props.
* @param {string} props.rootLabelText Translated label for the root element of the breadcrumb trail.
* @return {Element} Block Breadcrumb.
* @param {Object} props Component props.
* @param {string} props.rootLabelText Translated label for the root element of the breadcrumb trail.
* @param {Object} props.focusableWrapperRef Ref of the element to focus when the breadcrumb is clicked.
* @return {Element} Block Breadcrumb.
*/
function BlockBreadcrumb( { rootLabelText } ) {
function BlockBreadcrumb( { rootLabelText, focusableWrapperRef } ) {
const { selectBlock, clearSelectedBlock } = useDispatch( blockEditorStore );
const { clientId, parents, hasSelection } = useSelect( ( select ) => {
const {
Expand Down Expand Up @@ -60,7 +61,12 @@ function BlockBreadcrumb( { rootLabelText } ) {
<Button
className="block-editor-block-breadcrumb__button"
variant="tertiary"
onClick={ clearSelectedBlock }
onClick={ () => {
clearSelectedBlock();

// Focus the editor iframe.
focusableWrapperRef.current?.focus();
} }
>
{ rootLabel }
</Button>
Expand Down
24 changes: 21 additions & 3 deletions packages/block-editor/src/components/block-canvas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* WordPress dependencies
*/
import { useMergeRefs } from '@wordpress/compose';
import { useRef } from '@wordpress/element';
import { useRef, forwardRef } from '@wordpress/element';

/**
* Internal dependencies
Expand All @@ -16,13 +16,27 @@ import { useMouseMoveTypingReset } from '../observe-typing';
import { useBlockSelectionClearer } from '../block-selection-clearer';
import { useBlockCommands } from '../use-block-commands';

const FocusableWrapper = forwardRef( ( { children }, ref ) => {
return (
<div
className="block-editor-accessible-wrapper"
tabIndex="-1"
aria-label="Block canvas"
ref={ ref }
>
{ children }
</div>
);
} );

export function ExperimentalBlockCanvas( {
shouldIframe = true,
height = '300px',
children = <BlockList />,
styles,
contentRef: contentRefProp,
iframeProps,
focusableWrapperRef,
} ) {
useBlockCommands();
const resetTypingRef = useMouseMoveTypingReset();
Expand All @@ -49,7 +63,9 @@ export function ExperimentalBlockCanvas( {
width: '100%',
} }
>
{ children }
<FocusableWrapper ref={ focusableWrapperRef }>
{ children }
</FocusableWrapper>
</WritingFlow>
</BlockTools>
);
Expand All @@ -70,7 +86,9 @@ export function ExperimentalBlockCanvas( {
name="editor-canvas"
>
<EditorStyles styles={ styles } />
{ children }
<FocusableWrapper ref={ focusableWrapperRef }>
{ children }
</FocusableWrapper>
</Iframe>
</BlockTools>
);
Expand Down
18 changes: 2 additions & 16 deletions packages/block-editor/src/components/block-list/content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,6 @@
}
}

@mixin selectedOutline() {
content: "";
position: absolute;
pointer-events: none;
top: 0;
right: 0;
bottom: 0;
left: 0;
outline-color: var(--wp-admin-theme-color);
outline-style: solid;
outline-width: calc(var(--wp-admin-border-width-focus) / var(--wp-block-editor-iframe-zoom-out-scale, 1));
outline-offset: calc((-1 * var(--wp-admin-border-width-focus)) / var(--wp-block-editor-iframe-zoom-out-scale, 1));
}

// Hide selections on this element, otherwise Safari will include it stacked
// under your actual selection.
// This uses a CSS hack to show the rules to Safari only. Failing here is okay,
Expand Down Expand Up @@ -101,7 +87,7 @@ _::-webkit-full-page-media, _:future, :root .has-multi-selection .block-editor-b
// We're using a pseudo element to overflow placeholder borders
// and any border inside the block itself.
&::after {
@include selectedOutline();
@include selected-block-outline();
z-index: 1;

// Show a light color for dark themes.
Expand Down Expand Up @@ -281,7 +267,7 @@ _::-webkit-full-page-media, _:future, :root .has-multi-selection .block-editor-b
&:not(.rich-text):not([contenteditable="true"]).is-selected {

&::after {
@include selectedOutline();
@include selected-block-outline();
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions packages/block-editor/src/components/iframe/content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,13 @@
}
}
}

.block-editor-accessible-wrapper:focus-visible {
outline: none;

&::after {
content: "";
@include selected-block-outline();
position: fixed;
}
}
11 changes: 9 additions & 2 deletions packages/editor/src/components/editor-interface/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '@wordpress/block-editor';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
import { useViewportMatch } from '@wordpress/compose';
import { useState, useCallback } from '@wordpress/element';
import { useState, useCallback, useRef } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -116,6 +116,7 @@ export default function EditorInterface( {
},
[ entitiesSavedStatesCallback ]
);
const focusableWrapperRef = useRef();

return (
<InterfaceSkeleton
Expand Down Expand Up @@ -191,6 +192,9 @@ export default function EditorInterface( {
// eslint-disable-next-line jsx-a11y/no-autofocus
autoFocus={ autoFocus }
iframeProps={ iframeProps }
focusableWrapperRef={
focusableWrapperRef
}
/>
) }
{ children }
Expand All @@ -208,7 +212,10 @@ export default function EditorInterface( {
isRichEditingEnabled &&
blockEditorMode !== 'zoom-out' &&
mode === 'visual' && (
<BlockBreadcrumb rootLabelText={ documentLabel } />
<BlockBreadcrumb
rootLabelText={ documentLabel }
focusableWrapperRef={ focusableWrapperRef }
/>
)
}
actions={
Expand Down
2 changes: 2 additions & 0 deletions packages/editor/src/components/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ function VisualEditor( {
iframeProps,
contentRef,
className,
focusableWrapperRef,
} ) {
const [ resizeObserver, sizes ] = useResizeObserver();
const isMobileViewport = useViewportMatch( 'small', '<' );
Expand Down Expand Up @@ -407,6 +408,7 @@ function VisualEditor( {
...deviceStyles,
},
} }
focusableWrapperRef={ focusableWrapperRef }
>
{ themeSupportsLayout &&
! themeHasDisabledLayoutStyles &&
Expand Down
Loading