-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[Buttons block]: Add gap and vertical margin support #34546
Changes from all commits
5e84bbf
77cf76c
9f68e6f
0c7f72a
3dae091
b789108
5c13b88
306c35c
127848c
89c6978
fa22c12
0768a73
4979a68
9fd3a7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,6 @@ | |
.is-selected & { | ||
height: auto; | ||
overflow: visible; | ||
margin-top: $grid-unit-20; | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ $blocks-block__margin: 0.5em; | |
} | ||
} | ||
|
||
// Increased specificity needed to override margins | ||
stacimc marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Increased specificity needed to override margins. | ||
.wp-block-buttons > .wp-block-button { | ||
&.has-custom-width { | ||
max-width: none; | ||
|
@@ -50,58 +50,35 @@ $blocks-block__margin: 0.5em; | |
} | ||
|
||
&.wp-block-button__width-25 { | ||
width: calc(25% - #{ $blocks-block__margin }); | ||
width: calc(25% - (var(--wp--style--block-gap, #{$blocks-block__margin}) * 0.75)); | ||
} | ||
|
||
&.wp-block-button__width-50 { | ||
width: calc(50% - #{ $blocks-block__margin }); | ||
width: calc(50% - (var(--wp--style--block-gap, #{$blocks-block__margin}) * 0.5)); | ||
} | ||
|
||
&.wp-block-button__width-75 { | ||
width: calc(75% - #{ $blocks-block__margin }); | ||
width: calc(75% - (var(--wp--style--block-gap, #{$blocks-block__margin}) * 0.25)); | ||
} | ||
|
||
&.wp-block-button__width-100 { | ||
width: calc(100% - #{ $blocks-block__margin }); | ||
|
||
&:only-child { | ||
margin-right: 0; | ||
width: 100%; | ||
} | ||
width: 100%; | ||
flex-basis: 100%; | ||
} | ||
} | ||
|
||
// If the browser supports column-gap, use that instead of the margins above. | ||
@supports ( column-gap: #{ $blocks-block__margin } ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
.wp-block-buttons { | ||
|
||
> .wp-block-button, | ||
&.is-content-justification-right > .wp-block-button, { | ||
// Added (duplicate) specificity needed to override the default button margin. | ||
&.wp-block-button { | ||
margin-right: 0; | ||
margin-left: 0; | ||
} | ||
} | ||
|
||
> .wp-block-button { | ||
&.wp-block-button__width-25 { | ||
width: calc(25% - #{ $blocks-block__margin * 0.75 }); | ||
} | ||
|
||
&.wp-block-button__width-50 { | ||
width: calc(50% - #{ $blocks-block__margin * 0.5 }); | ||
} | ||
// For vertical buttons, gap is not factored into width calculations. | ||
.wp-block-buttons.is-vertical > .wp-block-button { | ||
&.wp-block-button__width-25 { | ||
width: 25%; | ||
} | ||
|
||
&.wp-block-button__width-75 { | ||
width: calc(75% - #{ $blocks-block__margin * 0.25 }); | ||
} | ||
&.wp-block-button__width-50 { | ||
width: 50%; | ||
} | ||
|
||
&.wp-block-button__width-100 { | ||
width: auto; | ||
flex-basis: 100%; | ||
} | ||
} | ||
&.wp-block-button__width-75 { | ||
width: 75%; | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,11 @@ $blocks-block__margin: 0.5em; | |
display: flex; | ||
flex-direction: row; | ||
flex-wrap: wrap; | ||
column-gap: $blocks-block__margin; | ||
gap: var(--wp--style--block-gap, $blocks-block__margin); | ||
|
||
&.is-vertical { | ||
flex-direction: column; | ||
> .wp-block-button { | ||
/*rtl:ignore*/ | ||
margin-right: 0; | ||
&:last-child { | ||
margin-bottom: 0; | ||
} | ||
|
@@ -21,16 +19,7 @@ $blocks-block__margin: 0.5em; | |
// Increased specificity to override blocks default margin. | ||
> .wp-block-button { | ||
display: inline-block; | ||
/*rtl:ignore*/ | ||
margin-left: 0; | ||
/*rtl:ignore*/ | ||
margin-right: $blocks-block__margin; | ||
margin-bottom: $blocks-block__margin; | ||
|
||
&:last-child { | ||
/*rtl:ignore*/ | ||
margin-right: 0; | ||
} | ||
margin: 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In questions like these, the best way in most cases is too create a Trac ticket with a suggested fix and have it fixed in the theme, IMO. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree this is unfortunate but I think it's one of the fundamental tradeoffs we were hoping to make by going back to using In order to start using For blocks themes, I added the margin block support to the Buttons container to make this easily configurable. For classic themes, I thought about adding extra margin to the container to compensate -- but if the margin is on the container, it collapses into margin of adjacent blocks. It's another tricky one -- if we add margins to the individual buttons in addition to row-gap, we'll end up artificially increasing the spacing between rows, and the only other idea I had was adding another wrapping div (👎). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for exploring all the options and explaining the trade-offs in detail @stacimc! That satisfies me when it comes to this issue, and I think the benefits are worth it. I'm supportive of proceeding with this PR and opening Trac tickets where needed as Joen has suggested 👍 |
||
} | ||
|
||
&.is-content-justification-left { | ||
|
@@ -50,18 +39,6 @@ $blocks-block__margin: 0.5em; | |
&.is-content-justification-right { | ||
justify-content: flex-end; | ||
|
||
> .wp-block-button { | ||
/*rtl:ignore*/ | ||
margin-left: $blocks-block__margin; | ||
/*rtl:ignore*/ | ||
margin-right: 0; | ||
|
||
&:first-child { | ||
/*rtl:ignore*/ | ||
margin-left: 0; | ||
} | ||
} | ||
|
||
&.is-vertical { | ||
align-items: flex-end; | ||
} | ||
|
@@ -75,28 +52,6 @@ $blocks-block__margin: 0.5em; | |
&.aligncenter { | ||
text-align: center; | ||
} | ||
&.alignleft .wp-block-button { | ||
/*rtl:ignore*/ | ||
margin-left: 0; | ||
/*rtl:ignore*/ | ||
margin-right: $blocks-block__margin; | ||
|
||
&:last-child { | ||
/*rtl:ignore*/ | ||
margin-right: 0; | ||
} | ||
} | ||
&.alignright .wp-block-button { | ||
/*rtl:ignore*/ | ||
margin-right: 0; | ||
/*rtl:ignore*/ | ||
margin-left: $blocks-block__margin; | ||
|
||
&:first-child { | ||
/*rtl:ignore*/ | ||
margin-left: 0; | ||
} | ||
} | ||
|
||
// Back compat: Inner button blocks previously had their own alignment | ||
// options. Forcing them to 100% width in the flex container replicates | ||
|
@@ -116,7 +71,6 @@ $blocks-block__margin: 0.5em; | |
/* stylelint-enable indentation */ | ||
margin-left: auto; | ||
margin-right: auto; | ||
margin-bottom: $blocks-block__margin; | ||
width: 100%; | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know what this margin was for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was added here, looks like it was applied to the
LinkControl
in the block toolbar. It's been refactored since then and I'm fairly confident this isn't getting used at all anymore, actually 🤔I have tested adding/removing a button's link and the controls look good to me.