Skip to content

Commit 1a5c981

Browse files
Merge pull request #2206 from appbaseio/web-searchbox-query-bug
fix(web): custom query fired on clearing input via keyboard
2 parents 980e99a + aa40441 commit 1a5c981

File tree

1 file changed

+34
-43
lines changed

1 file changed

+34
-43
lines changed

packages/web/src/components/search/SearchBox.js

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -504,14 +504,7 @@ const SearchBox = (props) => {
504504
setIsOpen(true);
505505
}
506506
if (value === undefined) {
507-
setValue(
508-
inputValue,
509-
false,
510-
props,
511-
inputValue === '' ? causes.CLEAR_VALUE : undefined,
512-
true,
513-
false,
514-
);
507+
setValue(inputValue, false, props, undefined, true, false);
515508
} else if (onChange) {
516509
// handle caret position in controlled components
517510
handleCaretPosition(e);
@@ -555,7 +548,14 @@ const SearchBox = (props) => {
555548
};
556549

557550
const clearValue = () => {
558-
setValue('', false, props, causes.CLEAR_VALUE, true, false);
551+
setValue(
552+
'',
553+
false,
554+
props,
555+
!isTagsMode.current ? causes.CLEAR_VALUE : undefined,
556+
true,
557+
false,
558+
);
559559
if (onChange) {
560560
onChange('', ({ isOpen } = {}) =>
561561
triggerQuery({
@@ -765,11 +765,9 @@ const SearchBox = (props) => {
765765
return props.icon;
766766
}
767767
if (props.iconURL) {
768-
return (<img
769-
style={{ maxHeight: '25px' }}
770-
src={XSS(props.iconURL)}
771-
alt="search-icon"
772-
/>);
768+
return (
769+
<img style={{ maxHeight: '25px' }} src={XSS(props.iconURL)} alt="search-icon" />
770+
);
773771
}
774772
return <SearchSvg />;
775773
}
@@ -814,14 +812,11 @@ const SearchBox = (props) => {
814812
{renderCancelIcon()}
815813
</IconWrapper>
816814
)}
817-
{
818-
showFocusShortcutsIcon
819-
&& (
820-
<ButtonIconWrapper onClick={e => focusSearchBox(e)}>
821-
{renderShortcut()}
822-
</ButtonIconWrapper>
823-
)
824-
}
815+
{showFocusShortcutsIcon && (
816+
<ButtonIconWrapper onClick={e => focusSearchBox(e)}>
817+
{renderShortcut()}
818+
</ButtonIconWrapper>
819+
)}
825820
{shouldMicRender(showVoiceSearch) && (
826821
<Mic
827822
getInstance={getMicInstance}
@@ -840,20 +835,18 @@ const SearchBox = (props) => {
840835
<IconWrapper onClick={handleSearchIconClick}>{renderIcon()}</IconWrapper>
841836
)}
842837
</IconGroup>
843-
844838
</div>
845839
);
846840
};
847-
const SuggestionsFooter = () => (
848-
typeof renderSuggestionsFooter === 'function'
849-
? renderSuggestionsFooter()
850-
: ((
851-
<AutosuggestFooterContainer>
852-
<div>↑↓ Navigate</div>
853-
<div>↩ Go</div>
854-
</AutosuggestFooterContainer>))
855-
);
856-
841+
const SuggestionsFooter = () =>
842+
(typeof renderSuggestionsFooter === 'function' ? (
843+
renderSuggestionsFooter()
844+
) : (
845+
<AutosuggestFooterContainer>
846+
<div>↑↓ Navigate</div>
847+
<div>↩ Go</div>
848+
</AutosuggestFooterContainer>
849+
));
857850

858851
const onAutofillClick = (suggestion) => {
859852
const { value } = suggestion;
@@ -1391,8 +1384,7 @@ const SearchBox = (props) => {
13911384
);
13921385
})}
13931386

1394-
{showSuggestionsFooter
1395-
? <SuggestionsFooter /> : null}
1387+
{showSuggestionsFooter ? <SuggestionsFooter /> : null}
13961388
</ul>
13971389
) : (
13981390
renderNoSuggestion(parsedSuggestions())
@@ -1706,14 +1698,13 @@ const ForwardRefComponent = React.forwardRef((props, ref) => (
17061698
componentType={componentTypes.searchBox}
17071699
mode={preferenceProps.testMode ? 'test' : ''}
17081700
>
1709-
{
1710-
componentProps =>
1711-
(<ConnectedComponent
1712-
{...preferenceProps}
1713-
{...componentProps}
1714-
myForwardedRef={ref}
1715-
/>)
1716-
}
1701+
{componentProps => (
1702+
<ConnectedComponent
1703+
{...preferenceProps}
1704+
{...componentProps}
1705+
myForwardedRef={ref}
1706+
/>
1707+
)}
17171708
</ComponentWrapper>
17181709
)}
17191710
</PreferencesConsumer>

0 commit comments

Comments
 (0)