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

Commit 3fe5ea3

Browse files
fix(flex): add min-width to elements with flex basis using px values
Need to specify the min- widths/heights css when using fxFlex=“<val>px” Fixes #68.
1 parent a77de3c commit 3fe5ea3

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

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

+16
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,21 @@ describe('flex directive', () => {
8383
'flex' : '1 2 0.9em'
8484
});
8585
});
86+
it('should set a min-width when the shrink == 0', () => {
87+
expectDOMFrom(`<div fxFlex="1 0 37px"></div>`).toHaveCssStyle({
88+
'flex' : '1 0 37px',
89+
'max-width' : '37px',
90+
'min-width' : '37px',
91+
'box-sizing': 'border-box',
92+
});
93+
});
94+
it('should set a min-width when basis is a Px value', () => {
95+
expectDOMFrom(`<div fxFlex="312px"></div>`).toHaveCssStyle({
96+
'flex' : '1 1 312px',
97+
'max-width' : '312px',
98+
'min-width' : '312px'
99+
});
100+
});
86101

87102
describe('', () => {
88103

@@ -92,6 +107,7 @@ describe('flex directive', () => {
92107
</div>
93108
`)
94109
.not.toHaveCssStyle({
110+
'flex-direction': 'row',
95111
'max-height' : '37%',
96112
});
97113
});

src/lib/flexbox/api/flex.ts

+13-8
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,8 @@ export class FlexDirective extends BaseFxDirective implements OnInit, OnChanges,
178178
* Validate the value to be one of the acceptable value options
179179
* Use default fallback of "row"
180180
*/
181-
private _validateValue(grow: number, shrink: number, basis: string|number|FlexBasisAlias) {
182-
let css;
181+
private _validateValue(grow: number|string, shrink: number|string, basis: string|number|FlexBasisAlias) {
182+
let css, isValue;
183183
let direction = (this._layout === 'column') || (this._layout == 'column-reverse') ?
184184
'column' :
185185
'row';
@@ -216,6 +216,7 @@ export class FlexDirective extends BaseFxDirective implements OnInit, OnChanges,
216216
css = extendObject(clearStyles, {'flex': '1 1 auto'});
217217
break;
218218
case 'none':
219+
shrink = 0;
219220
css = extendObject(clearStyles, {'flex': '0 0 auto'});
220221
break;
221222
case 'nogrow':
@@ -225,16 +226,18 @@ export class FlexDirective extends BaseFxDirective implements OnInit, OnChanges,
225226
css = extendObject(clearStyles, {'flex': 'none'});
226227
break;
227228
case 'noshrink':
229+
shrink = 0;
228230
css = extendObject(clearStyles, {'flex': '1 0 auto'});
229231
break;
230232

231233
default:
232234
let isPercent = String(basis).indexOf('%') > -1;
233-
let isValue = String(basis).indexOf('px') > -1 ||
234-
String(basis).indexOf('calc') > -1 ||
235-
String(basis).indexOf('em') > -1 ||
236-
String(basis).indexOf('vw') > -1 ||
237-
String(basis).indexOf('vh') > -1;
235+
236+
isValue = String(basis).indexOf('px') > -1 ||
237+
String(basis).indexOf('calc') > -1 ||
238+
String(basis).indexOf('em') > -1 ||
239+
String(basis).indexOf('vw') > -1 ||
240+
String(basis).indexOf('vh') > -1;
238241

239242
// Defaults to percentage sizing unless `px` is explicitly set
240243
if (!isValue && !isPercent && !isNaN(basis as any))
@@ -253,9 +256,11 @@ export class FlexDirective extends BaseFxDirective implements OnInit, OnChanges,
253256

254257
let max = (direction === 'row') ? 'max-width' : 'max-height';
255258
let min = (direction === 'row') ? 'min-width' : 'min-height';
259+
256260
let usingCalc = String(basis).indexOf('calc') > -1;
261+
let isPx = String(basis).indexOf('px') > -1 || usingCalc;
257262

258-
css[min] = (basis == '0%') ? 0 : null;
263+
css[min] = (basis == '0%') ? 0 : isPx ? basis : null;
259264
css[max] = (basis == '0%') ? 0 : usingCalc ? null : basis;
260265

261266
return extendObject(css, {'box-sizing': 'border-box'});

0 commit comments

Comments
 (0)