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

Nav offcanvas restore click to edit #47608

Merged
merged 6 commits into from
Jan 31, 2023
Merged
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { forwardRef } from '@wordpress/element';
import { Icon, lockSmall as lock } from '@wordpress/icons';
import { SPACE, ENTER } from '@wordpress/keycodes';
import { sprintf, __ } from '@wordpress/i18n';

/**
* Internal dependencies
Expand All @@ -27,7 +28,7 @@ import { useBlockLock } from '../block-lock';
function ListViewBlockSelectButton(
{
className,
block: { clientId },
block,
onClick,
onToggleExpanded,
tabIndex,
Expand All @@ -38,6 +39,7 @@ function ListViewBlockSelectButton(
},
ref
) {
const { clientId } = block;
const blockInformation = useBlockDisplayInformation( clientId );
const blockTitle = useBlockDisplayTitle( {
clientId,
Expand All @@ -60,6 +62,14 @@ function ListViewBlockSelectButton(
}
}

const editAriaLabel = blockInformation
? sprintf(
// translators: %s: The title of the block.
__( 'Edit %s block' ),
blockInformation.title
)
: __( 'Edit' );

return (
<>
<Button
Expand All @@ -77,6 +87,7 @@ function ListViewBlockSelectButton(
draggable={ draggable }
href={ `#block-${ clientId }` }
aria-hidden={ true }
title={ editAriaLabel }
>
<ListViewExpander onClick={ onToggleExpanded } />
<BlockIcon
Expand Down
45 changes: 3 additions & 42 deletions packages/block-editor/src/components/off-canvas-editor/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import {
} from '../block-mover/button';
import ListViewBlockContents from './block-contents';
import BlockSettingsDropdown from '../block-settings-menu/block-settings-dropdown';
import BlockEditButton from './block-edit-button';
import { useListViewContext } from './context';
import { getBlockPositionDescription } from './utils';
import { store as blockEditorStore } from '../../store';
Expand All @@ -55,7 +54,6 @@ function ListViewBlock( {
isExpanded,
selectedClientIds,
preventAnnouncement,
selectBlockInCanvas,
} ) {
const cellRef = useRef( null );
const [ isHovered, setIsHovered ] = useState( false );
Expand Down Expand Up @@ -186,15 +184,6 @@ function ListViewBlock( {
)
: __( 'Options' );

const editAriaLabel = blockInformation
? sprintf(
// translators: %s: The title of the block.
__( 'Edit %s block' ),
blockInformation.title
)
: __( 'Edit' );

const isEditable = !! block && block.name !== 'core/page-list-item';
const hasSiblings = siblingBlockCount > 0;
const hasRenderedMovers = showBlockMovers && hasSiblings;
const moverCellClassName = classnames(
Expand All @@ -207,17 +196,11 @@ function ListViewBlock( {
{ 'is-visible': isHovered || isFirstSelectedBlock }
);

const listViewBlockEditClassName = classnames(
'block-editor-list-view-block__menu-cell',
'block-editor-list-view-block__menu-edit',
{ 'is-visible': isHovered || isFirstSelectedBlock }
);

let colSpan;
if ( hasRenderedMovers ) {
colSpan = 2;
colSpan = 1;
} else if ( ! showBlockActions ) {
colSpan = 3;
colSpan = 2;
}

const classes = classnames( {
Expand Down Expand Up @@ -270,13 +253,7 @@ function ListViewBlock( {
<div className="block-editor-list-view-block__contents-container">
<ListViewBlockContents
block={ block }
onClick={
selectBlockInCanvas
? selectEditorBlock
: ( event ) => {
event.preventDefault();
}
}
onClick={ selectEditorBlock }
onToggleExpanded={ toggleExpanded }
isSelected={ isSelected }
position={ position }
Expand Down Expand Up @@ -332,22 +309,6 @@ function ListViewBlock( {

{ showBlockActions && (
<>
<TreeGridCell
className={ listViewBlockEditClassName }
aria-selected={
!! isSelected || forceSelectionContentLock
}
>
{ ( props ) =>
isEditable && (
<BlockEditButton
{ ...props }
label={ editAriaLabel }
clientId={ clientId }
/>
)
}
</TreeGridCell>
<TreeGridCell
className={ listViewBlockSettingsClassName }
aria-selected={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ function ListViewBranch( props ) {
isExpanded,
parentId,
shouldShowInnerBlocks = true,
selectBlockInCanvas,
} = props;

const isContentLocked = useSelect(
Expand Down Expand Up @@ -186,7 +185,6 @@ function ListViewBranch( props ) {
isExpanded={ shouldExpand }
listPosition={ nextPosition }
selectedClientIds={ selectedClientIds }
selectBlockInCanvas={ selectBlockInCanvas }
/>
) }
{ ! showBlock && (
Expand All @@ -207,7 +205,6 @@ function ListViewBranch( props ) {
isBranchSelected={ isSelectedBranch }
selectedClientIds={ selectedClientIds }
isExpanded={ isExpanded }
selectBlockInCanvas={ selectBlockInCanvas }
/>
) }
</AsyncModeProvider>
Expand Down
25 changes: 8 additions & 17 deletions packages/block-editor/src/components/off-canvas-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,16 @@ export const BLOCK_LIST_ITEM_HEIGHT = 36;
/**
* Show a hierarchical list of blocks.
*
* @param {Object} props Components props.
* @param {string} props.id An HTML element id for the root element of ListView.
* @param {Array} props.blocks Custom subset of block client IDs to be used instead of the default hierarchy.
* @param {boolean} props.showBlockMovers Flag to enable block movers
* @param {boolean} props.isExpanded Flag to determine whether nested levels are expanded by default.
* @param {boolean} props.selectBlockInCanvas Flag to determine whether the list view should be a block selection mechanism.
* @param {Object} props.LeafMoreMenu Optional more menu substitution.
* @param {Object} ref Forwarded ref
* @param {Object} props Components props.
* @param {string} props.id An HTML element id for the root element of ListView.
* @param {Array} props.blocks Custom subset of block client IDs to be used instead of the default hierarchy.
* @param {boolean} props.showBlockMovers Flag to enable block movers
* @param {boolean} props.isExpanded Flag to determine whether nested levels are expanded by default.
* @param {Object} props.LeafMoreMenu Optional more menu substitution.
* @param {Object} ref Forwarded ref
*/
function OffCanvasEditor(
{
id,
blocks,
showBlockMovers = false,
isExpanded = false,
selectBlockInCanvas = true,
LeafMoreMenu,
},
{ id, blocks, showBlockMovers = false, isExpanded = false, LeafMoreMenu },
ref
) {
const { clientIdsTree, draggedClientIds, selectedClientIds } =
Expand Down Expand Up @@ -227,7 +219,6 @@ function OffCanvasEditor(
selectedClientIds={ selectedClientIds }
isExpanded={ isExpanded }
shouldShowInnerBlocks={ shouldShowInnerBlocks }
selectBlockInCanvas={ selectBlockInCanvas }
/>
<TreeGridRow
level={ 1 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ const MainContent = ( {
<OffCanvasEditor
blocks={ clientIdsTree }
isExpanded={ true }
selectBlockInCanvas={ false }
LeafMoreMenu={ LeafMoreMenu }
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,5 @@ export default function NavigationMenu( { innerBlocks } ) {
} );
}, [ updateBlockListSettings, innerBlocks ] );

return (
<OffCanvasEditor blocks={ innerBlocks } selectBlockInCanvas={ false } />
);
return <OffCanvasEditor blocks={ innerBlocks } />;
}