Skip to content

Commit cf1ebcb

Browse files
authored
Fix grid gap inheritance from row-gap and column-gap longhands (#1557)
1 parent e1212dc commit cf1ebcb

3 files changed

Lines changed: 50 additions & 4 deletions

File tree

‎lib/hacks/grid-utils.js‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ let uniq = require('../utils').uniq
55
let escapeRegexp = require('../utils').escapeRegexp
66
let splitSelector = require('../utils').splitSelector
77

8+
const GAP_PROPS = /^(grid-)?((row|column)-)?gap$/
9+
810
function convert(value) {
911
if (
1012
value &&
@@ -878,8 +880,7 @@ function getGridGap(decl) {
878880
let gap = {}
879881

880882
// try to find gap
881-
let testGap = /^(grid-)?((row|column)-)?gap$/
882-
decl.parent.walkDecls(testGap, ({ prop, value }) => {
883+
decl.parent.walkDecls(GAP_PROPS, ({ prop, value }) => {
883884
if (/^(grid-)?gap$/.test(prop)) {
884885
let [row, , column] = parser(value).nodes
885886

@@ -1014,8 +1015,8 @@ function inheritGridGap(decl, gap) {
10141015
return false
10151016
}
10161017

1017-
// find grid-gap values
1018-
r.walkDecls('grid-gap', d => (gridGap = getGridGap(d)))
1018+
// find gap values, set either by the shorthand or by the longhands
1019+
r.walkDecls(GAP_PROPS, d => (gridGap = getGridGap(d)))
10191020

10201021
// skip rule without gaps
10211022
if (!gridGap || Object.keys(gridGap).length === 0) {

‎test/cases/grid-gap.css‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,3 +301,23 @@
301301
grid-template-rows: repeat(2, 100px);
302302
}
303303
}
304+
305+
.longhand-gap {
306+
display: grid;
307+
grid-column-gap: 50px;
308+
grid-row-gap: 40px;
309+
grid-template-areas:
310+
"p p"
311+
"q q";
312+
grid-template-columns: repeat(2, 1fr);
313+
grid-template-rows: repeat(2, 100px);
314+
}
315+
316+
/* must inherit gap from .longhand-gap */
317+
.longhand-gap.modifier {
318+
grid-template-areas:
319+
"p p"
320+
"q q";
321+
grid-template-columns: repeat(2, 1fr);
322+
grid-template-rows: repeat(2, 100px);
323+
}

‎test/cases/grid-gap.out.css‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,3 +435,28 @@
435435
grid-template-rows: repeat(2, 100px);
436436
}
437437
}
438+
439+
.longhand-gap {
440+
display: -ms-grid;
441+
display: grid;
442+
grid-column-gap: 50px;
443+
grid-row-gap: 40px;
444+
grid-template-areas:
445+
"p p"
446+
"q q";
447+
-ms-grid-columns: 1fr 50px 1fr;
448+
grid-template-columns: repeat(2, 1fr);
449+
-ms-grid-rows: 100px 40px 100px;
450+
grid-template-rows: repeat(2, 100px);
451+
}
452+
453+
/* must inherit gap from .longhand-gap */
454+
.longhand-gap.modifier {
455+
grid-template-areas:
456+
"p p"
457+
"q q";
458+
-ms-grid-columns: 1fr 50px 1fr;
459+
grid-template-columns: repeat(2, 1fr);
460+
-ms-grid-rows: 100px 40px 100px;
461+
grid-template-rows: repeat(2, 100px);
462+
}

0 commit comments

Comments
 (0)