Skip to content

Commit b932d65

Browse files
fix(module:cdk): zIndex is not used properly when creating overlay (#8373)
* fix(module:cdk): zIndex is not used properly when creating overlay * fix(module:cdk): zIndex is not used properly when creating overlay
1 parent 6e1decb commit b932d65

5 files changed

Lines changed: 31 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Use of this source code is governed by an MIT-style license that can be
3+
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
4+
*/
5+
6+
import { OverlayRef } from '@angular/cdk/overlay';
7+
8+
export function overlayZIndexSetter(overlayRef: OverlayRef, zIndex?: number): void {
9+
if (!zIndex) return;
10+
11+
(overlayRef['_host'] as HTMLElement).style.zIndex = `${zIndex}`;
12+
}

components/core/overlay/public-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@
66
export * from './nz-connected-overlay';
77
export * from './nz-overlay.module';
88
export * from './overlay-position';
9+
export * from './overlay-z-index';

components/drawer/drawer.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import { takeUntil } from 'rxjs/operators';
3838
import { NzConfigKey, NzConfigService, WithConfig } from 'ng-zorro-antd/core/config';
3939
import { NzNoAnimationDirective } from 'ng-zorro-antd/core/no-animation';
4040
import { NzOutletModule } from 'ng-zorro-antd/core/outlet';
41+
import { overlayZIndexSetter } from 'ng-zorro-antd/core/overlay';
4142
import { BooleanInput, NgStyleInterface, NzSafeAny } from 'ng-zorro-antd/core/types';
4243
import { InputBoolean, isTemplateRef, toCssPixel } from 'ng-zorro-antd/core/util';
4344
import { NzIconModule } from 'ng-zorro-antd/icon';
@@ -456,6 +457,8 @@ export class NzDrawerComponent<T extends {} = NzSafeAny, R = NzSafeAny, D extend
456457
if (!this.overlayRef) {
457458
this.portal = new TemplatePortal(this.drawerTemplate, this.viewContainerRef);
458459
this.overlayRef = this.overlay.create(this.getOverlayConfig());
460+
461+
overlayZIndexSetter(this.overlayRef, this.nzZIndex);
459462
}
460463

461464
if (this.overlayRef && !this.overlayRef.hasAttached()) {

components/modal/modal.service.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { startWith } from 'rxjs/operators';
1212

1313
import { NzConfigService } from 'ng-zorro-antd/core/config';
1414
import { warn } from 'ng-zorro-antd/core/logger';
15+
import { overlayZIndexSetter } from 'ng-zorro-antd/core/overlay';
1516
import { IndexableObject, NzSafeAny } from 'ng-zorro-antd/core/types';
1617
import { isNotNil } from 'ng-zorro-antd/core/util';
1718

@@ -98,6 +99,8 @@ export class NzModalService implements OnDestroy {
9899
const modalRef = this.attachModalContent<T, D, R>(componentOrTemplateRef, modalContainer, overlayRef, configMerged);
99100
modalContainer.modalRef = modalRef;
100101

102+
overlayZIndexSetter(overlayRef, config?.nzZIndex);
103+
101104
this.openModals.push(modalRef);
102105
modalRef.afterClose.subscribe(() => this.removeOpenModal(modalRef));
103106

components/modal/modal.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ describe('NzModal', () => {
138138
modalRef.close();
139139
});
140140

141+
it('should give correct z-index value to overlay', fakeAsync(() => {
142+
const Z_INDEX = 9999;
143+
modalService.create({
144+
nzContent: TestWithModalContentComponent,
145+
nzData: 'Modal',
146+
nzZIndex: Z_INDEX
147+
});
148+
149+
const overlay = document.querySelector('.cdk-global-overlay-wrapper');
150+
expect((overlay as HTMLElement).style.zIndex).toEqual(`${Z_INDEX}`);
151+
}));
152+
141153
it('should open a modal with data', () => {
142154
const modalRef = modalService.create({
143155
nzContent: TestWithModalContentComponent,

0 commit comments

Comments
 (0)