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

Commit c4f9fe2

Browse files
authored
fix(core): reset current value when directive is cleared (#1376)
1 parent 4ea6714 commit c4f9fe2

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

projects/libs/flex-layout/core/base/base2.ts

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export abstract class BaseDirective2 implements OnChanges, OnDestroy {
105105
});
106106
this.applyStyleToElement(this.mru);
107107
this.mru = {};
108+
this.currentValue = undefined;
108109
}
109110

110111
/** Force trigger style updates on DOM element */

projects/libs/flex-layout/core/media-marshaller/media-marshaller.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ export class MediaMarshaller {
135135
if (bpMap) {
136136
const values = this.getActivatedValues(bpMap, key);
137137
if (values) {
138-
return values.get(key) !== undefined || false;
138+
return values.get(key) !== undefined ?? false;
139139
}
140140
}
141141
return false;
@@ -154,7 +154,7 @@ export class MediaMarshaller {
154154
bpMap = new Map().set(bp, new Map().set(key, val));
155155
this.elementMap.set(element, bpMap);
156156
} else {
157-
const values = (bpMap.get(bp) || new Map()).set(key, val);
157+
const values = (bpMap.get(bp) ?? new Map()).set(key, val);
158158
bpMap.set(bp, values);
159159
this.elementMap.set(element, bpMap);
160160
}

projects/libs/flex-layout/flex/layout/layout.spec.ts

+24
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,30 @@ describe('layout directive', () => {
300300
}, styler);
301301

302302
});
303+
304+
it('should fallback to default styles after multiple state changes', () => { // tslint:disable-line:max-line-length
305+
createTestComponent(`<div fxLayout.md='column'></div>`);
306+
307+
expectNativeEl(fixture).not.toHaveStyle({
308+
'flex-direction': 'column'
309+
}, styler);
310+
311+
mediaController.activate('md');
312+
expectNativeEl(fixture).toHaveStyle({
313+
'flex-direction': 'column'
314+
}, styler);
315+
316+
mediaController.activate('lg');
317+
expectNativeEl(fixture).not.toHaveStyle({
318+
'flex-direction': 'column'
319+
}, styler);
320+
321+
mediaController.activate('md');
322+
expectNativeEl(fixture).toHaveStyle({
323+
'flex-direction': 'column'
324+
}, styler);
325+
});
326+
303327
it('should fallback to closest overlapping value when the active mediaQuery change is not configured', () => { // tslint:disable-line:max-line-length
304328
createTestComponent(`<div fxLayout fxLayout.gt-sm='column' fxLayout.md='row'></div>`);
305329

0 commit comments

Comments
 (0)