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

[grid-template] fix adding grid span for IE (fixes #1084) #1086

Merged
merged 3 commits into from
Aug 2, 2018
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
54 changes: 50 additions & 4 deletions lib/hacks/grid-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -345,21 +345,28 @@ function parseTemplate ({

// Insert parsed grid areas

function getMSDecls (area) {
/**
* Get an array of -ms- prefixed props and values
* @param {Object} [area] area object with columm and row data
* @param {Boolean} [addRowSpan] should we add grid-column-row value?
* @param {Boolean} [addColumnSpan] should we add grid-column-span value?
* @return {Array<Object>}
*/
function getMSDecls (area, addRowSpan = false, addColumnSpan = false) {
return [].concat(
{
prop: '-ms-grid-row',
value: String(area.row.start)
},
area.row.span > 1 ? {
(area.row.span > 1 || addRowSpan) ? {
prop: '-ms-grid-row-span',
value: String(area.row.span)
} : [],
{
prop: '-ms-grid-column',
value: String(area.column.start)
},
area.column.span > 1 ? {
(area.column.span > 1 || addColumnSpan) ? {
prop: '-ms-grid-column-span',
value: String(area.column.span)
} : []
Expand All @@ -375,6 +382,44 @@ function getParentMedia (parent) {
return getParentMedia(parent.parent)
}

/**
* Check grid-template(-areas) rules with the same selector for
* -ms-grid-(row|column)-span values. If initial and compared values are
* different - return an array of boolean values which need to be updated
* @param {Declaration} decl
* @param {Object} area area object with column and row data
* @param {String} areaName area name (e.g. "head")
* @return {Array<Boolean, Boolean>}
*/
function shouldAddSpan (decl, area, areaName) {
const root = decl.root()
const rule = decl.parent
const overrideValues = [false, false]

root.walkRules(rule.selector, node => {
// abort if we are on the same rule
if (rule.toString() === node.toString()) {
return false
}

node.walkDecls('grid-template', d => {
const template = parseTemplate({ decl: d, gap: getGridGap(d) })
const comparedArea = template.areas[areaName]
if (area.row.span !== comparedArea.row.span) {
overrideValues[0] = true
} else if (area.column.span !== comparedArea.column.span) {
overrideValues[1] = true
}

return undefined
})

return undefined
})

return overrideValues
}

function insertAreas (areas, decl, result) {
let missed = Object.keys(areas)

Expand All @@ -397,7 +442,8 @@ function insertAreas (areas, decl, result) {
rule.removeAll()

// insert prefixed decls in new rule
getMSDecls(area)
const [addRowSpan, addColumnSpan] = shouldAddSpan(decl, area, value)
getMSDecls(area, addRowSpan, addColumnSpan)
.forEach(i => rule.append(
Object.assign(i, {
raws: {
Expand Down
4 changes: 4 additions & 0 deletions test/cases/grid-template.out.css
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@
.head {
-ms-grid-row: 1;
-ms-grid-column: 1;
-ms-grid-column-span: 1;
}
.nav {
-ms-grid-row: 2;
-ms-grid-row-span: 1;
-ms-grid-column: 1;
}
.main {
Expand Down Expand Up @@ -389,11 +391,13 @@
@media (min-width: 600px) {
.k-1 {
-ms-grid-row: 1;
-ms-grid-row-span: 1;
-ms-grid-column: 1;
}
.k-2 {
-ms-grid-row: 1;
-ms-grid-column: 3;
-ms-grid-column-span: 1;
}
}

Expand Down