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

Buttons block: lighten editor DOM even more. #23222

Merged
merged 2 commits into from
Sep 25, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 9 additions & 9 deletions packages/block-library/src/buttons/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ const alignmentHooksSetting = {
function ButtonsEdit() {
const blockWrapperProps = useBlockWrapperProps();
return (
<div { ...blockWrapperProps }>
<AlignmentHookSettingsProvider value={ alignmentHooksSetting }>
<InnerBlocks
allowedBlocks={ ALLOWED_BLOCKS }
template={ BUTTONS_TEMPLATE }
orientation="horizontal"
/>
</AlignmentHookSettingsProvider>
</div>
<AlignmentHookSettingsProvider value={ alignmentHooksSetting }>
<InnerBlocks
allowedBlocks={ ALLOWED_BLOCKS }
__experimentalPassedProps={ blockWrapperProps }
__experimentalTagName="div"
template={ BUTTONS_TEMPLATE }
orientation="horizontal"
/>
</AlignmentHookSettingsProvider>
);
}

Expand Down
8 changes: 4 additions & 4 deletions packages/block-library/src/buttons/editor.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.wp-block-buttons .wp-block.block-editor-block-list__block[data-type="core/button"] {
display: inline-block;
width: auto;
.wp-block-buttons > .wp-block {
// Override editor auto block margins.
margin-left: 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Curious why this changed so much though?

Copy link
Member Author

Choose a reason for hiding this comment

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

I found that both the display and width properties were unnecessary. The former was already set by style.scss, and the latter was already auto by default. (And the editor never overrode it.) I tested with various alignments to make sure everything worked as expected.

I also found that the selector had a lot more specificity than it actually needed, so I simplified that. Notably, I chose to point at just the wp-block class for the children, to make it easier for 3rd-party button blocks to be inserted and styled correctly in the Buttons block. I almost just went with a .wp-block-buttons > * selector, but that turned out to not have enough specificity to override the margin-left value being set by the editor in some cases.

}

.wp-block[data-align="center"] > .wp-block-buttons {
Expand All @@ -15,6 +15,6 @@
justify-content: flex-end;
}

.wp-block-buttons .block-list-appender {
.wp-block-buttons > .block-list-appender {
display: inline-block;
}