如何使反应引导模式可拖动

6 draggable bootstrap-modal reactjs react-bootstrap

我试过让它起作用,但这就是发生的事情。

  1. 使用 react-draggable npm 包,我能够使内容可拖放。但是整个对话的背面保持原位,之后看起来已经损坏了。

我也在网上找到了这个 https://gist.github.com/burgalon/870a68de68c5ed15c416fab63589d503

import { Modal } from 'react-bootstrap'
import ModalDialog from 'react-bootstrap/lib/ModalDialog'
import Draggable from 'react-draggable'

class DraggableModalDialog extends React.Component {
    render() {
        return <Draggable handle=".modal-title"><ModalDialog 
{...this.props} /></Draggable>
    }
}

// enforceForce=false causes recursion exception otherwise....
export default ({titleIconClass, modalClass, children, title,...props}) =>
<Modal dialogComponent={DraggableModalDialog} show={true} enforceFocus={false} backdrop="static" {...props}>
    <Modal.Header closeButton>
        <Modal.Title>
            {title}
        </Modal.Title>
    </Modal.Header>
    <Modal.Body>
        {children}
    </Modal.Body>
</Modal>
Run Code Online (Sandbox Code Playgroud)

我从搜索中得到的这段代码,我实际上无法让它工作。


尤其是这个,

<ModalDialog {...this.props} />
Run Code Online (Sandbox Code Playgroud)

,我不明白为什么要送道具,送什么样的道具。

<Modal dialogComponent={DraggableModalDialog} show={true} enforceFocus={false} backdrop="static" {...props}>
Run Code Online (Sandbox Code Playgroud)

<------ {...props} 有什么作用?它似乎没有为 Modal 提供道具。它的目的是什么?是否与

"<ModalDialog {...this.props} />"
Run Code Online (Sandbox Code Playgroud)

?

如果这是一项有效的工作,任何人都可以给我提示上述两个问题如何工作?

谢谢!

Hun*_*Cao 5

对于任何可能仍在为最新版本react-bootstrap(我的是1.0.0-beta.5在写作时)而苦苦挣扎的人。这是(https://gist.github.com/burgalon/870a68de68c5ed15c416fab63589d503)的修改版本

import React, { Component } from "react";
import Modal from "react-bootstrap/Modal";
import Draggable from 'react-draggable';
import ModalDialog from 'react-bootstrap/ModalDialog';

class DraggableModalDialog extends React.Component {
    render() {
        return <Draggable handle=".modal-title"><ModalDialog {...this.props} /> 
   </Draggable>
    }
}

export default class BSModal extends Component {

render() {
    return (
        <Modal
                dialogAs={DraggableModalDialog} 
                show={this.props.show} 
                onHide={this.props.close}>
            <Modal.Header>
                <Modal.Title>{this.props.title}</Modal.Title>
            </Modal.Header>
            <Modal.Body>
                {this.props.children}
            </Modal.Body>
            <Modal.Footer >
            </Modal.Footer>
        </Modal>
    );
}
}
Run Code Online (Sandbox Code Playgroud)