react-set modal draggable with react-draggalble

问题描述 投票:1回答:1

我正在尝试添加具有拖放功能的antd模式。

import React, { Component } from "react";
import Draggable from "react-draggable";
import { Modal } from 'antd';
import 'antd/dist/antd.css';
export default class App extends Component {
  state = {
    disabled: false
  };

  render = () => {
    const { disabled } = this.state;
    return (
      <div className="container">
          <Modal visible>
          <Draggable>
          <div>
            <h4 style={{ height: 20, userSelect: "none" }}>
              {"Drag Me"}
            </h4>
            <textarea disabled={!disabled} className="uk-textarea" />

            <br />
            </div>
        </Draggable>
          </Modal>
      </div>
    );
  };
}

这是我的Sanbox代码https://codesandbox.io/s/small-currying-j3emq,但似乎ant modal元素中的react-draggable不起作用,可能是我可以将元素“ ant-modal-content”]]设置为可拖动元素有效。

有人知道是否有可能通过道具将可拖动元素放置在react-draggable中吗?

我也可以更改软件包以进行拖放,我只需要能够拖动一个蚂蚁模态

enter image description here

我正在尝试添加具有拖放功能的antd模态。从“反应”中导入React,{组件};从“ react-draggable”导入Draggable;从“ antd”导入{Modal};导入'antd / dist / antd.css'...

reactjs drag-and-drop modal-dialog antd
1个回答
0
投票

只需将<Draggable>放在<Modal>内,而不是相反的位置>>

    return (
      <div className="container">
        <Modal visible>
          <Draggable>
            <div>
              <h4 style={{ height: 20, userSelect: "none" }}>{"Drag Me"}</h4>
              <textarea disabled={!disabled} className="uk-textarea" />

              <br />
            </div>
          </Draggable>
        </Modal>
      </div>
    );
© www.soinside.com 2019 - 2024. All rights reserved.