Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/DraggableCore.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,10 +297,6 @@ export default class DraggableCore extends React.Component<DraggableCoreProps, D
const shouldUpdate = this.props.onStart(e, coreEvent);
if (shouldUpdate === false || this.mounted === false) return;

// Add a style to the body to disable user-select. This prevents text from
// being selected all over the page.
if (this.props.enableUserSelectHack) addUserSelectStyles(ownerDocument);

// Initiate dragging. Set the current x and y as offsets
// so we know how much we've moved during the drag. This allows us
// to drag elements around even if they have been moved, without issue.
Expand Down Expand Up @@ -354,6 +350,13 @@ export default class DraggableCore extends React.Component<DraggableCoreProps, D
return;
}

const thisNode = ReactDOM.findDOMNode(this);
if (thisNode) {
// Add a style to the body to disable user-select. This prevents text from
// being selected all over the page.
if (this.props.enableUserSelectHack) addUserSelectStyles(thisNode.ownerDocument);
}

this.setState({
lastX: x,
lastY: y
Expand Down
31 changes: 18 additions & 13 deletions specs/draggable.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -357,20 +357,22 @@ describe('react-draggable', function () {
});

it('should add and remove transparent selection class', function () {
drag = TestUtils.renderIntoDocument(
<Draggable>
<div />
</Draggable>
);

const node = ReactDOM.findDOMNode(drag);
drag = TestUtils.renderIntoDocument(
<Draggable>
<div />
</Draggable>
);

assert(!document.body.classList.contains('react-draggable-transparent-selection'));
TestUtils.Simulate.mouseDown(node, {clientX: 0, clientY: 0});
assert(document.body.classList.contains('react-draggable-transparent-selection'));
TestUtils.Simulate.mouseUp(node);
assert(!document.body.classList.contains('react-draggable-transparent-selection'));
});
const node = ReactDOM.findDOMNode(drag);

assert(!document.body.classList.contains('react-draggable-transparent-selection'));
TestUtils.Simulate.mouseDown(node, {clientX: 0, clientY: 0});
assert(!document.body.classList.contains('react-draggable-transparent-selection'));
mouseMove(100, 100, node);
assert(document.body.classList.contains('react-draggable-transparent-selection'));
TestUtils.Simulate.mouseUp(node);
assert(!document.body.classList.contains('react-draggable-transparent-selection'));
});

it('should not add and remove transparent selection class when disabled', function () {

Expand Down Expand Up @@ -493,6 +495,9 @@ describe('react-draggable', function () {
assert(!iframeDoc.body.classList.contains('react-draggable-transparent-selection'));
TestUtils.Simulate.mouseDown(node, {clientX: 0, clientY: 0});
assert(!document.body.classList.contains('react-draggable-transparent-selection'));
assert(!iframeDoc.body.classList.contains('react-draggable-transparent-selection'));
mouseMove(100, 100, node);
assert(!document.body.classList.contains('react-draggable-transparent-selection'));
assert(iframeDoc.body.classList.contains('react-draggable-transparent-selection'));
TestUtils.Simulate.mouseUp(node);
assert(!document.body.classList.contains('react-draggable-transparent-selection'));
Expand Down