Skip to content

Commit

Permalink
Revert "fix(show-hide): use initial value as fallback instead of pare…
Browse files Browse the repository at this point in the history
…nt (#1243)"

This reverts commit bf2355b.
  • Loading branch information
CaerusKaru authored May 13, 2020
1 parent 942c507 commit 80fdd80
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/lib/extended/show-hide/show-hide.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'};
}
}

Expand Down
34 changes: 24 additions & 10 deletions src/lib/extended/show-hide/show.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -35,15 +35,17 @@ describe('show directive', () => {
let fixture: ComponentFixture<any>;
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;
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
});
});

Expand Down

0 comments on commit 80fdd80

Please sign in to comment.