Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds onMouseDown workaround to TypeaheadOption #235

Merged
merged 1 commit into from
Jun 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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