Skip to content

Commit c62577b

Browse files
committed
fix #21
1 parent 18d17ba commit c62577b

File tree

6 files changed

+25
-8
lines changed

6 files changed

+25
-8
lines changed

bugs/bug4.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ function properBasis(basis) {
1616

1717
module.exports = function(decl) {
1818
if (decl.prop === 'flex') {
19+
if(decl.value === 'none'){
20+
return;
21+
}
1922
var values = postcss.list.space(decl.value);
2023
var flexGrow = values[0];
2124
var flexShrink = values[1];
22-
var flexBasis = values[2] || '0%';
25+
var flexBasis = values[2] || 'auto';
2326
decl.value = flexGrow + ' ' + (flexShrink || '1') + ' ' + properBasis(flexBasis);
2427
}
2528
};

bugs/bug6.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = function(decl) {
2+
if (decl.prop === 'flex') {
3+
if(decl.value === 'none'){
4+
decl.value = '0 0 auto';
5+
}
6+
}
7+
};

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var postcss = require('postcss');
22
var bug4 = require('./bugs/bug4');
3+
var bug6 = require('./bugs/bug6');
34
var bug81a = require('./bugs/bug81a');
45

56
module.exports = postcss.plugin('postcss-flexbugs-fixes', function(opts) {
@@ -8,6 +9,7 @@ module.exports = postcss.plugin('postcss-flexbugs-fixes', function(opts) {
89
return function(css) {
910
css.eachDecl(function(d) {
1011
bug4(d);
12+
bug6(d);
1113
bug81a(d);
1214
});
1315
};

specs/bug4Spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
var test = require('./test');
22

33
describe('bug 4', function() {
4-
it('set auto for default flex-basis property and flex-shrink in flex shorthand', function(done) {
4+
it('set auto for default flex-basis and 1 for flex-shrink in flex shorthand', function(done) {
55
var input = 'div{flex: 1;}';
6-
var output = 'div{flex: 1 1 0%;}';
6+
var output = 'div{flex: 1 1 auto;}';
77
test(input, output, {}, done);
88
});
9-
it('set flex-basis === auto when flex-basis is not set and flex-shrink is specified', function(done) {
9+
it('set auto for default flex-basis when not specified', function(done) {
1010
var input = 'div{flex: 1 1;}';
11-
var output = 'div{flex: 1 1 0%;}';
11+
var output = 'div{flex: 1 1 auto;}';
1212
test(input, output, {}, done);
1313
});
1414
it('set flex-basis === 0% for flex-basis with plain 0', function(done) {

specs/bug6Spec.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ var test = require('./test');
33
describe('bug 6', function() {
44
it('Set flex-shrink to 1 by default', function(done) {
55
var input = 'div{flex: 1;}';
6-
var output = 'div{flex: 1 1 0%;}';
6+
var output = 'div{flex: 1 1 auto;}';
7+
test(input, output, {}, done);
8+
});
9+
it('Set flex 0 0 auto when none', function(done) {
10+
var input = 'div{flex: none;}';
11+
var output = 'div{flex: 0 0 auto;}';
712
test(input, output, {}, done);
813
});
914
describe('does nothing', function() {

specs/bug81aSpec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ describe('bug 8.1.a', function() {
3636
describe('does nothing', function() {
3737
it('when using only first value', function(done) {
3838
var input = 'a{flex: 0}';
39-
var output = 'a{flex: 0 1 0%}';
39+
var output = 'a{flex: 0 1 auto}';
4040
test(input, output, {}, done);
4141
});
4242
it('when using only first and second values', function(done) {
4343
var input = 'a{flex: 0 0}';
44-
var output = 'a{flex: 0 0 0%}';
44+
var output = 'a{flex: 0 0 auto}';
4545
test(input, output, {}, done);
4646
});
4747
it('when not using calc', function(done) {

0 commit comments

Comments
 (0)