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

Use grid-auto-rows to ensure min height of new grid rows. #61383

Closed
wants to merge 3 commits into from
Closed
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
6 changes: 6 additions & 0 deletions lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,11 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support
'selector' => $selector,
'declarations' => array( 'grid-template-rows' => 'repeat(' . $layout['rowCount'] . ', minmax(0, 1fr))' ),
);
} else {
$layout_styles[] = array(
'selector' => $selector,
'declarations' => array( 'grid-auto-rows' => 'minmax(1.5em, min-content)' ),
);
}
} else {
$minimum_column_width = ! empty( $layout['minimumColumnWidth'] ) ? $layout['minimumColumnWidth'] : '12rem';
Expand All @@ -484,6 +489,7 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support
'selector' => $selector,
'declarations' => array(
'grid-template-columns' => 'repeat(auto-fill, minmax(min(' . $minimum_column_width . ', 100%), 1fr))',
'grid-auto-rows' => 'minmax(1.5em, min-content)',
'container-type' => 'inline-size',
),
);
Expand Down
3 changes: 3 additions & 0 deletions packages/block-editor/src/layouts/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,13 @@ export default {
rules.push(
`grid-template-rows: repeat(${ rowCount }, minmax(0, 1fr))`
);
} else {
rules.push( `grid-auto-rows: minmax(1.5em, min-content)` );
}
} else if ( minimumColumnWidth ) {
rules.push(
`grid-template-columns: repeat(auto-fill, minmax(min(${ minimumColumnWidth }, 100%), 1fr))`,
`grid-auto-rows: minmax(1.5em, min-content)`,
`container-type: inline-size`
);
}
Expand Down
8 changes: 4 additions & 4 deletions packages/block-editor/src/layouts/test/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import grid from '../grid';

describe( 'getLayoutStyle', () => {
it( 'should return only `grid-template-columns` and `container-type` properties if no non-default params are provided', () => {
const expected = `.editor-styles-wrapper .my-container { grid-template-columns: repeat(auto-fill, minmax(min(12rem, 100%), 1fr)); container-type: inline-size; }`;
it( 'should return only `grid-template-columns`, `grid-auto-rows` and `container-type` properties if no non-default params are provided', () => {
const expected = `.editor-styles-wrapper .my-container { grid-template-columns: repeat(auto-fill, minmax(min(12rem, 100%), 1fr)); grid-auto-rows: minmax(1.5em, min-content); container-type: inline-size; }`;

const result = grid.getLayoutStyle( {
selector: '.my-container',
Expand All @@ -18,8 +18,8 @@ describe( 'getLayoutStyle', () => {

expect( result ).toBe( expected );
} );
it( 'should return only `grid-template-columns` if columnCount property is provided', () => {
const expected = `.editor-styles-wrapper .my-container { grid-template-columns: repeat(3, minmax(0, 1fr)); }`;
it( 'should return only `grid-template-columns` and `grid-auto-rows` if columnCount property is provided', () => {
const expected = `.editor-styles-wrapper .my-container { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: minmax(1.5em, min-content); }`;

const result = grid.getLayoutStyle( {
selector: '.my-container',
Expand Down
4 changes: 2 additions & 2 deletions phpunit/block-supports/layout-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ public function data_gutenberg_get_layout_style() {
'type' => 'grid',
),
),
'expected_output' => '.wp-layout{grid-template-columns:repeat(auto-fill, minmax(min(12rem, 100%), 1fr));container-type:inline-size;}',
'expected_output' => '.wp-layout{grid-template-columns:repeat(auto-fill, minmax(min(12rem, 100%), 1fr));grid-auto-rows:minmax(1.5em, min-content);container-type:inline-size;}',
),
'grid layout with columnCount' => array(
'args' => array(
Expand All @@ -381,7 +381,7 @@ public function data_gutenberg_get_layout_style() {
'columnCount' => 3,
),
),
'expected_output' => '.wp-layout{grid-template-columns:repeat(3, minmax(0, 1fr));}',
'expected_output' => '.wp-layout{grid-template-columns:repeat(3, minmax(0, 1fr));grid-auto-rows:minmax(1.5em, min-content);}',
),
'default layout with blockGap to verify converting gap value into valid CSS' => array(
'args' => array(
Expand Down
Loading