Skip to content

Commit b1d2095

Browse files
fix(module:message): fix the z-index of overlay (#8081)
1 parent 0f3aed5 commit b1d2095

5 files changed

Lines changed: 23 additions & 72 deletions

File tree

‎components/message/base.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ export abstract class NzMNService {
5454
});
5555
const componentPortal = new ComponentPortal(ctor, null, this.injector);
5656
const componentRef = overlayRef.attach(componentPortal);
57-
const overlayPane = overlayRef.overlayElement;
58-
overlayPane.style.zIndex = '1010';
57+
const overlayWrapper = overlayRef.hostElement;
58+
overlayWrapper.style.zIndex = '1010';
5959

6060
if (!containerInstance) {
6161
this.container = containerInstance = componentRef.instance;

‎components/message/message.spec.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Component, TemplateRef, ViewChild } from '@angular/core';
33
import { ComponentFixture, fakeAsync, inject, tick } from '@angular/core/testing';
44
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
55

6-
import { NzConfigService, NZ_CONFIG } from 'ng-zorro-antd/core/config';
6+
import { NZ_CONFIG, NzConfigService } from 'ng-zorro-antd/core/config';
77
import { dispatchMouseEvent } from 'ng-zorro-antd/core/testing';
88
import { ComponentBed, createComponentBed } from 'ng-zorro-antd/core/testing/component-bed';
99

@@ -57,7 +57,9 @@ describe('message', () => {
5757
fixture.detectChanges();
5858
overlayContainerElement = overlayContainer.getContainerElement();
5959

60-
expect((overlayContainerElement.querySelector('.cdk-overlay-pane') as HTMLElement).style.zIndex).toBe('1010');
60+
expect((overlayContainerElement.querySelector('.cdk-global-overlay-wrapper') as HTMLElement).style.zIndex).toBe(
61+
'1010'
62+
);
6163
expect(overlayContainerElement.textContent).toContain('SUCCESS');
6264
expect(overlayContainerElement.querySelector('.anticon-check-circle')).not.toBeNull();
6365
});

‎components/style/patch.less‎

Lines changed: 9 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
@import './themes/@{root-entry-name}.less';
2-
3-
// cdk overlay
4-
.cdk-overlay-container {
5-
pointer-events: none;
6-
top: 0;
7-
left: 0;
8-
height: 100%;
9-
width: 100%;
10-
position: fixed;
11-
z-index: 1000;
12-
}
2+
@import '~@angular/cdk/overlay-prebuilt.css';
133

144
.cdk-visually-hidden {
155
border: 0;
@@ -25,66 +15,16 @@
2515
-moz-appearance: none;
2616
}
2717

28-
.cdk-overlay-backdrop {
29-
top: 0;
30-
bottom: 0;
31-
left: 0;
32-
right: 0;
33-
-webkit-tap-highlight-color: transparent;
34-
transition: opacity 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
35-
opacity: 0;
36-
position: absolute;
37-
pointer-events: auto;
38-
z-index: 1000;
39-
40-
&.ant-modal-mask {
41-
opacity: 1;
42-
}
43-
}
44-
45-
.cdk-overlay-pane {
46-
position: absolute;
47-
pointer-events: auto;
48-
z-index: 1000; // Give an opportunity to the content own to manage their z-index such as Modal
49-
}
50-
51-
.cdk-overlay-connected-position-bounding-box {
52-
position: absolute;
53-
z-index: 1000;
54-
display: flex;
55-
flex-direction: column;
56-
min-width: 1px;
57-
min-height: 1px;
58-
}
59-
60-
// Used when disabling global scrolling.
61-
.cdk-global-scrollblock {
62-
position: fixed;
63-
64-
// Necessary for the content not to lose its width. Note that we're using 100%, instead of
65-
// 100vw, because 100vw includes the width plus the scrollbar, whereas 100% is the width
66-
// that the element had before we made it `fixed`.
67-
width: 100%;
68-
69-
// Note: this will always add a scrollbar to whatever element it is on, which can
70-
// potentially result in double scrollbars. It shouldn't be an issue, because we won't
71-
// block scrolling on a page that doesn't have a scrollbar in the first place.
72-
overflow-y: scroll;
73-
74-
// https://github.com/angular/material2/issues/15051
75-
body {
76-
overflow-x: visible;
77-
}
78-
}
79-
8018
.nz-overlay-transparent-backdrop {
19+
8120
&,
8221
&.cdk-overlay-backdrop-showing {
8322
opacity: 0;
8423
}
8524
}
8625

8726
.nz-animate-disabled {
27+
8828
// badge
8929
&.ant-scroll-number-only {
9030
animation: none;
@@ -98,7 +38,7 @@
9838
transition: none;
9939
}
10040

101-
& > * {
41+
&>* {
10242
transition: none;
10343
}
10444
}
@@ -131,18 +71,19 @@
13171
.ant-menu-submenu-title .anticon {
13272
transition: none;
13373

134-
& + span {
74+
&+span {
13575
transition: none;
13676
}
13777
}
13878
}
13979

14080
// tabs
14181
&.ant-tabs {
82+
14283
.ant-tabs-top-content.ant-tabs-content-animated,
14384
.ant-tabs-bottom-content.ant-tabs-content-animated,
144-
.ant-tabs-top-content > .ant-tabs-tabpane,
145-
.ant-tabs-bottom-content > .ant-tabs-tabpane,
85+
.ant-tabs-top-content>.ant-tabs-tabpane,
86+
.ant-tabs-bottom-content>.ant-tabs-tabpane,
14687
&.ant-tabs-left .ant-tabs-ink-bar-animated,
14788
&.ant-tabs-right .ant-tabs-ink-bar-animated,
14889
&.ant-tabs-top .ant-tabs-ink-bar-animated,
@@ -152,7 +93,7 @@
15293
}
15394

15495
// collapse
155-
&.ant-collapse > .ant-collapse-item > .ant-collapse-header .ant-collapse-arrow svg {
96+
&.ant-collapse>.ant-collapse-item>.ant-collapse-header .ant-collapse-arrow svg {
15697
transition: none;
15798
}
15899
}

‎docs/getting-started.en-US.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ Then use the component inside the template:
157157
<button nz-button nzType="primary">Primary</button>
158158
```
159159

160+
# Precautions
161+
162+
- `ng-zorro-antd` already contains `@angular/cdk/overlay-prebuilt.css` overlay style, no additional import is required.
163+
160164
## Other
161165

162166
- [I18n](/docs/i18n/en)

‎docs/getting-started.zh-CN.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ export class AppModule { }
153153
<button nz-button nzType="primary">Primary</button>
154154
```
155155

156+
# 注意事项
157+
158+
- `ng-zorro-antd` 已经包含了 `@angular/cdk/overlay-prebuilt.css` 浮层样式,无需额外导入。
159+
156160
## 其他
157161

158162
- [国际化配置](/docs/i18n/zh)

0 commit comments

Comments
 (0)