From 883d0a5af077ff60fc13ed4f2bf51c6c25f21f2b Mon Sep 17 00:00:00 2001 From: JF-Cozy Date: Wed, 16 Oct 2024 16:24:11 +0200 Subject: [PATCH 1/2] feat(SearchBar): Add `onClear` and `disabledFocus` props --- react/SearchBar/index.jsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/react/SearchBar/index.jsx b/react/SearchBar/index.jsx index 27d543068..616457814 100644 --- a/react/SearchBar/index.jsx +++ b/react/SearchBar/index.jsx @@ -116,12 +116,14 @@ const SearchBar = forwardRef( label: labelProp, componentsProps, disabledClear, + disabledFocus, className, defaultValue, value, elevation, disabled, onChange, + onClear, onFocus, onBlur, ...props @@ -155,6 +157,7 @@ const SearchBar = forwardRef( const handleClear = ev => { onChange({ ...ev, target: { ...ev.target, value: '' } }) + onClear(ev) setCurrentValue('') } @@ -175,7 +178,7 @@ const SearchBar = forwardRef( className={cx(className, classes.root, { [classes.flat]: !elevation, [classes.elevation]: elevation, - [classes.focused]: isFocused, + [classes.focused]: isFocused && !disabledFocus, [classes.disabled]: disabled })} ref={ref} @@ -233,9 +236,11 @@ SearchBar.defaultProps = { size: 'small', type: 'search', disabledClear: false, + disabledFocus: false, defaultValue: '', onChange: () => {}, onFocus: () => {}, + onClear: () => {}, onBlur: () => {} } @@ -253,6 +258,7 @@ SearchBar.propTypes = { /** Used only with self-controlled component */ defaultValue: PropTypes.string, disabledClear: PropTypes.bool, + disabledFocus: PropTypes.bool, elevation: PropTypes.bool, placeholder: PropTypes.string, label: PropTypes.oneOfType([ @@ -263,6 +269,7 @@ SearchBar.propTypes = { disabled: PropTypes.bool, onChange: PropTypes.func, onFocus: PropTypes.func, + onClear: PropTypes.func, onBlur: PropTypes.func } From 3504eb54cb6d2520c18d66a9c7eab181c667a0b8 Mon Sep 17 00:00:00 2001 From: JF-Cozy Date: Wed, 16 Oct 2024 16:24:46 +0200 Subject: [PATCH 2/2] fix(SearchBar): Ref wasn't spread correctly --- react/SearchBar/index.jsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/react/SearchBar/index.jsx b/react/SearchBar/index.jsx index 616457814..ef7013c99 100644 --- a/react/SearchBar/index.jsx +++ b/react/SearchBar/index.jsx @@ -273,10 +273,10 @@ SearchBar.propTypes = { onBlur: PropTypes.func } -const SearchBarWithLocales = props => { +const SearchBarWithLocales = forwardRef((props, ref) => { useExtendI18n(locales) - return -} + return +}) export default SearchBarWithLocales