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

Commit bf2355b

Browse files
authored
fix(show-hide): use initial value as fallback instead of parent (#1243)
1 parent e8ded3e commit bf2355b

File tree

2 files changed

+11
-25
lines changed

2 files changed

+11
-25
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export interface ShowHideParent {
3636
export class ShowHideStyleBuilder extends StyleBuilder {
3737
buildStyles(show: string, parent: ShowHideParent) {
3838
const shouldShow = show === 'true';
39-
return {'display': shouldShow ? parent.display : 'none'};
39+
return {'display': shouldShow ? parent.display || 'initial' : 'none'};
4040
}
4141
}
4242

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

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import {Component, Directive, OnInit, PLATFORM_ID} from '@angular/core';
9-
import {CommonModule, isPlatformBrowser} from '@angular/common';
8+
import {Component, Directive, OnInit} from '@angular/core';
9+
import {CommonModule} from '@angular/common';
1010
import {ComponentFixture, TestBed, inject} from '@angular/core/testing';
1111
import {
1212
ɵMatchMedia as MatchMedia,
@@ -35,17 +35,15 @@ describe('show directive', () => {
3535
let fixture: ComponentFixture<any>;
3636
let mediaController: MockMatchMedia;
3737
let styler: StyleUtils;
38-
let platformId: Object;
3938
let createTestComponent = (template: string) => {
4039
fixture = makeCreateTestComponent(() => TestShowComponent)(template);
4140

4241
// Can only Inject() AFTER TestBed.override(...)
4342
inject(
44-
[MatchMedia, StyleUtils, PLATFORM_ID],
45-
(_matchMedia: MockMatchMedia, _styler: StyleUtils, _platformId: Object) => {
43+
[MatchMedia, StyleUtils],
44+
(_matchMedia: MockMatchMedia, _styler: StyleUtils) => {
4645
mediaController = _matchMedia;
4746
styler = _styler;
48-
platformId = _platformId;
4947
})();
5048

5149
return fixture;
@@ -294,15 +292,9 @@ describe('show directive', () => {
294292
fixture.detectChanges();
295293

296294
// NOTE: platform-server can't compute display for unknown elements
297-
if (isPlatformBrowser(platformId)) {
298-
expectEl(queryFor(fixture, elSelector)[0]).toHaveCSS({
299-
'display': 'inline'
300-
}, styler);
301-
} else {
302-
expectEl(queryFor(fixture, elSelector)[0]).not.toHaveStyle({
303-
'display': '*'
304-
}, styler);
305-
}
295+
expectEl(queryFor(fixture, elSelector)[0]).toHaveCSS({
296+
'display': 'initial'
297+
}, styler);
306298

307299
mediaController.activate('xs');
308300
fixture.detectChanges();
@@ -313,15 +305,9 @@ describe('show directive', () => {
313305
mediaController.activate('lg');
314306
fixture.detectChanges();
315307
// NOTE: platform-server can't compute display for unknown elements
316-
if (isPlatformBrowser(platformId)) {
317-
expectEl(queryFor(fixture, elSelector)[0]).toHaveCSS({
318-
'display': 'inline'
319-
}, styler);
320-
} else {
321-
expectEl(queryFor(fixture, elSelector)[0]).not.toHaveStyle({
322-
'display': '*'
323-
}, styler);
324-
}
308+
expectEl(queryFor(fixture, elSelector)[0]).toHaveCSS({
309+
'display': 'initial'
310+
}, styler);
325311
});
326312
});
327313

0 commit comments

Comments
 (0)