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

Grid Interactivity: Fix block mover layout and styles #64021

Merged
merged 1 commit into from
Jul 30, 2024
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
6 changes: 5 additions & 1 deletion packages/block-editor/src/components/block-mover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ function BlockMover( {
[ clientIds ]
);

if ( ! canMove || ( isFirst && isLast && ! rootClientId ) ) {
if (
! canMove ||
( isFirst && isLast && ! rootClientId ) ||
( hideDragHandle && isManualGrid )
) {
Comment on lines +72 to +76
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Prevents a ToolbarGroup component that has no children from being rendered.

return null;
}

Expand Down
90 changes: 46 additions & 44 deletions packages/block-editor/src/components/grid/grid-item-movers.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,29 @@ export function GridItemMovers( {
return (
<BlockControls group="parent">
<ToolbarGroup className="block-editor-grid-item-mover__move-button-container">
<GridItemMover
className="is-left-button"
icon={ chevronLeft }
label={ __( 'Move left' ) }
description={ __( 'Move left' ) }
isDisabled={ columnStart <= 1 }
onClick={ () => {
onChange( {
columnStart: columnStart - 1,
} );
__unstableMarkNextChangeAsNotPersistent();
moveBlocksToPosition(
[ blockClientId ],
gridClientId,
gridClientId,
getNumberOfBlocksBeforeCell(
columnStart - 1,
rowStart
)
);
} }
/>
<div className="block-editor-grid-item-mover__move-horizontal-button-container is-left">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the toolbar button, the ::before pseudo-element is used for the focus outline and the :::after pseudo-element is used for the text when "Show button text labels" is enabled.

I wrapped the button in a div to render a border as a pseudo-element.

<GridItemMover
icon={ chevronLeft }
label={ __( 'Move left' ) }
description={ __( 'Move left' ) }
isDisabled={ columnStart <= 1 }
onClick={ () => {
onChange( {
columnStart: columnStart - 1,
} );
__unstableMarkNextChangeAsNotPersistent();
moveBlocksToPosition(
[ blockClientId ],
gridClientId,
gridClientId,
getNumberOfBlocksBeforeCell(
columnStart - 1,
rowStart
)
);
} }
/>
</div>
<div className="block-editor-grid-item-mover__move-vertical-button-container">
<GridItemMover
className="is-up-button"
Expand Down Expand Up @@ -123,28 +124,29 @@ export function GridItemMovers( {
} }
/>
</div>
<GridItemMover
className="is-right-button"
icon={ chevronRight }
label={ __( 'Move right' ) }
description={ __( 'Move right' ) }
isDisabled={ columnCount && columnEnd >= columnCount }
onClick={ () => {
onChange( {
columnStart: columnStart + 1,
} );
__unstableMarkNextChangeAsNotPersistent();
moveBlocksToPosition(
[ blockClientId ],
gridClientId,
gridClientId,
getNumberOfBlocksBeforeCell(
columnStart + 1,
rowStart
)
);
} }
/>
<div className="block-editor-grid-item-mover__move-horizontal-button-container is-right">
<GridItemMover
icon={ chevronRight }
label={ __( 'Move right' ) }
description={ __( 'Move right' ) }
isDisabled={ columnCount && columnEnd >= columnCount }
onClick={ () => {
onChange( {
columnStart: columnStart + 1,
} );
__unstableMarkNextChangeAsNotPersistent();
moveBlocksToPosition(
[ blockClientId ],
gridClientId,
gridClientId,
getNumberOfBlocksBeforeCell(
columnStart + 1,
rowStart
)
);
} }
/>
</div>
</ToolbarGroup>
</BlockControls>
);
Expand Down
70 changes: 60 additions & 10 deletions packages/block-editor/src/components/grid/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@
.block-editor-grid-item-mover-button {
width: $block-toolbar-height * 0.5;
min-width: 0 !important; // overrides default button width.
overflow: hidden;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To fix incorrect focus outline

image

padding-left: 0;
padding-right: 0;

Expand Down Expand Up @@ -155,7 +154,7 @@
justify-content: space-around;

> .block-editor-grid-item-mover-button.block-editor-grid-item-mover-button {
height: $block-toolbar-height * 0.5 - $grid-unit-05;
height: $block-toolbar-height * 0.5 - $grid-unit-05 !important; // overrides toolbar button height.
width: 100%;
min-width: 0 !important; // overrides default button width.

Expand All @@ -173,18 +172,53 @@
}
}

.editor-collapsible-block-toolbar {
.block-editor-grid-item-mover__move-vertical-button-container {
// Move up a little to prevent the toolbar shift when focus is on the vertical movers.
@include break-small() {
height: $grid-unit-50;
position: relative;
top: -5px; // Should be -4px, but that causes scrolling when focus lands on the movers, in a 60px header.
}
}
}
Comment on lines +175 to +184
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similar to this approach for the default block mover. the .editor-collapsible-block-toolbar selector is used to determine that the Top Toolbar is enabled.


.show-icon-labels {

.block-editor-grid-item-mover-button.block-editor-grid-item-mover-button.is-left-button {
border-right: 1px solid $gray-700;
padding-right: 12px;
}
.block-editor-grid-item-mover__move-horizontal-button-container {
position: relative;

.block-editor-grid-item-mover-button.block-editor-grid-item-mover-button.is-right-button {
border-left: 1px solid $gray-700;
padding-left: 12px;
}
&::before {
@include break-small() {
content: "";
height: 100%;
width: $border-width;
background: $gray-200;
position: absolute;
top: 0;
}

@include break-medium() {
background: $gray-900;
}
}

&.is-left {
padding-right: 6px;

&::before {
right: 0;
}
}

&.is-right {
padding-left: 6px;

&::before {
left: 0;
}
}
}

.block-editor-grid-item-mover__move-vertical-button-container {
&::before {
Expand All @@ -208,5 +242,21 @@
}
}

.block-editor-grid-item-mover-button {
white-space: nowrap;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To prevent text wrapping when the "Show button text labels" is enabled

image

}

.editor-collapsible-block-toolbar {
.block-editor-grid-item-mover__move-horizontal-button-container::before {
height: $grid-unit-30;
background: $gray-300;
top: $grid-unit-05;
}

.block-editor-grid-item-mover__move-vertical-button-container::before {
background: $gray-300;
width: calc(100% - #{$grid-unit-30});
}
}
}

Loading