Skip to content

Instantly share code, notes, and snippets.

@burgalon
Created March 31, 2016 06:18
Show Gist options
  • Save burgalon/870a68de68c5ed15c416fab63589d503 to your computer and use it in GitHub Desktop.
Save burgalon/870a68de68c5ed15c416fab63589d503 to your computer and use it in GitHub Desktop.
Draggable React Bootstrap modal
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>
@adamtal3
Copy link

adamtal3 commented Aug 8, 2016

Is Draggable not imported from somewhere?

Should be imported from react-draggable:

import Draggable from 'react-draggable';

@katexue-cm
Copy link

For anyone that can't get it work, try change 'dialogComponent' to 'dialogComponentClass'

@tischsoic
Copy link

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';

@hungqcao
Copy link

If you have trouble with the newer version of react-bootstrap. Try my updated gist here https://gist.github.com/hungqcao/571fa6dfe0522847b182a228e4d852af

@willbee28
Copy link

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