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

Commit b245229

Browse files
authored
fix(fxFlex): restore correct styles after fxLayoutAlign is applied (#1038)
There is currently a race condition when `fxFlex` and `fxLayoutAlign` are present on the same element. Both directives end up injecting `max-width`/`max-height` stylings onto their host element, which leads to a conflict when both are present. The intended behavior is to have child elements take precandence due to their higher specificity/importance, so this commit adds a watcher for a sibling `fxLayoutAlign` in `fxFlex` to retrigger styles. Fixes #1038
1 parent ce9b989 commit b245229

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/lib/flex/flex/flex.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ export class FlexDirective extends BaseDirective2 {
234234
this.marshal.trackValue(this.parentElement, 'layout')
235235
.pipe(takeUntil(this.destroySubject))
236236
.subscribe(this.onLayoutChange.bind(this));
237+
this.marshal.trackValue(this.nativeElement, 'layout-align')
238+
.pipe(takeUntil(this.destroySubject))
239+
.subscribe(this.triggerReflow.bind(this));
237240
}
238241
}
239242

src/lib/flex/layout-align/layout-align.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,28 @@ describe('layout-align directive', () => {
304304
}, styler);
305305
});
306306

307+
it('should add responsive styles with fxFlex', () => {
308+
createTestComponent(`
309+
<div fxFlex.gt-sm="25%" fxFlex.lt-md="100%" fxLayoutAlign="center end"></div>
310+
`);
311+
312+
expectNativeEl(fixture).not.toHaveStyle({
313+
'max-width': '25%',
314+
}, styler);
315+
316+
mediaController.activate('md', true);
317+
318+
expectNativeEl(fixture).toHaveStyle({
319+
'max-width': '25%',
320+
}, styler);
321+
322+
mediaController.activate('sm', true);
323+
324+
expectNativeEl(fixture).not.toHaveStyle({
325+
'max-width': '25%',
326+
}, styler);
327+
});
328+
307329
it('should update responsive styles when the layout direction changes', () => {
308330
createTestComponent(`
309331
<div fxLayout

0 commit comments

Comments
 (0)