Skip to content

Commit e683187

Browse files
authored
Merge pull request #235 from kuzzmi/master
Adds onMouseDown workaround to TypeaheadOption
2 parents 8ce5b61 + 2544b1e commit e683187

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/typeahead/option.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,11 @@ var TypeaheadOption = React.createClass({
3333

3434
var classList = classNames(classes);
3535

36+
// For some reason onClick is not fired when clicked on an option
37+
// onMouseDown is used here as a workaround of #205 and other
38+
// related tickets
3639
return (
37-
<li className={classList} onClick={this._onClick}>
40+
<li className={classList} onClick={this._onClick} onMouseDown={this._onClick}>
3841
<a href="javascript: void 0;" className={this._getClasses()} ref="anchor">
3942
{ this.props.children }
4043
</a>

test/typeahead-test.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,27 @@ describe('Typeahead Component', function() {
138138
});
139139
});
140140

141+
describe('mouse controls', function() {
142+
// as of React 15.5.4 this does not work
143+
xit('mouse click selects an option (click event)', function() {
144+
var results = simulateTextInput(this.component, 'o');
145+
var secondItem = ReactDOM.findDOMNode(results[1]);
146+
var secondItemValue = secondItem.innerText;
147+
var node = this.component.refs.entry;
148+
TestUtils.Simulate.click(secondItem);
149+
assert.equal(node.value, secondItemValue);
150+
});
151+
// but this one works
152+
it('mouse click selects an option (mouseDown event)', function() {
153+
var results = simulateTextInput(this.component, 'o');
154+
var secondItem = ReactDOM.findDOMNode(results[1]);
155+
var secondItemValue = secondItem.innerText;
156+
var node = this.component.refs.entry;
157+
TestUtils.Simulate.mouseDown(secondItem);
158+
assert.equal(node.value, secondItemValue);
159+
});
160+
});
161+
141162
describe('component functions', function() {
142163
beforeEach(function() {
143164
this.sinon = sinon.sandbox.create();

0 commit comments

Comments
 (0)