Skip to content

Commit

Permalink
Don't convert min-width: 0% to min-width: 0 (#1385)
Browse files Browse the repository at this point in the history
* Don't convert `min-width: 0%` to `min-width: 0`

This transformation isn't safe on IE11. See https://codepen.io/nex3/full/XWVqJrJ as an example of `min-width: 0` breaking IE11's flexbox behavior where `min-width: 0%` does not.

* Add a test

* Update packages/postcss-convert-values/src/index.js

Co-authored-by: Ludovico Fischer <43557+ludofischer@users.noreply.github.com>

Co-authored-by: Ludovico Fischer <43557+ludofischer@users.noreply.github.com>
  • Loading branch information
nex3 and ludofischer committed Apr 13, 2022
1 parent a469a7f commit 57f060a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions packages/postcss-convert-values/src/index.js
Expand Up @@ -36,6 +36,13 @@ const keepWhenZero = new Set([
'line-height',
]);

// Can't remove the % on these properties when they're 0 on IE 11
const keepZeroPercent = new Set([
'max-height',
'height',
'min-width',
]);

/**
* Numbers without digits after the dot are technically invalid,
* but in that case css-value-parser returns the dot as part of the unit,
Expand Down Expand Up @@ -110,8 +117,7 @@ function shouldKeepZeroUnit(decl) {
const { parent } = decl;
const lowerCasedProp = decl.prop.toLowerCase();
return (
(decl.value.includes('%') &&
(lowerCasedProp === 'max-height' || lowerCasedProp === 'height')) ||
(decl.value.includes('%') && keepZeroPercent.has(lowerCasedProp)) ||
(parent &&
parent.parent &&
parent.parent.type === 'atrule' &&
Expand Down
4 changes: 2 additions & 2 deletions packages/postcss-convert-values/test/index.js
Expand Up @@ -252,8 +252,8 @@ test(
);

test(
'should not strip the percentage from 0 in max-height & height props',
passthroughCSS('h1{height:0%;max-height:0%}')
'should not strip the percentage from 0 in max-height, height, and min-width props',
passthroughCSS('h1{height:0%;max-height:0%;min-width:0%}')
);

test(
Expand Down

0 comments on commit 57f060a

Please sign in to comment.