Skip to content

Commit b5d42a3

Browse files
committed
default flex-basis is 0% not auto. fixes #19
1 parent 8eb2ad1 commit b5d42a3

File tree

5 files changed

+13
-18
lines changed

5 files changed

+13
-18
lines changed

bugs/bug4.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
var postcss = require('postcss');
22

3-
function shouldSetAutoBasis(basisValue) {
4-
return !basisValue || !basisValue.length;
5-
}
6-
73
function shouldSetZeroBasis(basisValue) {
4+
if (!basisValue) {
5+
return false;
6+
}
87
return basisValue === '0' || basisValue.replace(/\s/g, '') === '0px';
98
}
109

1110
function properBasis(basis) {
12-
if (shouldSetAutoBasis(basis))
13-
{
14-
return 'auto';
15-
}
16-
if (shouldSetZeroBasis(basis)){
11+
if (shouldSetZeroBasis(basis)) {
1712
return '0%';
1813
}
1914
return basis;
@@ -24,7 +19,7 @@ module.exports = function(decl) {
2419
var values = postcss.list.space(decl.value);
2520
var flexGrow = values[0];
2621
var flexShrink = values[1];
27-
var flexBasis = values[2];
22+
var flexBasis = values[2] || '0%';
2823
decl.value = flexGrow + ' ' + (flexShrink || '1') + ' ' + properBasis(flexBasis);
2924
}
3025
};

specs/bug3Spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('bug 3', function() {
99
describe('does nothing', function() {
1010
it('when not display: flex', function(done) {
1111
var input = 'a{flex: 0;}';
12-
var output = 'a{flex: 0 1 auto;}';
12+
var output = 'a{flex: 0 1 0%;}';
1313
test(input, output, {}, done);
1414
});
1515
it('when no min-height is set', function(done) {

specs/bug4Spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ var test = require('./test');
33
describe('bug 4', function() {
44
it('set auto for default flex-basis property and flex-shrink in flex shorthand', function(done) {
55
var input = 'div{flex: 1;}';
6-
var output = 'div{flex: 1 1 auto;}';
6+
var output = 'div{flex: 1 1 0%;}';
77
test(input, output, {}, done);
88
});
99
it('set flex-basis === auto when flex-basis is not set and flex-shrink is specified', function(done) {
1010
var input = 'div{flex: 1 1;}';
11-
var output = 'div{flex: 1 1 auto;}';
11+
var output = 'div{flex: 1 1 0%;}';
1212
test(input, output, {}, done);
1313
});
1414
it('set flex-basis === 0% for flex-basis with plain 0', function(done) {
1515
var input = 'div{flex: 1 0 0;}';
1616
var output = 'div{flex: 1 0 0%;}';
1717
test(input, output, {}, done);
1818
});
19-
it('set flex-basis === 0% for flex-basis with 0 px', function(done) {
20-
var input = 'div{flex: 1 0 0 px;}';
19+
it('set flex-basis === 0% for flex-basis with 0px', function(done) {
20+
var input = 'div{flex: 1 0 0px;}';
2121
var output = 'div{flex: 1 0 0%;}';
2222
test(input, output, {}, done);
2323
});

specs/bug6Spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ 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 auto;}';
6+
var output = 'div{flex: 1 1 0%;}';
77
test(input, output, {}, done);
88
});
99
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 auto}';
39+
var output = 'a{flex: 0 1 0%}';
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 auto}';
44+
var output = 'a{flex: 0 0 0%}';
4545
test(input, output, {}, done);
4646
});
4747
it('when not using calc', function(done) {

0 commit comments

Comments
 (0)