Skip to content

Commit

Permalink
fix: Drawer cover other elements when closed (#24290)
Browse files Browse the repository at this point in the history
* fix: Drawer cover other elements when closed

close #24287

* Add no-mask demo for Drawer
  • Loading branch information
afc163 committed May 19, 2020
1 parent 4feb186 commit 6ad1b18
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 43 deletions.
11 changes: 11 additions & 0 deletions components/drawer/__tests__/__snapshots__/demo.test.js.snap
Expand Up @@ -57,6 +57,17 @@ exports[`renders ./components/drawer/demo/multi-level-drawer.md correctly 1`] =
</button>
`;

exports[`renders ./components/drawer/demo/no-mask.md correctly 1`] = `
<button
class="ant-btn ant-btn-primary"
type="button"
>
<span>
Open
</span>
</button>
`;

exports[`renders ./components/drawer/demo/placement.md correctly 1`] = `
<div
class="ant-space ant-space-horizontal ant-space-align-center"
Expand Down
68 changes: 30 additions & 38 deletions components/drawer/demo/basic-right.md
Expand Up @@ -13,51 +13,43 @@ title:

Basic drawer.

```jsx
```tsx
import React, { useState } from 'react';
import { Drawer, Button } from 'antd';

class App extends React.Component {
state = { visible: false };

showDrawer = () => {
this.setState({
visible: true,
});
const App: React.FC = () => {
const [visible, setVisible] = useState(false);
const showDrawer = () => {
setVisible(true);
};

onClose = () => {
this.setState({
visible: false,
});
const onClose = () => {
setVisible(false);
};

render() {
return (
<>
<Button type="primary" onClick={this.showDrawer}>
Open
</Button>
<Drawer
title="Basic Drawer"
placement="right"
closable={false}
onClose={this.onClose}
visible={this.state.visible}
>
<p>Some contents...</p>
<p>Some contents...</p>
<p>Some contents...</p>
</Drawer>
</>
);
}
}
return (
<>
<Button type="primary" onClick={showDrawer}>
Open
</Button>
<Drawer
title="Basic Drawer"
placement="right"
closable={false}
onClose={onClose}
visible={visible}
>
<p>Some contents...</p>
<p>Some contents...</p>
<p>Some contents...</p>
</Drawer>
</>
);
};

ReactDOM.render(<App />, mountNode);
```

```css
<style>
[data-theme='compact'] .ant-drawer-body p {
margin-bottom: 0px;
margin-bottom: 0;
}
```
</style>
50 changes: 50 additions & 0 deletions components/drawer/demo/no-mask.md
@@ -0,0 +1,50 @@
---
order: 99
title:
zh-CN: 无遮罩
en-US: No mask
debug: true
---

## zh-CN

通过 `mask={false}` 去掉遮罩。

## en-US

Remove mask.

```tsx
import React, { useState } from 'react';
import { Drawer, Button } from 'antd';

const App: React.FC = () => {
const [visible, setVisible] = useState(false);
const showDrawer = () => {
setVisible(true);
};
const onClose = () => {
setVisible(false);
};
return (
<>
<Button type="primary" onClick={showDrawer}>
Open
</Button>
<Drawer
title="Drawer without mask"
placement="right"
mask={false}
onClose={onClose}
visible={visible}
>
<p>Some contents...</p>
<p>Some contents...</p>
<p>Some contents...</p>
</Drawer>
</>
);
};

ReactDOM.render(<App />, mountNode);
```
6 changes: 2 additions & 4 deletions components/drawer/demo/placement.md
Expand Up @@ -16,8 +16,6 @@ The Drawer can appear from any edge of the screen.
```jsx
import { Drawer, Button, Radio, Space } from 'antd';

const RadioGroup = Radio.Group;

class App extends React.Component {
state = { visible: false, placement: 'left' };

Expand All @@ -44,12 +42,12 @@ class App extends React.Component {
return (
<>
<Space>
<RadioGroup defaultValue={placement} onChange={this.onChange}>
<Radio.Group defaultValue={placement} onChange={this.onChange}>
<Radio value="top">top</Radio>
<Radio value="right">right</Radio>
<Radio value="bottom">bottom</Radio>
<Radio value="left">left</Radio>
</RadioGroup>
</Radio.Group>
<Button type="primary" onClick={this.showDrawer}>
Open
</Button>
Expand Down
6 changes: 5 additions & 1 deletion components/drawer/index.tsx
Expand Up @@ -137,7 +137,11 @@ class Drawer extends React.Component<DrawerProps & ConfigConsumerProps, IDrawerS
};

getOffsetStyle() {
const { placement, width, height } = this.props;
const { placement, width, height, visible, mask } = this.props;
// https://github.com/ant-design/ant-design/issues/24287
if (!visible && !mask) {
return {};
}
const offsetStyle: any = {};
if (placement === 'left' || placement === 'right') {
offsetStyle.width = width;
Expand Down

0 comments on commit 6ad1b18

Please sign in to comment.