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

Restore visual separator between mover buttons when show button label is on #57640

Merged
merged 4 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
31 changes: 18 additions & 13 deletions packages/block-editor/src/components/block-toolbar/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,24 @@

.block-editor-block-mover .block-editor-block-mover__move-button-container {
width: auto;

@include break-small() {
position: relative;

&::before {
content: "";
display: block;
t-hamano marked this conversation as resolved.
Show resolved Hide resolved
height: $border-width;
width: 100%;
background: $gray-900;
position: absolute;
top: 50%;
left: 50%;
// With Top toolbar on, this separator has a smaller width. Translating both
// X and Y axis allows to make the separator alwasy centered regardless of its width.
transform: translate(-50%);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
transform: translate(-50%);
transform: translate(-50%, 0);
margin-top: -$border-width * 0.5;

I think translate(-50%); means translate(-50%, 0);. Strictly speaking, it is not vertically centered.

I tried changing it to translate(-50%, -50%) to align it vertically, but the border seems to bleed.

image

Instead, I tried using a negative margin to shift the border up by half the height value. This approach draws a solid border in my environment. Could you test if this approach works in your environment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think translate(-50%); means translate(-50%, 0);. Strictly speaking, it is not vertically centered.

Right.

the border seems to bleed.

Are you on Windows or some GNU-Linux distro? What browser are you using? What display type and resolution?

I tried using a negative margin to shift the border up by half the height value. This approach draws a solid border in my environment.

The root problem is that the toolbar height is 48px. The mover buttons height is 24px. A vertically centered 1 pixel horizontal line would need to be placed at exactly 23.5 pixels. However, a physical pixel can't be split in two. Some operating systems / browsers / displays (retina resolution, sub-pixel rendering) may render that more nicely than others. The 'bleeding' depends on the ability to position an element to 'half a pixel'. In environments where a CSS pixel is actually more than one physical pixel that may work better. In your screenshot, the horizontal line is actually 2 pixels, apparently that's because your environment isn't able to render sub-pixels.

The top margin approach actually computes to margin-top: -0.5px;. In your environment it may preserve the height of the line to 1 pixel but I guess the line isn't vertically centered.

Environments that support true subpixel rendering won't trigger this issue. The only reliable way to avoid a greyish blurred line or its rendered height to be altered would be to make sure it is moved to a 'full pixel' e.g. by making the toolbar height an odd number.

Maybe translateZ(0) may help prevent the blurriness because it promotes the element to its own layer but there's no guarantee the line will be vertically centered. Also margin-top: -0.5px; doesn't guarantee the line will be vertically centered but I'd think that's batter than a blurred line.

For the records, this is how the translateY approach looks in my environment (zoomed in): no blurring or doubled height:

Screenshot 2024-01-11 at 10 45 07

}
}
}

.block-editor-block-mover.is-horizontal {
Expand Down Expand Up @@ -231,19 +249,6 @@
padding-right: $grid-unit-15;
}

@include break-small() {
// Specificity override for https://github.com/WordPress/gutenberg/blob/try/block-toolbar-labels/packages/block-editor/src/components/block-mover/style.scss#L69
.is-up-button.is-up-button.is-up-button {
margin-right: 0;
border-radius: 0;
order: 1;
}

.is-down-button.is-down-button.is-down-button {
order: 2;
}
}

.block-editor-block-contextual-toolbar .block-editor-block-mover.is-horizontal .block-editor-block-mover-button.block-editor-block-mover-button {
width: auto;
}
Expand Down
14 changes: 12 additions & 2 deletions packages/edit-post/src/components/header/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,24 @@
.edit-post-header__toolbar .block-editor-block-mover {
border-left: none;

// Modified group borders
t-hamano marked this conversation as resolved.
Show resolved Hide resolved
&::before {
content: "";
width: $border-width;
margin-top: $grid-unit + $grid-unit-05;
margin-bottom: $grid-unit + $grid-unit-05;
margin-top: $grid-unit-15;
margin-bottom: $grid-unit-15;
background-color: $gray-300;
margin-left: $grid-unit;
}

// Modified block movers separator
.block-editor-block-mover__move-button-container {
&::before {
width: calc(100% - #{$grid-unit-30});
background: $gray-300;
left: calc(50% + 1px);
}
}
}
}

Expand Down
18 changes: 14 additions & 4 deletions packages/edit-site/src/components/header-edit-mode/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,24 @@ $header-toolbar-min-width: 335px;
.block-editor-block-mover {
border-left: none;

// Modified group borders
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment doesn't seem to be related to the actual pseudo-element style, so how about deleting this comment?

&::before {
content: "";
width: $border-width;
margin-top: $grid-unit + $grid-unit-05;
margin-bottom: $grid-unit + $grid-unit-05;
margin-top: $grid-unit-15;
margin-bottom: $grid-unit-15;
background-color: $gray-300;
margin-left: $grid-unit;
}

// Modified block movers separator
.block-editor-block-mover__move-button-container {
&::before {
width: calc(100% - #{$grid-unit-30});
background: $gray-300;
left: calc(50% + 1px);
}
}
}
}

Expand All @@ -172,8 +182,8 @@ $header-toolbar-min-width: 335px;
&::after {
content: "";
width: $border-width;
margin-top: $grid-unit + $grid-unit-05;
margin-bottom: $grid-unit + $grid-unit-05;
margin-top: $grid-unit-15;
margin-bottom: $grid-unit-15;
background-color: $gray-300;
margin-left: $grid-unit;
}
Expand Down
Loading