Skip to content

Commit

Permalink
Add padding support to Group block (#24966)
Browse files Browse the repository at this point in the history
Co-authored-by: Jon Q <[email protected]>
  • Loading branch information
youknowriad and Jon Q authored Sep 3, 2020
1 parent b9597d9 commit 97ec77e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
8 changes: 8 additions & 0 deletions packages/block-library/src/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@
margin-bottom: $default-block-margin;
}

.block-editor-block-list__layout > .wp-block:first-child {
margin-top: 0;
}

.block-editor-block-list__layout > .wp-block:last-child {
margin-bottom: 0;
}

// This tag marks the end of the styles that apply to editing canvas contents and need to be manipulated when we resize the editor.
#end-resizable-editor-section {
display: none;
Expand Down
3 changes: 2 additions & 1 deletion packages/block-library/src/group/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"__experimentalColor": {
"gradients": true,
"linkColor": true
}
},
"__experimentalPadding": true
}
}
6 changes: 6 additions & 0 deletions packages/block-library/src/group/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
InnerBlocks,
__experimentalBlock as Block,
} from '@wordpress/block-editor';
import { __experimentalBoxControl as BoxControl } from '@wordpress/components';
const { __Visualizer: BoxControlVisualizer } = BoxControl;

function GroupEdit( { attributes, className, clientId } ) {
const hasInnerBlocks = useSelect(
Expand All @@ -20,6 +22,10 @@ function GroupEdit( { attributes, className, clientId } ) {

return (
<BlockWrapper className={ className }>
<BoxControlVisualizer
values={ attributes.style?.spacing?.padding }
showValues={ attributes.style?.visualizers?.padding }
/>
<InnerBlocks
renderAppender={
hasInnerBlocks
Expand Down
3 changes: 0 additions & 3 deletions packages/block-library/src/group/editor.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
*/

.wp-block-group {
// Zero out the baseline margin that is set for every block in the editor.
margin-top: 0;
margin-bottom: 0;

// Ensure not rendering outside the element
// as -1px causes overflow-x scrollbars
Expand Down
10 changes: 9 additions & 1 deletion packages/components/src/box-control/unit-control.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,17 @@ export default function BoxUnitControl( {
function Tooltip( { children, text } ) {
if ( ! text ) return children;

/**
* Wrapping the children in a `<div />` as Tooltip as it attempts
* to render the <UnitControl />. Using a plain `<div />` appears to
* resolve this issue.
*
* Originally discovered and referenced here:
* https://github.com/WordPress/gutenberg/pull/24966#issuecomment-685875026
*/
return (
<BaseTooltip text={ text } position="top">
{ children }
<div>{ children }</div>
</BaseTooltip>
);
}

0 comments on commit 97ec77e

Please sign in to comment.