Skip to content

Commit aaecf3b

Browse files
yepninjaai
authored andcommitted
[grid-template-areas] Repetitive grid-area declarations (#983)
* [grid-template-areas] Add test for repetitive grid-area declarations * [grid-template-areas] Fix prefixing of repetitive grid-area declarations
1 parent 15a54ab commit aaecf3b

3 files changed

Lines changed: 32 additions & 7 deletions

File tree

lib/hacks/grid-template-areas.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,20 @@ class GridTemplateAreas extends Declaration {
5858
if (prefix !== '-ms-') return super.insert(decl, prefix, prefixes);
5959

6060
const areas = parseGridAreas(decl.value);
61+
let missed = Object.keys(areas);
62+
6163
this.getRoot(decl.parent).walkDecls('grid-area', gridArea => {
6264
const value = gridArea.value;
6365
const area = areas[value];
64-
delete areas[value];
6566

66-
if (gridArea.parent.some(i => i.prop === '-ms-grid-row')) {
67-
return undefined;
68-
}
67+
missed = missed.filter(e => e !== value);
6968

7069
if (area) {
70+
gridArea.parent
71+
.walkDecls(/-ms-grid-(row|column)/, (d) => {
72+
d.remove();
73+
});
74+
7175
gridArea.cloneBefore({
7276
prop: '-ms-grid-row',
7377
value: String(area.row.start)
@@ -92,7 +96,6 @@ class GridTemplateAreas extends Declaration {
9296
return undefined;
9397
});
9498

95-
const missed = Object.keys(areas);
9699
if (missed.length > 0) {
97100
decl.warn(result, 'Can not find grid areas: ' + missed.join(', '));
98101
}

test/cases/grid-template-areas.css

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
grid-template-areas:
33
"head head"
44
"nav main"
5-
"nav foot";
5+
"nav foot"
6+
"another";
67
}
78

89
.b {
@@ -21,6 +22,10 @@
2122
grid-area: foot;
2223
}
2324

25+
.f {
26+
grid-area: foot;
27+
}
28+
2429
@media (max-width: 1000px) {
2530
.a {
2631
grid-template-areas: "head main";
@@ -33,4 +38,8 @@
3338
.c {
3439
grid-area: main;
3540
}
41+
42+
.d {
43+
grid-area: main;
44+
}
3645
}

test/cases/grid-template-areas.out.css

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
grid-template-areas:
33
"head head"
44
"nav main"
5-
"nav foot";
5+
"nav foot"
6+
"another";
67
}
78

89
.b {
@@ -31,6 +32,12 @@
3132
grid-area: foot;
3233
}
3334

35+
.f {
36+
-ms-grid-row: 3;
37+
-ms-grid-column: 2;
38+
grid-area: foot;
39+
}
40+
3441
@media (max-width: 1000px) {
3542
.a {
3643
grid-template-areas: "head main";
@@ -47,4 +54,10 @@
4754
-ms-grid-column: 2;
4855
grid-area: main;
4956
}
57+
58+
.d {
59+
-ms-grid-row: 1;
60+
-ms-grid-column: 2;
61+
grid-area: main;
62+
}
5063
}

0 commit comments

Comments
 (0)