Skip to content

Commit f2f04fe

Browse files
authored
fix(module:modal): remove dark backdrop when nzMask is false (#8798)
1 parent 0de6d62 commit f2f04fe

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

components/modal/modal.service.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,11 @@ export class NzModalService implements OnDestroy {
134134
const overlayConfig = new OverlayConfig({
135135
hasBackdrop: true,
136136
scrollStrategy: this.overlay.scrollStrategies.block(),
137+
backdropClass: getValueWithConfig(config.nzMask, globalConfig.nzMask, true) ? MODAL_MASK_CLASS_NAME : '',
137138
positionStrategy: this.overlay.position().global(),
138139
disposeOnNavigation: getValueWithConfig(config.nzCloseOnNavigation, globalConfig.nzCloseOnNavigation, true),
139140
direction: getValueWithConfig(config.nzDirection, globalConfig.nzDirection, this.directionality.value)
140141
});
141-
if (getValueWithConfig(config.nzMask, globalConfig.nzMask, true)) {
142-
overlayConfig.backdropClass = MODAL_MASK_CLASS_NAME;
143-
}
144142

145143
return this.overlay.create(overlayConfig);
146144
}

components/modal/modal.spec.ts

+26
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,32 @@ describe('NzModal', () => {
504504
flush();
505505
}));
506506

507+
it('nzMask work', fakeAsync(() => {
508+
configService.set('modal', { nzMask: false });
509+
510+
const modalRef = modalService.create({
511+
nzContent: TestWithModalContentComponent
512+
});
513+
514+
fixture.detectChanges();
515+
516+
expect(modalRef.getBackdropElement()?.classList)
517+
.not.withContext('not has default cdk dark backdrop')
518+
.toContain('cdk-overlay-dark-backdrop');
519+
520+
configService.set('modal', { nzMask: true });
521+
fixture.detectChanges();
522+
523+
expect(modalRef.getBackdropElement()?.classList).toContain(
524+
'ant-modal-mask',
525+
'should add class when global config changed'
526+
);
527+
528+
modalRef.close();
529+
fixture.detectChanges();
530+
flush();
531+
}));
532+
507533
it(
508534
'should not close when clicking on the modal wrap and ' + 'nzMaskClosable or nzMask is false',
509535
fakeAsync(() => {

0 commit comments

Comments
 (0)