Skip to content

Commit 6e69c49

Browse files
jasmussengziolo
authored andcommitted
Try: Restore block mover for floats. (WordPress#12758)
* Try: Restore block mover for floats. This PR hopes to fix WordPress#12736, WordPress#11424, WordPress#10300. Currently we hide the block mover for any floated block. We do this because if you have a left floated image followed by a paragraph, the block mover for the image would overlap exactly with the block mover for the subsequent paragraph block. This would cause moving a float to be fiddly and virtually impossible as the hover states for the two conflicted. This PR is an experiment to mitigate, or possibly fix that. It's a try branch because it is not necessarily a solid fix. What this PR does: - It makes it so the block mover cannot be invoked when only hovering a float, but when the float is selected they are permanently visible. - It changes some z-indexes so floats always have a higher z-index than not a float. - It changes the footprint of the side-UI container to "cover up" the underlying paragraph block, so it won't invoke unlesss you move the mouse below the footprint. This is best explained in some GIFs. The reason this is a "Try" branch is that when you move the mouse over the adjacent paragraph, the block mover is show as overlapping the selected floats block mover. But due to the rearranging of z-indexes, at least this is only a visual issue. A click on the floats block mover will still work as intended. Why can't the float have on-hover block movers like every other block, you ask? Picture again the test-case of a left floated image followed by a paragraph of text. In this case, hovering over the image would show a block mover that would visually appear to be that of the paragraph block. By showing it when the float is selected, the context is clear. We could experiment with not showing the hover block mover for float-adjacent blocks when hovered, but this isn't feasible because you might have a float, and then a block that clears this float, in which case the rule would break down. Lay your thoughts on me. * Address feedback, and improve dragging edgecase. This addresses comment feedback by @ZebulanStanphill, thanks, and it also hides the block mover from the ghost when you are dragging. * Add borders around floats.
1 parent 4c57b59 commit 6e69c49

File tree

4 files changed

+75
-39
lines changed

4 files changed

+75
-39
lines changed

assets/stylesheets/_z-index.scss

+5-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
$z-layers: (
66
".editor-block-list__block-edit::before": 0,
77
".editor-block-switcher__arrow": 1,
8-
".editor-block-list__block {core/image aligned left or right}": 20,
98
".editor-block-list__block {core/image aligned wide or fullwide}": 20,
109
".block-library-classic__toolbar": 10,
1110
".editor-block-list__layout .reusable-block-indicator": 1,
@@ -48,9 +47,12 @@ $z-layers: (
4847
".components-drop-zone": 100,
4948
".components-drop-zone__content": 110,
5049

51-
// Block controls, particularly in nested contexts, floats aside block and
50+
// The block mover, particularly in nested contexts,
5251
// should overlap most block content.
53-
".editor-block-list__block.is-{selected,hovered} .editor-block-{settings-menu,mover}": 80,
52+
".editor-block-list__block.is-{selected,hovered} .editor-block-mover": 80,
53+
54+
// The block mover for floats should overlap the controls of adjacent blocks.
55+
".editor-block-list__block {core/image aligned left or right}": 81,
5456

5557
// Small screen inner blocks overlay must be displayed above drop zone,
5658
// settings menu, and movers.

packages/editor/src/components/block-list/block.js

+15-15
Original file line numberDiff line numberDiff line change
@@ -519,25 +519,25 @@ export class BlockListBlock extends Component {
519519
clientId={ clientId }
520520
rootClientId={ rootClientId }
521521
/>
522-
{ shouldRenderMovers && (
523-
<BlockMover
524-
clientIds={ clientId }
525-
blockElementId={ blockElementId }
526-
isFirst={ isFirst }
527-
isLast={ isLast }
528-
isHidden={ ! ( isHovered || isSelected ) || hoverArea !== 'left' }
529-
isDraggable={
530-
isDraggable !== false &&
531-
( ! isPartOfMultiSelection && isMovable )
532-
}
533-
onDragStart={ this.onDragStart }
534-
onDragEnd={ this.onDragEnd }
535-
/>
536-
) }
537522
{ isFirstMultiSelected && (
538523
<BlockMultiControls rootClientId={ rootClientId } />
539524
) }
540525
<div className="editor-block-list__block-edit">
526+
{ shouldRenderMovers && (
527+
<BlockMover
528+
clientIds={ clientId }
529+
blockElementId={ blockElementId }
530+
isFirst={ isFirst }
531+
isLast={ isLast }
532+
isHidden={ ! ( isHovered || isSelected ) || hoverArea !== 'left' }
533+
isDraggable={
534+
isDraggable !== false &&
535+
( ! isPartOfMultiSelection && isMovable )
536+
}
537+
onDragStart={ this.onDragStart }
538+
onDragEnd={ this.onDragEnd }
539+
/>
540+
) }
541541
{ shouldShowBreadcrumb && (
542542
<BlockBreadcrumb
543543
clientId={ clientId }

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

+53-21
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
.editor-block-list__layout .components-draggable__clone {
2-
// Hide the Block UI when dragging the block
3-
// This ensures the page scroll properly (no sticky elements)
2+
// Hide the Block UI when dragging the block.
3+
// This ensures the page scroll properly (no sticky elements).
44
.editor-block-contextual-toolbar {
5-
// I think important is fine here to avoid over complexing the selector
5+
// It's probably okay to use !important here to avoid over-complicating the selector.
66
display: none !important;
77
}
88
}
@@ -127,7 +127,7 @@
127127
}
128128
}
129129

130-
// Selected style
130+
// Selected style.
131131
&.is-selected > .editor-block-list__block-edit::before {
132132
// Use opacity to work in various editor styles.
133133
outline: $border-width solid $dark-opacity-light-500;
@@ -137,12 +137,12 @@
137137
}
138138
}
139139

140-
// Hover style
140+
// Hover style.
141141
&.is-hovered > .editor-block-list__block-edit::before {
142142
outline: $border-width solid theme(outlines);
143143
}
144144

145-
// Spotlight mode
145+
// Spotlight mode.
146146
&.is-focus-mode:not(.is-multi-selected) {
147147
opacity: 0.5;
148148
transition: opacity 0.1s linear;
@@ -168,7 +168,7 @@
168168
background-color: $blue-medium-highlight;
169169
}
170170

171-
// selection style for multiple blocks
171+
// Selection style for multiple blocks.
172172
&.is-multi-selected *::selection {
173173
background-color: transparent;
174174
}
@@ -179,7 +179,7 @@
179179
// Use opacity to work in various editor styles.
180180
mix-blend-mode: multiply;
181181

182-
// Collapse extra vertical padding on selection
182+
// Collapse extra vertical padding on selection.
183183
top: -$block-padding;
184184
bottom: -$block-padding;
185185

@@ -293,12 +293,6 @@
293293
margin-bottom: $border-width;
294294
}
295295

296-
// Hide all additional UI on floats.
297-
.editor-block-mover,
298-
.editor-block-list__block-mobile-toolbar {
299-
display: none;
300-
}
301-
302296
// Position toolbar better on mobile.
303297
.editor-block-contextual-toolbar {
304298
width: auto;
@@ -506,7 +500,8 @@
506500
.editor-block-list__block {
507501

508502
// Left and right block settings and mover.
509-
> .editor-block-mover {
503+
&.is-multi-selected > .editor-block-mover,
504+
> .editor-block-list__block-edit > .editor-block-mover {
510505
position: absolute;
511506
width: $block-side-ui-width + $block-side-ui-clearance;
512507

@@ -516,7 +511,8 @@
516511
}
517512

518513
// Position depending on whether selected or not.
519-
> .editor-block-mover {
514+
&.is-multi-selected > .editor-block-mover,
515+
> .editor-block-list__block-edit > .editor-block-mover {
520516
top: -$block-padding - $border-width;
521517
}
522518

@@ -526,24 +522,60 @@
526522
&.is-selected,
527523
&.is-hovered {
528524
.editor-block-mover {
529-
z-index: z-index(".editor-block-list__block.is-{selected,hovered} .editor-block-{settings-menu,mover}");
525+
z-index: z-index(".editor-block-list__block.is-{selected,hovered} .editor-block-mover");
530526
}
531527
}
532528
}
533529

534530
// Left side UI.
535-
> .editor-block-mover {
531+
&.is-multi-selected > .editor-block-mover,
532+
> .editor-block-list__block-edit > .editor-block-mover {
536533
padding-right: $block-side-ui-clearance;
537534

538-
// Position for top level blocks
539-
left: -$block-side-ui-width - $block-side-ui-clearance;
535+
// Position for top level blocks.
536+
left: -$block-side-ui-width - $block-side-ui-clearance - $block-padding - $border-width;
540537

541-
// Mobile
538+
// Hide on mobile, as mobile has a separate solution.
542539
display: none;
543540
@include break-small() {
544541
display: block;
545542
}
546543
}
544+
545+
&.is-multi-selected > .editor-block-mover {
546+
left: -$block-side-ui-width - $block-side-ui-clearance;
547+
}
548+
549+
// For floats, show block mover when block is selected, and never on hover.
550+
&[data-align="left"],
551+
&[data-align="right"] {
552+
// Show always when the block is selected.
553+
&.is-selected > .editor-block-list__block-edit > .editor-block-mover {
554+
// Don't show on mobile, allow the special mobile toolbar to work there.
555+
display: none;
556+
@include break-small() {
557+
display: block;
558+
opacity: 1;
559+
animation: none;
560+
561+
// Make wider and taller to make "safe" hover area bigger.
562+
// The intent is to make it less likely that you hover float-adjacent
563+
// blocks that visually appear below the block.
564+
width: $block-side-ui-width + $block-side-ui-clearance + $block-padding + $border-width;
565+
height: auto;
566+
padding-bottom: $block-padding;
567+
568+
// Unset the negative top margin, or it might overlap the block toolbar.
569+
margin-top: 0;
570+
}
571+
}
572+
573+
// Don't show on hover, or on the "ghost" when dragging.
574+
&.is-hovered > .editor-block-list__block-edit > .editor-block-mover,
575+
&.is-dragging > .editor-block-list__block-edit > .editor-block-mover {
576+
display: none;
577+
}
578+
}
547579
}
548580

549581

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

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@
8787
.editor-block-mover__control-drag-handle:not(:disabled):not([aria-disabled="true"]):not(.is-default),
8888
.editor-block-mover__control {
8989
@include break-small() {
90+
.editor-block-list__layout [data-align="right"] &,
91+
.editor-block-list__layout [data-align="left"] &,
9092
.editor-block-list__layout .editor-block-list__layout & {
9193
background: $white;
9294
box-shadow: inset 0 0 0 1px $light-gray-500;

0 commit comments

Comments
 (0)