Skip to content

Instantly share code, notes, and snippets.

@hungqcao
Forked from burgalon/DraggableModal.js
Created May 10, 2019 17:12
Show Gist options
  • Save hungqcao/571fa6dfe0522847b182a228e4d852af to your computer and use it in GitHub Desktop.
Save hungqcao/571fa6dfe0522847b182a228e4d852af to your computer and use it in GitHub Desktop.
Draggable React Bootstrap modal
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>
);
}
}
@ameyasd007
Copy link

ameyasd007 commented Feb 9, 2021

Thanks. This worked for me.

dialogAs={DraggableModalDialog} is important.

@Pamwamba
Copy link

Pamwamba commented Aug 3, 2023

Hi, I just tried your code and this worked. Do you know what can I do to move the modal on dragging ? Currently, the modal is moving when I stop dragging.

Edit: Nevermind I just had to set the transition duration to 0s. Hope this will help someone
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment