diff --git a/src/lib/extended/show-hide/show-hide.ts b/src/lib/extended/show-hide/show-hide.ts index 49fc808b7..19064c69e 100644 --- a/src/lib/extended/show-hide/show-hide.ts +++ b/src/lib/extended/show-hide/show-hide.ts @@ -30,13 +30,14 @@ import {takeUntil} from 'rxjs/operators'; export interface ShowHideParent { display: string; + isServer: boolean; } @Injectable({providedIn: 'root'}) export class ShowHideStyleBuilder extends StyleBuilder { buildStyles(show: string, parent: ShowHideParent) { const shouldShow = show === 'true'; - return {'display': shouldShow ? parent.display : 'none'}; + return {'display': shouldShow ? parent.display || (parent.isServer ? 'initial' : '') : 'none'}; } } @@ -44,7 +45,7 @@ export class ShowHideStyleBuilder extends StyleBuilder { export class ShowHideDirective extends BaseDirective2 implements AfterViewInit, OnChanges { protected DIRECTIVE_KEY = 'show-hide'; - /** Original dom Elements CSS display style */ + /** Original DOM Element CSS display style */ protected display: string = ''; protected hasLayout = false; protected hasFlexChild = false; @@ -146,8 +147,9 @@ export class ShowHideDirective extends BaseDirective2 implements AfterViewInit, if (value === '') { return; } - this.addStyles(value ? 'true' : 'false', {display: this.display}); - if (isPlatformServer(this.platformId) && this.serverModuleLoaded) { + const isServer = isPlatformServer(this.platformId); + this.addStyles(value ? 'true' : 'false', {display: this.display, isServer}); + if (isServer && this.serverModuleLoaded) { this.nativeElement.style.setProperty('display', ''); } this.marshal.triggerUpdate(this.parentElement!, 'layout-gap'); diff --git a/src/lib/extended/show-hide/show.spec.ts b/src/lib/extended/show-hide/show.spec.ts index ddddd3352..20c93fb58 100644 --- a/src/lib/extended/show-hide/show.spec.ts +++ b/src/lib/extended/show-hide/show.spec.ts @@ -299,8 +299,8 @@ describe('show directive', () => { 'display': 'inline' }, styler); } else { - expectEl(queryFor(fixture, elSelector)[0]).not.toHaveStyle({ - 'display': '*' + expectEl(queryFor(fixture, elSelector)[0]).toHaveStyle({ + 'display': 'initial' }, styler); } @@ -318,8 +318,8 @@ describe('show directive', () => { 'display': 'inline' }, styler); } else { - expectEl(queryFor(fixture, elSelector)[0]).not.toHaveStyle({ - 'display': '*' + expectEl(queryFor(fixture, elSelector)[0]).toHaveStyle({ + 'display': 'initial' }, styler); } });