Skip to content

Commit

Permalink
adds Search onSelect callback when dropdown is not active (#1260)
Browse files Browse the repository at this point in the history
* adds Search onSelect callback when dropdown is not active

Signed-off-by: Raphael Gruber <raphi011@gmail.com>

* Added onSelect inside onEnter too
  • Loading branch information
raphi011 authored and alansouzati committed Mar 22, 2017
1 parent bc96847 commit fc03118
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/js/components/Search.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ export default class Search extends Component {
}

_onInputKeyDown (event) {
const { inline, suggestions, onKeyDown } = this.props;
const {
inline, onSelect, suggestions, activeSuggestionIndex, onKeyDown
} = this.props;
const enter = 13;
const { dropActive } = this.state;
if (suggestions) {
const up = 38;
Expand All @@ -177,6 +180,14 @@ export default class Search extends Component {
}
}
}
if (!dropActive && onSelect && event.keyCode === enter) {
const suggestion = suggestions[activeSuggestionIndex];

onSelect({
target: this._inputRef || this._controlRef,
suggestion: suggestion
}, false);
}
if (onKeyDown) {
onKeyDown(event);
}
Expand Down Expand Up @@ -284,6 +295,10 @@ export default class Search extends Component {
suggestion: suggestion
}, true);
}
} else {
onSelect({
target: this._inputRef || this._controlRef
}, false);
}
}

Expand Down Expand Up @@ -482,6 +497,7 @@ Search.propTypes = {
inline: PropTypes.bool,
onDOMChange: PropTypes.func,
onSelect: PropTypes.func,
onKeyDown: PropTypes.func,
pad: PropTypes.oneOf(['small', 'medium']),
placeHolder: PropTypes.string,
responsive: PropTypes.bool,
Expand Down

0 comments on commit fc03118

Please sign in to comment.