Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 04d24d5

Browse files
ThomasBurlesonandrewseguin
authored andcommitted
fix(flex): fix use of values with 'auto' (#122)
* for cases where the flex-basis === "auto", use the specified or default values of shrink and grow. * add tests for flex-bases == "auto", "none", "initial", "noshrink", and "nogrow" Fixes #120.
1 parent 6482c12 commit 04d24d5

File tree

2 files changed

+49
-17
lines changed

2 files changed

+49
-17
lines changed

src/lib/flexbox/api/flex.spec.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ describe('flex directive', () => {
9090
'box-sizing': 'border-box',
9191
});
9292
});
93+
it('should work with "1 0 auto" values', () => {
94+
expectDOMFrom(`<div fxFlex="1 0 auto"></div>`).toHaveCssStyle({
95+
'flex': '1 0 auto',
96+
'box-sizing': 'border-box',
97+
});
98+
});
99+
it('should work with "1 1 auto" values', () => {
100+
expectDOMFrom(`<div fxFlex="1 1 auto"></div>`).toHaveCssStyle({
101+
'flex': '1 1 auto',
102+
'box-sizing': 'border-box',
103+
});
104+
});
93105
it('should work with calc values', () => {
94106
// @see http://caniuse.com/#feat=calc for IE issues with calc()
95107
if ( !isIE ) {
@@ -99,11 +111,37 @@ describe('flex directive', () => {
99111
});
100112
}
101113
});
102-
it('should work with named values', () => {
114+
115+
it('should work with "auto" values', () => {
116+
expectDOMFrom(`<div fxFlex="auto"></div>`).toHaveCssStyle({
117+
'flex': '1 1 auto'
118+
});
119+
});
120+
it('should work with "nogrow" values', () => {
103121
expectDOMFrom(`<div fxFlex="nogrow"></div>`).toHaveCssStyle({
104122
'flex': '0 1 auto'
105123
});
106124
});
125+
it('should work with "grow" values', () => {
126+
expectDOMFrom(`<div fxFlex="grow"></div>`).toHaveCssStyle({
127+
'flex': '1 1 100%'
128+
});
129+
});
130+
it('should work with "initial" values', () => {
131+
expectDOMFrom(`<div fxFlex="initial"></div>`).toHaveCssStyle({
132+
'flex': '0 1 auto'
133+
});
134+
});
135+
it('should work with "noshrink" values', () => {
136+
expectDOMFrom(`<div fxFlex="noshrink"></div>`).toHaveCssStyle({
137+
'flex': '1 0 auto'
138+
});
139+
});
140+
it('should work with "none" values', () => {
141+
expectDOMFrom(`<div fxFlex="none"></div>`).toHaveCssStyle({
142+
'flex': '0 0 auto'
143+
});
144+
});
107145

108146
it('should work with full-spec values', () => {
109147
expectDOMFrom(`<div fxFlex="1 2 0.9em"></div>`).toHaveCssStyle({

src/lib/flexbox/api/flex.ts

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ export type FlexBasisAlias = 'grow' | 'initial' | 'auto' | 'none' | 'nogrow' | '
4141
@Directive({
4242
selector: `
4343
[fxFlex],
44-
[fxFlex.xs]
44+
[fxFlex.xs],
4545
[fxFlex.gt-xs],
4646
[fxFlex.sm],
4747
[fxFlex.gt-sm]
@@ -249,30 +249,24 @@ export class FlexDirective extends BaseFxDirective implements OnInit, OnChanges,
249249
case '':
250250
css = extendObject(clearStyles, {'flex': '1 1 0.000000001px'});
251251
break;
252+
case 'initial': // default
253+
case 'nogrow':
254+
css = extendObject(clearStyles, {'flex': '0 1 auto'});
255+
break;
252256
case 'grow':
253257
css = extendObject(clearStyles, {'flex': '1 1 100%'});
254258
break;
255-
case 'initial':
256-
css = extendObject(clearStyles, {'flex': '0 1 auto'});
257-
break; // default
258-
case 'auto':
259-
css = extendObject(clearStyles, {'flex': '1 1 auto'});
260-
break;
261-
case 'none':
259+
case 'noshrink':
262260
shrink = 0;
263-
css = extendObject(clearStyles, {'flex': '0 0 auto'});
261+
css = extendObject(clearStyles, {'flex': '1 0 auto'});
264262
break;
265-
case 'nogrow':
266-
css = extendObject(clearStyles, {'flex': '0 1 auto'});
263+
case 'auto':
264+
css = extendObject(clearStyles, {'flex': `${grow} ${shrink} auto`});
267265
break;
268266
case 'none':
269-
css = extendObject(clearStyles, {'flex': 'none'});
270-
break;
271-
case 'noshrink':
272267
shrink = 0;
273-
css = extendObject(clearStyles, {'flex': '1 0 auto'});
268+
css = extendObject(clearStyles, {'flex': '0 0 auto'});
274269
break;
275-
276270
default:
277271
let isPercent = String(basis).indexOf('%') > -1;
278272

0 commit comments

Comments
 (0)