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

Commit 5990ed0

Browse files
charsleysaCaerusKaru
authored andcommitted
feat(flex): add support for rem units (#901)
Enable support for rem units in FlexDirective Closes #898
1 parent 1205588 commit 5990ed0

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/lib/flex/flex/flex.spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,15 @@ describe('flex directive', () => {
497497
}, styler);
498498
});
499499

500+
it('should set a min-width and max-width when basis is a rem value', () => {
501+
componentWithTemplate(`<div fxFlex='12rem'></div>`);
502+
expectNativeEl(fixture).toHaveStyle({
503+
'flex': '1 1 12rem',
504+
'max-width': '12rem',
505+
'min-width': '12rem'
506+
}, styler);
507+
});
508+
500509
describe('', () => {
501510

502511
it('should ignore fxLayout settings on same element', () => {

src/lib/flex/flex/flex.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ export class FlexStyleBuilder extends StyleBuilder {
6161
const hasCalc = String(basis).indexOf('calc') > -1;
6262
const usingCalc = hasCalc || (basis === 'auto');
6363
const isPercent = String(basis).indexOf('%') > -1 && !hasCalc;
64-
const hasUnits = String(basis).indexOf('px') > -1 || String(basis).indexOf('em') > -1 ||
65-
String(basis).indexOf('vw') > -1 || String(basis).indexOf('vh') > -1;
66-
const isPx = String(basis).indexOf('px') > -1 || usingCalc;
64+
const hasUnits = String(basis).indexOf('px') > -1 || String(basis).indexOf('rem') > -1 ||
65+
String(basis).indexOf('em') > -1 || String(basis).indexOf('vw') > -1 ||
66+
String(basis).indexOf('vh') > -1;
6767

6868
let isValue = (hasCalc || hasUnits);
6969

@@ -166,7 +166,7 @@ export class FlexStyleBuilder extends StyleBuilder {
166166

167167
// Fix for issues 277, 534, and 728
168168
if (basis !== '0%' && basis !== '0px' && basis !== '0.000000001px' && basis !== 'auto') {
169-
css[min] = isFixed || (isPx && grow) ? basis : null;
169+
css[min] = isFixed || (isValue && grow) ? basis : null;
170170
css[max] = isFixed || (!usingCalc && shrink) ? basis : null;
171171
}
172172

0 commit comments

Comments
 (0)