Skip to content

Fix #5 and add tests for touch functionality#6

Merged
mikepb merged 2 commits intomikepb:masterfrom
motiz88:master
Apr 21, 2015
Merged

Fix #5 and add tests for touch functionality#6
mikepb merged 2 commits intomikepb:masterfrom
motiz88:master

Conversation

@motiz88
Copy link
Copy Markdown

@motiz88 motiz88 commented Mar 10, 2015

In this PR, I have:

  • Removed the globals root and bodyElement in favor of always setting and clearing events on this.getDOMNode().ownerDocument.body.
  • Removed isTouchDevice and the either/or relationship between touch and mouse events in favor of tracking the source device on a per-drag basis. This tracking relies on having separate handlers for touch and mouse events; For the record, my earlier approach of just inspecting event.type in the shared handlers did not pan out, because TestUtils.Simulate doesn't seem to set that property.
  • Removed dragEventFor in favor of dragEventsFor.mouse and dragEventsFor.touch.
  • Changed the semantics of state.dragging slightly - its value is now always one of false, 'touch' and 'mouse'. This is mainly so that a stray mouseup doesn't interfere with an ongoing touch-based drag operation, and vice versa.
  • Added tests that use simulated touch events alongside the existing ones for mouse events. (All tests pass on my machine, but please see Missing an automated test for onDrag #7)

Comment thread lib/draggable.js Outdated
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to add e.preventDefault() here too?
http://www.html5rocks.com/en/mobile/touchandmouse/

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, absolutely, just ran into that myself. (Though in that case the preventDefault line should probably just move to handleDrag)

- onMouseDown, onMouseUp, onTouchStart, onTouchEnd props now supported.
- The above user event handlers can now call preventDefault() and cleanly override drag actions.
- Added tests of above functionality.
- In the internal handlers, preventDefault() is called if and only if a drag operation is started. This prevents scrolling / text selection.
- Modified the example to only hide user selection on the <strong/> drag handles.
mikepb added a commit that referenced this pull request Apr 21, 2015
Fix #5 and add tests for touch functionality
@mikepb mikepb merged commit af08f76 into mikepb:master Apr 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants