Skip to content

Commit 826a035

Browse files
authored
fix: Drawer zIndex dom element adjust (#290)
* chore: Adjust zIndex style pos * test: Update test case
1 parent 1fa88ec commit 826a035

File tree

4 files changed

+16
-32
lines changed

4 files changed

+16
-32
lines changed

docs/examples/assets/motion.less

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
transform: translateX(0);
5959

6060
&-active {
61-
transform: translateX(-100%);
61+
transform: translateX(-100%)!important;
6262
}
6363
}
6464
}
@@ -79,7 +79,7 @@
7979
transform: translateX(0);
8080

8181
&-active {
82-
transform: translateX(100%);
82+
transform: translateX(100%)!important;
8383
}
8484
}
8585
}

docs/examples/multiple.tsx

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,7 @@ class Demo extends React.Component {
3232
openChildren: !this.state.openChildren,
3333
});
3434
};
35-
public getLevelMove = (e: {
36-
target: HTMLElement;
37-
open: boolean;
38-
}): number | [number, number] => {
39-
const target = e.target as HTMLElement;
40-
if (target.className.indexOf('drawer1') >= 0) {
41-
return [200, 100];
42-
}
43-
return 100;
44-
};
35+
4536
public render() {
4637
return (
4738
<div>
@@ -59,35 +50,31 @@ class Demo extends React.Component {
5950
</div>
6051
<Drawer
6152
width="20vw"
62-
handler={false}
6353
open={this.state.open}
6454
onClose={this.onClick}
6555
className="drawer1"
6656
placement="right"
6757
push={{ distance: 64 }}
58+
// zIndex={99999}
6859
{...motionProps}
6960
>
7061
<div>
7162
<Button onClick={this.onChildClick}>打开子级</Button>
7263
<Drawer
73-
handler={false}
7464
open={this.state.openChild}
7565
onClose={this.onChildClick}
7666
className="drawer2"
77-
level=".drawer1"
7867
placement="right"
68+
// zIndex={88888}
7969
{...motionProps}
8070
>
8171
<div style={{ width: 200 }}>
8272
二级抽屉
83-
<Button onClick={this.onChildrenClick}>打开子级</Button>
73+
<Button onClick={this.onChildrenClick}>打开子子级</Button>
8474
<Drawer
85-
handler={false}
8675
open={this.state.openChildren}
8776
onClose={this.onChildrenClick}
88-
level={['.drawer1', '.drawer2']}
8977
placement="right"
90-
levelMove={this.getLevelMove}
9178
{...motionProps}
9279
>
9380
<div style={{ width: 200 }}>三级抽屉</div>

src/DrawerPopup.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,6 @@ export default function DrawerPopup(props: DrawerPopupProps) {
206206
[],
207207
);
208208

209-
// =========================== zIndex ===========================
210-
const zIndexStyle: React.CSSProperties = {};
211-
if (zIndex) {
212-
zIndexStyle.zIndex = zIndex;
213-
}
214-
215209
// ============================ Mask ============================
216210
const maskNode: React.ReactNode = mask && (
217211
<CSSMotion key="mask" {...maskMotion} visible={open}>
@@ -229,7 +223,6 @@ export default function DrawerPopup(props: DrawerPopupProps) {
229223
style={{
230224
...motionMaskStyle,
231225
...maskStyle,
232-
...zIndexStyle,
233226
}}
234227
onClick={maskClosable ? onClose : undefined}
235228
ref={maskRef}
@@ -294,7 +287,6 @@ export default function DrawerPopup(props: DrawerPopupProps) {
294287
...wrapperStyle,
295288
...motionStyle,
296289
...contentWrapperStyle,
297-
...zIndexStyle,
298290
}}
299291
>
300292
<DrawerPanel
@@ -312,6 +304,14 @@ export default function DrawerPopup(props: DrawerPopupProps) {
312304
);
313305

314306
// =========================== Render ===========================
307+
const containerStyle: React.CSSProperties = {
308+
...rootStyle,
309+
};
310+
311+
if (zIndex) {
312+
containerStyle.zIndex = zIndex;
313+
}
314+
315315
return (
316316
<DrawerContext.Provider value={mergedContext}>
317317
<div
@@ -324,7 +324,7 @@ export default function DrawerPopup(props: DrawerPopupProps) {
324324
[`${prefixCls}-inline`]: inline,
325325
},
326326
)}
327-
style={rootStyle}
327+
style={containerStyle}
328328
tabIndex={-1}
329329
ref={panelRef}
330330
onKeyDown={onPanelKeyDown}

tests/index.spec.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,7 @@ describe('rc-drawer-menu', () => {
305305
<Drawer zIndex={93} open getContainer={false} />,
306306
);
307307

308-
expect(container.querySelector('.rc-drawer-mask')).toHaveStyle({
309-
zIndex: 93,
310-
});
311-
expect(container.querySelector('.rc-drawer-content-wrapper')).toHaveStyle({
308+
expect(container.querySelector('.rc-drawer')).toHaveStyle({
312309
zIndex: 93,
313310
});
314311
});

0 commit comments

Comments
 (0)