From d64b4a18372fdb9f332c221463e5a484e9e715cd Mon Sep 17 00:00:00 2001 From: Bas Goyarts Date: Mon, 24 Jul 2023 15:16:17 +0200 Subject: [PATCH] feat: implement onFocus callback --- react/components/InputSearch/index.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/react/components/InputSearch/index.js b/react/components/InputSearch/index.js index 7c62c022a..6eb51fd76 100755 --- a/react/components/InputSearch/index.js +++ b/react/components/InputSearch/index.js @@ -55,8 +55,18 @@ class InputSearch extends Component { this.setState({ hover }) } - handleFocus = focus => { - this.setState({ focus }) + handleFocus = event => { + const { onFocus } = this.props + + this.setState({ focus: true }) + + if (onFocus && typeof onFocus === 'function') { + onFocus(event) + } + } + + handleBlur = () => { + this.setState({ focus: false }) } render() { @@ -67,8 +77,8 @@ class InputSearch extends Component { return ( this.handleFocus(true)} - onBlur={() => this.handleFocus(false)} + onFocus={this.handleFocus} + onBlur={this.handleBlur} onMouseEnter={() => this.handleHovering(true)} onMouseLeave={() => this.handleHovering(false)} onKeyUp={e => e.key === 'Enter' && this.handleSubmit(e)} @@ -111,6 +121,7 @@ InputSearch.propTypes = { forwardedRef: refShape, onChange: PropTypes.func, onSubmit: PropTypes.func, + onFocus: PropTypes.func, onClear: PropTypes.func, size: PropTypes.string, value: PropTypes.string,