Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Modal width out of screen #25765

Merged
merged 8 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions components/modal/__tests__/__snapshots__/demo.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -305,3 +305,14 @@ Array [
</button>,
]
`;

exports[`renders ./components/modal/demo/width.md correctly 1`] = `
<button
class="ant-btn ant-btn-primary"
type="button"
>
<span>
Vertically centered modal dialog
</span>
</button>
`;
52 changes: 52 additions & 0 deletions components/modal/demo/width.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
order: 13
title:
zh-CN: 自定义模态的宽度
en-US: To customize the width of modal
---

## zh-CN

使用 `width` 来设置模态对话框的宽度。

## en-US

Use `width` to set the width of the modal dialog.

```jsx
import { Modal, Button } from 'antd';

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

setmodalVisible(modalVisible) {
this.setState({ modalVisible });
}

render() {
return (
<>
<Button type="primary" onClick={() => this.setmodalVisible(true)}>
Vertically centered modal dialog
</Button>
<Modal
title="Vertically centered modal dialog"
centered
visible={this.state.modalVisible}
onOk={() => this.setmodalVisible(false)}
onCancel={() => this.setmodalVisible(false)}
width={1000}
>
<p>some contents...</p>
<p>some contents...</p>
<p>some contents...</p>
</Modal>
</>
);
}
}

ReactDOM.render(<App />, mountNode);
```
8 changes: 5 additions & 3 deletions components/modal/style/modal.less
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
margin: 0 auto;
padding-bottom: 24px;
pointer-events: none;
max-width: calc(100vw - 16px);

&-wrap {
position: fixed;
Expand Down Expand Up @@ -81,7 +82,8 @@
padding: @modal-header-padding;
color: @text-color;
background: @modal-header-bg;
border-bottom: @modal-header-border-width @modal-header-border-style @modal-header-border-color-split;
border-bottom: @modal-header-border-width @modal-header-border-style
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep original style

@modal-header-border-color-split;
border-radius: @border-radius-base @border-radius-base 0 0;
}

Expand All @@ -96,7 +98,8 @@
padding: @modal-footer-padding-vertical @modal-footer-padding-horizontal;
text-align: right;
background: @modal-footer-bg;
border-top: @modal-footer-border-width @modal-footer-border-style @modal-footer-border-color-split;
border-top: @modal-footer-border-width @modal-footer-border-style
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep original style

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be formatted by prettier.

@modal-footer-border-color-split;
border-radius: 0 0 @border-radius-base @border-radius-base;

button + button {
Expand Down Expand Up @@ -153,7 +156,6 @@

@media (max-width: @screen-sm-max) {
.@{dialog-prefix-cls} {
max-width: calc(100vw - 16px);
margin: 8px auto;
}
.@{dialog-prefix-cls}-centered {
Expand Down