Skip to content

Commit

Permalink
Nav offcanvas restore click to edit (#47608)
Browse files Browse the repository at this point in the history
* Default to select block on click

* Remove dedicated “edit” button

* Only allow editing where valid

* Remove redundant component

* Allow all blocks to be edited

* Remove `selectBlockInCanvas` prop as no longer required
  • Loading branch information
getdave authored Jan 31, 2023
1 parent abde4bd commit 04837c4
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 94 deletions.

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 } />;
}

1 comment on commit 04837c4

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 04837c4.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4055482344
📝 Reported issues:

Please sign in to comment.