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

Separator Block: Add top & bottom margin support #40551

Merged
merged 1 commit into from
Apr 28, 2022

Conversation

ryelle
Copy link
Contributor

@ryelle ryelle commented Apr 22, 2022

This adds top & bottom margin support to the separator block. There have been other attempts at this in the past, see #20758 #30609 #28451. They've been closed in favor of using the spacer block, but I don't think that's intuitive, especially as there are other blocks with margin controls.

For example, if I want to add a spacer with 50px space on either side, I need to add a group block, set the block gap & margin top to 0px (to account for added margins), and then add my spacers & separator.

<!-- wp:group {"style":{"spacing":{"blockGap":"0px","margin":{"top":"0px"}}},"layout":{"inherit":true}} -->
<div class="wp-block-group" style="margin-top:0px">
	<!-- wp:spacer {"height":"50px"} -->
	<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>
	<!-- /wp:spacer -->

	<!-- wp:separator {"color":"light-grey","className":"is-style-wide"} -->
	<hr class="wp-block-separator has-text-color has-background has-light-grey-background-color has-light-grey-color is-style-wide" />
	<!-- /wp:separator -->

	<!-- wp:spacer {"height":"50px"} -->
	<div style="height:50px" aria-hidden="true" class="wp-block-spacer"></div>
	<!-- /wp:spacer -->
</div>
<!-- /wp:group -->

Or, I could just control the margin directly.

<!-- wp:separator {"style":{"spacing":{"margin":{"top":"50px","bottom":"50px"}}},"backgroundColor":"black","className":"is-style-wide"} -->
<hr class="wp-block-separator has-text-color has-black-color has-alpha-channel-opacity has-black-background-color has-background is-style-wide" style="margin-top:50px;margin-bottom:50px"/>
<!-- /wp:separator -->

How?

This simply toggles the block support for spacing.margin, for top & bottom margin only (the minimum needed change).

Testing Instructions

  1. Add a separator block
  2. Change the margin (might need to enable "margin" in the Dimension panel)
  3. It should reflect the new margin in the editor
  4. Save & view the post
  5. The margin should also be applied on the frontend

Screenshots

Added Dimension panel & margin control

Spacer with margin

@ryelle ryelle added the [Block] Separator Affects the Separator Block label Apr 22, 2022
@ryelle ryelle self-assigned this Apr 22, 2022
@ryelle ryelle merged commit d12b5a9 into trunk Apr 28, 2022
@ryelle ryelle deleted the update/block-separator-margin-support branch April 28, 2022 15:58
@github-actions github-actions bot added this to the Gutenberg 13.2 milestone Apr 28, 2022
@georgeh georgeh added the [Type] Enhancement A suggestion for improvement. label May 10, 2022
@femkreations femkreations added the Needs User Documentation Needs new user documentation label Aug 22, 2022
@nendeb
Copy link

nendeb commented Sep 16, 2022

In the following use case
If a Separator Block is placed not only between the top and bottom blocks, but also between the left and right blocks, the left and right margins may be necessary as well.

@antonyjsmith
Copy link

Discovered what appears to be a bug on this here: #47059 the global margin is not working when set via global styles

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Separator Affects the Separator Block Needs User Documentation Needs new user documentation [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants