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

Commit c922ae3

Browse files
authored
fix(show-hide): account for fxLayout on same element (#948)
Fixes #945
1 parent 01c4148 commit c922ae3

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

src/lib/extended/show-hide/hide.spec.ts

+25-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {CommonModule} from '@angular/common';
1010
import {ComponentFixture, TestBed, inject} from '@angular/core/testing';
1111
import {
1212
MatchMedia,
13-
CoreModule,
1413
MockMatchMedia,
1514
MockMatchMediaProvider,
1615
MediaObserver,
@@ -22,7 +21,7 @@ import {customMatchers, expect, NgMatchers} from '../../utils/testing/custom-mat
2221
import {
2322
makeCreateTestComponent, expectNativeEl, queryFor
2423
} from '../../utils/testing/helpers';
25-
import {DefaultShowHideDirective} from './show-hide';
24+
import {FlexLayoutModule} from '../../module';
2625

2726

2827
describe('hide directive', () => {
@@ -59,8 +58,8 @@ describe('hide directive', () => {
5958

6059
// Configure testbed to prepare services
6160
TestBed.configureTestingModule({
62-
imports: [CommonModule, CoreModule],
63-
declarations: [TestHideComponent, DefaultShowHideDirective],
61+
imports: [CommonModule, FlexLayoutModule],
62+
declarations: [TestHideComponent],
6463
providers: [
6564
MockMatchMediaProvider,
6665
{provide: SERVER_TOKEN, useValue: true},
@@ -111,7 +110,12 @@ describe('hide directive', () => {
111110
expectNativeEl(fixture, {isHidden: false}).not.toHaveStyle({'display': 'none'}, styler);
112111
});
113112

114-
113+
it('should use "flex" display style when the element also has an fxLayoutAlign', () => {
114+
createTestComponent(`<div fxLayout fxLayoutAlign="start center" fxHide.xs></div>`);
115+
expectNativeEl(fixture).not.toHaveStyle({'display': 'none'}, styler);
116+
matchMedia.activate('xs');
117+
expectNativeEl(fixture).toHaveStyle({'display': 'none'}, styler);
118+
});
115119
});
116120

117121
describe('with responsive features', () => {
@@ -257,6 +261,22 @@ describe('hide directive', () => {
257261
expectNativeEl(fixture).toHaveStyle({'display': 'inline-block'}, styler);
258262
});
259263

264+
it('should support fxHide and fxLayout', () => {
265+
createTestComponent(`
266+
<div fxLayout [fxHide.xs]="true">
267+
This content to be shown ONLY when gt-sm
268+
</div>
269+
`);
270+
matchMedia.activate('xs');
271+
expectNativeEl(fixture).toHaveStyle({'display': 'none'}, styler);
272+
273+
matchMedia.activate('sm');
274+
expectNativeEl(fixture).not.toHaveStyle({'display': 'none'}, styler);
275+
276+
matchMedia.activate('xs');
277+
expectNativeEl(fixture).toHaveStyle({'display': 'none'}, styler);
278+
});
279+
260280
});
261281

262282

src/lib/extended/show-hide/show-hide.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ export class ShowHideDirective extends BaseDirective2 implements AfterViewInit,
6767
this.hasLayout = this.marshal.hasValue(this.nativeElement, 'layout');
6868
this.marshal.trackValue(this.nativeElement, 'layout')
6969
.pipe(takeUntil(this.destroySubject))
70-
.subscribe(this.updateWithValue.bind(this));
70+
.subscribe(this.triggerUpdate.bind(this));
71+
this.marshal.trackValue(this.nativeElement, 'layout-align')
72+
.pipe(takeUntil(this.destroySubject))
73+
.subscribe(this.triggerUpdate.bind(this));
7174

7275
const children = Array.from(this.nativeElement.children);
7376
for (let i = 0; i < children.length; i++) {

0 commit comments

Comments
 (0)