Skip to content

Commit

Permalink
fix(SearchInput): do not overwrite clear button * 2
Browse files Browse the repository at this point in the history
  • Loading branch information
tenphi committed Mar 23, 2023
1 parent d9c2ab3 commit c8b06f1
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/components/forms/SearchInput/SearchInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export const SearchInput = forwardRef(function SearchInput(

let state = useSearchFieldState(props);
let { inputProps, clearButtonProps } = useSearchField(props, state, inputRef);
let showClearButton = isClearable && state.value !== '' && !props.isReadOnly;

return (
<TextInputBase
Expand All @@ -55,16 +56,18 @@ export const SearchInput = forwardRef(function SearchInput(
suffixPosition="after"
{...props}
suffix={
<>
{props.suffix}
{isClearable && state.value !== '' && !props.isReadOnly && (
<ClearButton
type={validationState === 'invalid' ? 'clear' : 'neutral'}
theme={validationState === 'invalid' ? 'danger' : undefined}
{...ariaToCubeButtonProps(clearButtonProps)}
/>
)}
</>
props.suffix || showClearButton ? (
<>
{props.suffix}
{showClearButton && (
<ClearButton
type={validationState === 'invalid' ? 'clear' : 'neutral'}
theme={validationState === 'invalid' ? 'danger' : undefined}
{...ariaToCubeButtonProps(clearButtonProps)}
/>
)}
</>
) : undefined
}
/>
);
Expand Down

0 comments on commit c8b06f1

Please sign in to comment.