Skip to content

Commit 9886cec

Browse files
committed
Don't add user-select styles when enableUserSelectHack is false
1 parent d7b9021 commit 9886cec

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

lib/DraggableCore.es6

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ export default class DraggableCore extends React.Component {
241241

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

246246
// Get the current drag point from the event. This is used as the offset.
247247
let {clientX, clientY} = getControlPosition(e);

specs/draggable.spec.jsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,25 @@ describe('react-draggable', function () {
253253
TestUtils.Simulate.mouseUp(node);
254254
expect(document.body.getAttribute('style')).toEqual('');
255255
});
256+
257+
it('should not add and remove user-select styles when disabled', function () {
258+
// Karma runs in firefox in our tests
259+
var userSelectStyle = ';user-select: none;' + dashedBrowserPrefix + 'user-select: none;';
260+
261+
drag = TestUtils.renderIntoDocument(
262+
<Draggable enableUserSelectHack={false}>
263+
<div />
264+
</Draggable>
265+
);
266+
267+
var node = ReactDOM.findDOMNode(drag);
268+
269+
expect(document.body.getAttribute('style')).toEqual('');
270+
TestUtils.Simulate.mouseDown(node, {clientX: 0, clientY: 0});
271+
expect(document.body.getAttribute('style')).toEqual('');
272+
TestUtils.Simulate.mouseUp(node);
273+
expect(document.body.getAttribute('style')).toEqual('');
274+
});
256275
});
257276

258277
describe('interaction', function () {

0 commit comments

Comments
 (0)