Skip to content

Commit 308f1da

Browse files
gagan876574ad1992
authored andcommitted
feat: Add onTouchStart for mobile device (#448)
Add onTouchStart for tags and suggestions
1 parent 657d748 commit 308f1da

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

__tests__/suggestions.test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import ReactDOM from 'react-dom';
33
import { expect } from 'chai';
44
import { shallow, mount } from 'enzyme';
5-
import { spy } from 'sinon';
5+
import { spy, stub } from 'sinon';
66
import Suggestions from '../src/components/Suggestions';
77
import noop from 'lodash/noop';
88
import { DEFAULT_LABEL_FIELD } from '../src/components/constants';
@@ -221,4 +221,11 @@ describe('Suggestions', function() {
221221

222222
expect($el.find('.bar').length).to.equal(4);
223223
});
224+
225+
test('should trigger the click handler on touchStart', function () {
226+
const onTagClickedStub = stub();
227+
const $el = mount(mockItem({ handleClick: onTagClickedStub }));
228+
$el.find('li').first().simulate('touchStart');
229+
expect(onTagClickedStub.calledOnce).to.be.true;
230+
});
224231
});

__tests__/tag.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ describe('Tag', () => {
107107
expect(spy.calledOnce).to.be.true;
108108
});
109109

110+
test('should trigger the tag click handler on touchStart', () => {
111+
const onTagClickedStub = sinon.stub();
112+
const $el = mount(mockItem({ onTagClicked: onTagClickedStub }));
113+
$el.find('span').simulate('touchStart');
114+
expect(onTagClickedStub.calledOnce).to.be.true;
115+
});
116+
110117
test('should be draggable', () => {
111118
const root = TestUtils.renderIntoDocument(mockItem());
112119
const backend = root.getManager().getBackend();

src/components/Suggestions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ class Suggestions extends Component {
102102
<li
103103
key={i}
104104
onMouseDown={props.handleClick.bind(null, i)}
105+
onTouchStart={props.handleClick.bind(null, i)}
105106
onMouseOver={props.handleHover.bind(null, i)}
106107
className={
107108
i === props.selectedIndex ? props.classNames.activeSuggestion : ''

src/components/Tag.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class Tag extends Component {
3232
className={ClassNames('tag-wrapper', classNames.tag, className)}
3333
style={{opacity: isDragging ? 0 : 1, 'cursor': canDrag(props) ? 'move' : 'auto'}}
3434
onClick={props.onTagClicked}
35-
onKeyDown={props.onTagClicked}>
35+
onKeyDown={props.onTagClicked}
36+
onTouchStart={props.onTagClicked}>
3637
{label}
3738
<RemoveComponent
3839
tag={props.tag}

0 commit comments

Comments
 (0)