mirror of
https://github.com/ant-design/ant-design.git
synced 2024-12-02 15:59:38 +08:00
3a7273b5da
The behaviour of the draggable zone in the modal was incorrect : the header was supposed to be the only draggable zone, but because of an inverted logic of state change, all the modal was draggable
2.2 KiB
2.2 KiB
order | title | ||||
---|---|---|---|---|---|
13 |
|
zh-CN
自定义渲染对话框, 可通过 react-draggable
来实现拖拽。
en-US
Custom modal content render. use react-draggable
implements draggable.
import { Modal, Button } from 'antd';
import Draggable from 'react-draggable';
class App extends React.Component {
state = {
visible: false,
disabled: true,
};
showModal = () => {
this.setState({
visible: true,
});
};
handleOk = e => {
console.log(e);
this.setState({
visible: false,
});
};
handleCancel = e => {
console.log(e);
this.setState({
visible: false,
});
};
render() {
return (
<>
<Button onClick={this.showModal}>
Open Draggable Modal
</Button>
<Modal
title={
<div
style={{
width: '100%',
cursor: 'move',
}}
onMouseOver={() => {
if (this.state.disabled) {
this.setState({
disabled: false,
});
}
}}
onMouseOut={() => {
this.setState({
disabled: true,
});
}}
// fix eslintjsx-a11y/mouse-events-have-key-events
// https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/mouse-events-have-key-events.md
onFocus={() => {}}
onBlur={() => {}}
// end
>
Draggable Modal
</div>
}
visible={this.state.visible}
onOk={this.handleOk}
onCancel={this.handleCancel}
modalRender={modal => <Draggable disabled={this.state.disabled}>{modal}</Draggable>}
>
<p>
Just don't learn physics at school and your life will be full of magic and
miracles.
</p>
<br />
<p>Day before yesterday I saw a rabbit, and yesterday a deer, and today, you.</p>
</Modal>
</>
);
}
}
ReactDOM.render(<App />, mountNode);