diff --git a/packages/react-instantsearch/src/components/SearchBox.js b/packages/react-instantsearch/src/components/SearchBox.js index 7480e47afb..cb2486df84 100644 --- a/packages/react-instantsearch/src/components/SearchBox.js +++ b/packages/react-instantsearch/src/components/SearchBox.js @@ -21,6 +21,8 @@ class SearchBox extends Component { searchAsYouType: PropTypes.bool, onSubmit: PropTypes.func, + onReset: PropTypes.func, + onChange: PropTypes.func, // For testing purposes __inputRef: PropTypes.func, @@ -134,11 +136,19 @@ class SearchBox extends Component { onChange = e => { this.setQuery(e.target.value); + + if (this.props.onChange) { + this.props.onChange(e); + } }; onReset = () => { this.setQuery(''); this.input.focus(); + + if (this.props.onReset) { + this.props.onReset(); + } }; render() { @@ -160,6 +170,17 @@ class SearchBox extends Component { ; + const searchInputEvents = Object.keys(this.props).reduce((props, prop) => { + if ( + ['onsubmit', 'onreset', 'onchange'].indexOf(prop.toLowerCase()) === -1 && + prop.indexOf('on') === 0 + ) { + return {...props, [prop]: this.props[prop]}; + } + + return props; + }, {}); + /* eslint-disable max-len */ return (