Skip to content
Merged
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
3 changes: 3 additions & 0 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ <h1>React Draggable</h1>
<Draggable axis="y" {...dragHandlers}>
<div className="box cursor-y">I can only be dragged vertically</div>
</Draggable>
<Draggable onStart={() => false}>
<div className="box">I don't want to be dragged</div>
</Draggable>
<Draggable onDrag={this.handleDrag} {...dragHandlers}>
<div className="box">
<div>I track my deltas</div>
Expand Down
7 changes: 3 additions & 4 deletions lib/DraggableCore.es6
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,6 @@ export default class DraggableCore extends React.Component {
this.setState({touchIdentifier: e.targetTouches[0].identifier});
}

// 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();

// Get the current drag point from the event. This is used as the offset.
const {x, y} = getControlPosition(e, this);

Expand All @@ -216,6 +212,9 @@ export default class DraggableCore extends React.Component {
const shouldUpdate = this.props.onStart(e, coreEvent);
if (shouldUpdate === 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();

// Initiate dragging. Set the current x and y as offsets
// so we know how much we've moved during the drag. This allows us
Expand Down
18 changes: 18 additions & 0 deletions specs/draggable.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,24 @@ describe('react-draggable', function () {
TestUtils.Simulate.mouseUp(node);
expect(document.body.getAttribute('style')).toEqual('');
});

it('should not add and remove user-select styles when onStart returns false', function () {
function onStart() { return false; }

drag = TestUtils.renderIntoDocument(
<Draggable onStart={onStart}>
<div />
</Draggable>
);

var node = ReactDOM.findDOMNode(drag);

expect(document.body.getAttribute('style')).toEqual('');
TestUtils.Simulate.mouseDown(node, {clientX: 0, clientY: 0});
expect(document.body.getAttribute('style')).toEqual('');
TestUtils.Simulate.mouseUp(node);
expect(document.body.getAttribute('style')).toEqual('');
});
});

describe('interaction', function () {
Expand Down