Skip to content

Commit

Permalink
Merge pull request #235 from kuzzmi/master
Browse files Browse the repository at this point in the history
Adds onMouseDown workaround to TypeaheadOption
  • Loading branch information
fmoo authored Jun 19, 2017
2 parents 8ce5b61 + 2544b1e commit e683187
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/typeahead/option.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,11 @@ var TypeaheadOption = React.createClass({

var classList = classNames(classes);

// For some reason onClick is not fired when clicked on an option
// onMouseDown is used here as a workaround of #205 and other
// related tickets
return (
<li className={classList} onClick={this._onClick}>
<li className={classList} onClick={this._onClick} onMouseDown={this._onClick}>
<a href="javascript: void 0;" className={this._getClasses()} ref="anchor">
{ this.props.children }
</a>
Expand Down
21 changes: 21 additions & 0 deletions test/typeahead-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,27 @@ describe('Typeahead Component', function() {
});
});

describe('mouse controls', function() {
// as of React 15.5.4 this does not work
xit('mouse click selects an option (click event)', function() {
var results = simulateTextInput(this.component, 'o');
var secondItem = ReactDOM.findDOMNode(results[1]);
var secondItemValue = secondItem.innerText;
var node = this.component.refs.entry;
TestUtils.Simulate.click(secondItem);
assert.equal(node.value, secondItemValue);
});
// but this one works
it('mouse click selects an option (mouseDown event)', function() {
var results = simulateTextInput(this.component, 'o');
var secondItem = ReactDOM.findDOMNode(results[1]);
var secondItemValue = secondItem.innerText;
var node = this.component.refs.entry;
TestUtils.Simulate.mouseDown(secondItem);
assert.equal(node.value, secondItemValue);
});
});

describe('component functions', function() {
beforeEach(function() {
this.sinon = sinon.sandbox.create();
Expand Down

0 comments on commit e683187

Please sign in to comment.