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

Commit b028210

Browse files
authored
Revert "fix(show-hide): use initial value as fallback instead of parent" (#1251)
1 parent 942c507 commit b028210

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
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 || 'initial' : 'none'};
39+
return {'display': shouldShow ? parent.display : 'none'};
4040
}
4141
}
4242

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

Lines changed: 24 additions & 10 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} from '@angular/core';
9-
import {CommonModule} from '@angular/common';
8+
import {Component, Directive, OnInit, PLATFORM_ID} from '@angular/core';
9+
import {CommonModule, isPlatformBrowser} from '@angular/common';
1010
import {ComponentFixture, TestBed, inject} from '@angular/core/testing';
1111
import {
1212
ɵMatchMedia as MatchMedia,
@@ -35,15 +35,17 @@ describe('show directive', () => {
3535
let fixture: ComponentFixture<any>;
3636
let mediaController: MockMatchMedia;
3737
let styler: StyleUtils;
38+
let platformId: Object;
3839
let createTestComponent = (template: string) => {
3940
fixture = makeCreateTestComponent(() => TestShowComponent)(template);
4041

4142
// Can only Inject() AFTER TestBed.override(...)
4243
inject(
43-
[MatchMedia, StyleUtils],
44-
(_matchMedia: MockMatchMedia, _styler: StyleUtils) => {
44+
[MatchMedia, StyleUtils, PLATFORM_ID],
45+
(_matchMedia: MockMatchMedia, _styler: StyleUtils, _platformId: Object) => {
4546
mediaController = _matchMedia;
4647
styler = _styler;
48+
platformId = _platformId;
4749
})();
4850

4951
return fixture;
@@ -292,9 +294,15 @@ describe('show directive', () => {
292294
fixture.detectChanges();
293295

294296
// NOTE: platform-server can't compute display for unknown elements
295-
expectEl(queryFor(fixture, elSelector)[0]).toHaveCSS({
296-
'display': 'initial'
297-
}, styler);
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+
}
298306

299307
mediaController.activate('xs');
300308
fixture.detectChanges();
@@ -305,9 +313,15 @@ describe('show directive', () => {
305313
mediaController.activate('lg');
306314
fixture.detectChanges();
307315
// NOTE: platform-server can't compute display for unknown elements
308-
expectEl(queryFor(fixture, elSelector)[0]).toHaveCSS({
309-
'display': 'initial'
310-
}, styler);
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+
}
311325
});
312326
});
313327

0 commit comments

Comments
 (0)