Skip to content

Commit

Permalink
fix(module:cdk): zIndex is not used properly when creating overlay (#…
Browse files Browse the repository at this point in the history
…8373)

* fix(module:cdk): zIndex is not used properly when creating overlay

* fix(module:cdk): zIndex is not used properly when creating overlay
  • Loading branch information
ParsaArvanehPA committed Mar 11, 2024
1 parent 6e1decb commit b932d65
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
12 changes: 12 additions & 0 deletions components/core/overlay/overlay-z-index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/

import { OverlayRef } from '@angular/cdk/overlay';

export function overlayZIndexSetter(overlayRef: OverlayRef, zIndex?: number): void {
if (!zIndex) return;

(overlayRef['_host'] as HTMLElement).style.zIndex = `${zIndex}`;
}
1 change: 1 addition & 0 deletions components/core/overlay/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
export * from './nz-connected-overlay';
export * from './nz-overlay.module';
export * from './overlay-position';
export * from './overlay-z-index';
3 changes: 3 additions & 0 deletions components/drawer/drawer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { takeUntil } from 'rxjs/operators';
import { NzConfigKey, NzConfigService, WithConfig } from 'ng-zorro-antd/core/config';
import { NzNoAnimationDirective } from 'ng-zorro-antd/core/no-animation';
import { NzOutletModule } from 'ng-zorro-antd/core/outlet';
import { overlayZIndexSetter } from 'ng-zorro-antd/core/overlay';
import { BooleanInput, NgStyleInterface, NzSafeAny } from 'ng-zorro-antd/core/types';
import { InputBoolean, isTemplateRef, toCssPixel } from 'ng-zorro-antd/core/util';
import { NzIconModule } from 'ng-zorro-antd/icon';
Expand Down Expand Up @@ -456,6 +457,8 @@ export class NzDrawerComponent<T extends {} = NzSafeAny, R = NzSafeAny, D extend
if (!this.overlayRef) {
this.portal = new TemplatePortal(this.drawerTemplate, this.viewContainerRef);
this.overlayRef = this.overlay.create(this.getOverlayConfig());

overlayZIndexSetter(this.overlayRef, this.nzZIndex);
}

if (this.overlayRef && !this.overlayRef.hasAttached()) {
Expand Down
3 changes: 3 additions & 0 deletions components/modal/modal.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { startWith } from 'rxjs/operators';

import { NzConfigService } from 'ng-zorro-antd/core/config';
import { warn } from 'ng-zorro-antd/core/logger';
import { overlayZIndexSetter } from 'ng-zorro-antd/core/overlay';
import { IndexableObject, NzSafeAny } from 'ng-zorro-antd/core/types';
import { isNotNil } from 'ng-zorro-antd/core/util';

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

overlayZIndexSetter(overlayRef, config?.nzZIndex);

this.openModals.push(modalRef);
modalRef.afterClose.subscribe(() => this.removeOpenModal(modalRef));

Expand Down
12 changes: 12 additions & 0 deletions components/modal/modal.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,18 @@ describe('NzModal', () => {
modalRef.close();
});

it('should give correct z-index value to overlay', fakeAsync(() => {
const Z_INDEX = 9999;
modalService.create({
nzContent: TestWithModalContentComponent,
nzData: 'Modal',
nzZIndex: Z_INDEX
});

const overlay = document.querySelector('.cdk-global-overlay-wrapper');
expect((overlay as HTMLElement).style.zIndex).toEqual(`${Z_INDEX}`);
}));

it('should open a modal with data', () => {
const modalRef = modalService.create({
nzContent: TestWithModalContentComponent,
Expand Down

0 comments on commit b932d65

Please sign in to comment.