From 80fdd80c9e6fe2215ac5252a3a475d7ce00f60d5 Mon Sep 17 00:00:00 2001 From: CaerusKaru Date: Wed, 13 May 2020 12:31:55 -0500 Subject: [PATCH] Revert "fix(show-hide): use initial value as fallback instead of parent (#1243)" This reverts commit bf2355bb0426828a8fc74927e7011aa5b0758349. --- src/lib/extended/show-hide/show-hide.ts | 2 +- src/lib/extended/show-hide/show.spec.ts | 34 +++++++++++++++++-------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/lib/extended/show-hide/show-hide.ts b/src/lib/extended/show-hide/show-hide.ts index b405ce8d0..49fc808b7 100644 --- a/src/lib/extended/show-hide/show-hide.ts +++ b/src/lib/extended/show-hide/show-hide.ts @@ -36,7 +36,7 @@ export interface ShowHideParent { export class ShowHideStyleBuilder extends StyleBuilder { buildStyles(show: string, parent: ShowHideParent) { const shouldShow = show === 'true'; - return {'display': shouldShow ? parent.display || 'initial' : 'none'}; + return {'display': shouldShow ? parent.display : 'none'}; } } diff --git a/src/lib/extended/show-hide/show.spec.ts b/src/lib/extended/show-hide/show.spec.ts index b36e89c3d..ddddd3352 100644 --- a/src/lib/extended/show-hide/show.spec.ts +++ b/src/lib/extended/show-hide/show.spec.ts @@ -5,8 +5,8 @@ * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ -import {Component, Directive, OnInit} from '@angular/core'; -import {CommonModule} from '@angular/common'; +import {Component, Directive, OnInit, PLATFORM_ID} from '@angular/core'; +import {CommonModule, isPlatformBrowser} from '@angular/common'; import {ComponentFixture, TestBed, inject} from '@angular/core/testing'; import { ɵMatchMedia as MatchMedia, @@ -35,15 +35,17 @@ describe('show directive', () => { let fixture: ComponentFixture; let mediaController: MockMatchMedia; let styler: StyleUtils; + let platformId: Object; let createTestComponent = (template: string) => { fixture = makeCreateTestComponent(() => TestShowComponent)(template); // Can only Inject() AFTER TestBed.override(...) inject( - [MatchMedia, StyleUtils], - (_matchMedia: MockMatchMedia, _styler: StyleUtils) => { + [MatchMedia, StyleUtils, PLATFORM_ID], + (_matchMedia: MockMatchMedia, _styler: StyleUtils, _platformId: Object) => { mediaController = _matchMedia; styler = _styler; + platformId = _platformId; })(); return fixture; @@ -292,9 +294,15 @@ describe('show directive', () => { fixture.detectChanges(); // NOTE: platform-server can't compute display for unknown elements - expectEl(queryFor(fixture, elSelector)[0]).toHaveCSS({ - 'display': 'initial' - }, styler); + if (isPlatformBrowser(platformId)) { + expectEl(queryFor(fixture, elSelector)[0]).toHaveCSS({ + 'display': 'inline' + }, styler); + } else { + expectEl(queryFor(fixture, elSelector)[0]).not.toHaveStyle({ + 'display': '*' + }, styler); + } mediaController.activate('xs'); fixture.detectChanges(); @@ -305,9 +313,15 @@ describe('show directive', () => { mediaController.activate('lg'); fixture.detectChanges(); // NOTE: platform-server can't compute display for unknown elements - expectEl(queryFor(fixture, elSelector)[0]).toHaveCSS({ - 'display': 'initial' - }, styler); + if (isPlatformBrowser(platformId)) { + expectEl(queryFor(fixture, elSelector)[0]).toHaveCSS({ + 'display': 'inline' + }, styler); + } else { + expectEl(queryFor(fixture, elSelector)[0]).not.toHaveStyle({ + 'display': '*' + }, styler); + } }); });