Skip to content

Commit dcd0bcd

Browse files
t-hamanonoisysocks
andauthored
Grid Interactivity: Fix block mover layout and styles (#64021)
Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: noisysocks <noisysocks@git.wordpress.org>
1 parent a051fe7 commit dcd0bcd

File tree

3 files changed

+111
-55
lines changed

3 files changed

+111
-55
lines changed

packages/block-editor/src/components/block-mover/index.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ function BlockMover( {
6969
[ clientIds ]
7070
);
7171

72-
if ( ! canMove || ( isFirst && isLast && ! rootClientId ) ) {
72+
if (
73+
! canMove ||
74+
( isFirst && isLast && ! rootClientId ) ||
75+
( hideDragHandle && isManualGrid )
76+
) {
7377
return null;
7478
}
7579

packages/block-editor/src/components/grid/grid-item-movers.js

+46-44
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,29 @@ export function GridItemMovers( {
5555
return (
5656
<BlockControls group="parent">
5757
<ToolbarGroup className="block-editor-grid-item-mover__move-button-container">
58-
<GridItemMover
59-
className="is-left-button"
60-
icon={ chevronLeft }
61-
label={ __( 'Move left' ) }
62-
description={ __( 'Move left' ) }
63-
isDisabled={ columnStart <= 1 }
64-
onClick={ () => {
65-
onChange( {
66-
columnStart: columnStart - 1,
67-
} );
68-
__unstableMarkNextChangeAsNotPersistent();
69-
moveBlocksToPosition(
70-
[ blockClientId ],
71-
gridClientId,
72-
gridClientId,
73-
getNumberOfBlocksBeforeCell(
74-
columnStart - 1,
75-
rowStart
76-
)
77-
);
78-
} }
79-
/>
58+
<div className="block-editor-grid-item-mover__move-horizontal-button-container is-left">
59+
<GridItemMover
60+
icon={ chevronLeft }
61+
label={ __( 'Move left' ) }
62+
description={ __( 'Move left' ) }
63+
isDisabled={ columnStart <= 1 }
64+
onClick={ () => {
65+
onChange( {
66+
columnStart: columnStart - 1,
67+
} );
68+
__unstableMarkNextChangeAsNotPersistent();
69+
moveBlocksToPosition(
70+
[ blockClientId ],
71+
gridClientId,
72+
gridClientId,
73+
getNumberOfBlocksBeforeCell(
74+
columnStart - 1,
75+
rowStart
76+
)
77+
);
78+
} }
79+
/>
80+
</div>
8081
<div className="block-editor-grid-item-mover__move-vertical-button-container">
8182
<GridItemMover
8283
className="is-up-button"
@@ -123,28 +124,29 @@ export function GridItemMovers( {
123124
} }
124125
/>
125126
</div>
126-
<GridItemMover
127-
className="is-right-button"
128-
icon={ chevronRight }
129-
label={ __( 'Move right' ) }
130-
description={ __( 'Move right' ) }
131-
isDisabled={ columnCount && columnEnd >= columnCount }
132-
onClick={ () => {
133-
onChange( {
134-
columnStart: columnStart + 1,
135-
} );
136-
__unstableMarkNextChangeAsNotPersistent();
137-
moveBlocksToPosition(
138-
[ blockClientId ],
139-
gridClientId,
140-
gridClientId,
141-
getNumberOfBlocksBeforeCell(
142-
columnStart + 1,
143-
rowStart
144-
)
145-
);
146-
} }
147-
/>
127+
<div className="block-editor-grid-item-mover__move-horizontal-button-container is-right">
128+
<GridItemMover
129+
icon={ chevronRight }
130+
label={ __( 'Move right' ) }
131+
description={ __( 'Move right' ) }
132+
isDisabled={ columnCount && columnEnd >= columnCount }
133+
onClick={ () => {
134+
onChange( {
135+
columnStart: columnStart + 1,
136+
} );
137+
__unstableMarkNextChangeAsNotPersistent();
138+
moveBlocksToPosition(
139+
[ blockClientId ],
140+
gridClientId,
141+
gridClientId,
142+
getNumberOfBlocksBeforeCell(
143+
columnStart + 1,
144+
rowStart
145+
)
146+
);
147+
} }
148+
/>
149+
</div>
148150
</ToolbarGroup>
149151
</BlockControls>
150152
);

packages/block-editor/src/components/grid/style.scss

+60-10
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@
105105
.block-editor-grid-item-mover-button {
106106
width: $block-toolbar-height * 0.5;
107107
min-width: 0 !important; // overrides default button width.
108-
overflow: hidden;
109108
padding-left: 0;
110109
padding-right: 0;
111110

@@ -155,7 +154,7 @@
155154
justify-content: space-around;
156155

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

@@ -173,18 +172,53 @@
173172
}
174173
}
175174

175+
.editor-collapsible-block-toolbar {
176+
.block-editor-grid-item-mover__move-vertical-button-container {
177+
// Move up a little to prevent the toolbar shift when focus is on the vertical movers.
178+
@include break-small() {
179+
height: $grid-unit-50;
180+
position: relative;
181+
top: -5px; // Should be -4px, but that causes scrolling when focus lands on the movers, in a 60px header.
182+
}
183+
}
184+
}
185+
176186
.show-icon-labels {
177187

178-
.block-editor-grid-item-mover-button.block-editor-grid-item-mover-button.is-left-button {
179-
border-right: 1px solid $gray-700;
180-
padding-right: 12px;
181-
}
188+
.block-editor-grid-item-mover__move-horizontal-button-container {
189+
position: relative;
182190

183-
.block-editor-grid-item-mover-button.block-editor-grid-item-mover-button.is-right-button {
184-
border-left: 1px solid $gray-700;
185-
padding-left: 12px;
186-
}
191+
&::before {
192+
@include break-small() {
193+
content: "";
194+
height: 100%;
195+
width: $border-width;
196+
background: $gray-200;
197+
position: absolute;
198+
top: 0;
199+
}
200+
201+
@include break-medium() {
202+
background: $gray-900;
203+
}
204+
}
205+
206+
&.is-left {
207+
padding-right: 6px;
187208

209+
&::before {
210+
right: 0;
211+
}
212+
}
213+
214+
&.is-right {
215+
padding-left: 6px;
216+
217+
&::before {
218+
left: 0;
219+
}
220+
}
221+
}
188222

189223
.block-editor-grid-item-mover__move-vertical-button-container {
190224
&::before {
@@ -208,5 +242,21 @@
208242
}
209243
}
210244

245+
.block-editor-grid-item-mover-button {
246+
white-space: nowrap;
247+
}
248+
249+
.editor-collapsible-block-toolbar {
250+
.block-editor-grid-item-mover__move-horizontal-button-container::before {
251+
height: $grid-unit-30;
252+
background: $gray-300;
253+
top: $grid-unit-05;
254+
}
255+
256+
.block-editor-grid-item-mover__move-vertical-button-container::before {
257+
background: $gray-300;
258+
width: calc(100% - #{$grid-unit-30});
259+
}
260+
}
211261
}
212262

0 commit comments

Comments
 (0)