Created
March 31, 2016 06:18
-
-
Save burgalon/870a68de68c5ed15c416fab63589d503 to your computer and use it in GitHub Desktop.
Draggable React Bootstrap modal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Modal } from 'react-bootstrap' | |
import ModalDialog from 'react-bootstrap/lib/ModalDialog' | |
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> |
For anyone that can't get it work, try change 'dialogComponent' to 'dialogComponentClass'
If you have error:
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.
Solution may be changing imports. The correct import of ModalDialog looks like this:
import * as ModalDialog from 'react-bootstrap/lib/ModalDialog';
If you have trouble with the newer version of react-bootstrap. Try my updated gist here https://gist.github.com/hungqcao/571fa6dfe0522847b182a228e4d852af
Use 'dialogAs' as opposed o 'dialogComponent' as of the v1.0.0 beta
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Should be imported from react-draggable: