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

Commit 3a72cd5

Browse files
committed
fix(style): apply correct flex with ngStyle and layout change
#700
1 parent 9689207 commit 3a72cd5

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/lib/extended/style/style.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,22 @@ export class StyleDirective extends BaseDirective
109109
if (this._base.activeKey in changes) {
110110
this._ngStyleInstance.ngStyle = this._base.mqActivation.activatedInput || '';
111111
}
112+
113+
// Fix for issue 700
114+
const currentStyleBase = this._getAttributeValue('style');
115+
if (!currentStyleBase.includes(this._base.queryInput(this._base.activeKey))) {
116+
this.ngStyleBase = currentStyleBase || '';
117+
Object.getOwnPropertyNames(this._base.inputMap).forEach((input) => {
118+
if (input !== this._base.activeKey) {
119+
Object.getOwnPropertyNames(this._base.inputMap[input]).forEach((style) => {
120+
if (currentStyleBase.includes(style)) {
121+
delete this._base.inputMap[input][style];
122+
}
123+
});
124+
this._base.cacheInput(input, this._base.inputMap[input], true);
125+
}
126+
});
127+
}
112128
}
113129

114130

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,34 @@ describe('flex directive', () => {
7575
expectEl(dom).toHaveStyle({'flex': '1 1 0%'}, styler);
7676
});
7777

78+
it('should add correct styles for `fxFlex` and ngStyle with layout change', () => {
79+
componentWithTemplate(`
80+
<div fxLayout="row wrap" fxLayoutAlign="start center">
81+
<div *ngIf="true" fxFlex="10 1 auto" [ngStyle.lt-md]="{'width.px': 15}"></div>
82+
</div>
83+
`);
84+
fixture.detectChanges();
85+
matchMedia.activate('sm', true);
86+
let element = queryFor(fixture, '[fxFlex]')[0];
87+
expectEl(element).toHaveStyle({'width': '15px'}, styler);
88+
expectEl(element).toHaveStyle({'box-sizing': 'border-box'}, styler);
89+
expectEl(element).toHaveStyle({'flex': '10 1 auto'}, styler);
90+
});
91+
92+
it('should add correct styles for `fxFlex` and ngStyle without layout change', () => {
93+
componentWithTemplate(`
94+
<div fxLayout="row wrap" fxLayoutAlign="start center">
95+
<div fxFlex="10 1 auto" [ngStyle.lt-md]="{'width.px': 15}"></div>
96+
</div>
97+
`);
98+
fixture.detectChanges();
99+
matchMedia.activate('sm', true);
100+
let element = queryFor(fixture, '[fxFlex]')[0];
101+
expectEl(element).toHaveStyle({'width': '15px'}, styler);
102+
expectEl(element).toHaveStyle({'box-sizing': 'border-box'}, styler);
103+
expectEl(element).toHaveStyle({'flex': '10 1 auto'}, styler);
104+
});
105+
78106
it('should apply `fxGrow` value to flex-grow when used default `fxFlex`', () => {
79107
componentWithTemplate(`<div fxFlex fxGrow="10"></div>`);
80108
fixture.detectChanges();

0 commit comments

Comments
 (0)