Skip to content

Commit

Permalink
fix: Drawer cover other elements when closed
Browse files Browse the repository at this point in the history
close #24287
  • Loading branch information
afc163 committed May 19, 2020
1 parent baa56b6 commit 9555e27
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 39 deletions.
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>
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 9555e27

Please sign in to comment.