Skip to content

Commit

Permalink
Merge pull request arco-design#2591 from bestlyg/fix-lyg-input-search
Browse files Browse the repository at this point in the history
fix: can not use suffix and addAfter prop in input-search
  • Loading branch information
flsion authored Mar 21, 2024
2 parents 4407b57 + b917636 commit 8c95dc8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
7 changes: 6 additions & 1 deletion components/AutoComplete/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,12 @@ function AutoComplete(baseProps: AutoCompleteProps, ref) {
...inputProps,
...pickDataAttributes(props),
// Empty tag to ensure the consistency of the dom structure of input, such that input won't accidentally lose focus due to structure change on input.
suffix: loading ? <IconLoading /> : inputProps?.suffix || <i />,
suffix: loading ? (
<IconLoading />
) : (usedTriggerElement?.type as unknown as { displayName: string })?.displayName ===
'Search' ? undefined : (
inputProps?.suffix || <i />
),
onFocus: (event) => {
setIsFocused(true);
onFocus?.(event);
Expand Down
24 changes: 20 additions & 4 deletions components/Input/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,18 @@ import { isObject } from '../_util/is';
const Search = React.forwardRef<RefInputType, InputSearchProps>((props: InputSearchProps, ref) => {
const { getPrefixCls } = useContext(ConfigContext);

const { className, style, placeholder, disabled, searchButton, loading, defaultValue, ...rest } =
props;
const {
className,
style,
placeholder,
disabled,
searchButton,
loading,
defaultValue,
addAfter,
suffix,
...rest
} = props;

const trueMaxLength = isObject(props.maxLength) ? props.maxLength.length : props.maxLength;
const mergedMaxLength =
Expand Down Expand Up @@ -48,7 +58,9 @@ const Search = React.forwardRef<RefInputType, InputSearchProps>((props: InputSea
ref={ref}
placeholder={placeholder}
addAfter={
searchButton ? (
addAfter !== undefined ? (
addAfter
) : searchButton ? (
<Button
disabled={disabled}
size={rest.size}
Expand All @@ -63,7 +75,11 @@ const Search = React.forwardRef<RefInputType, InputSearchProps>((props: InputSea
</Button>
) : null
}
suffix={!searchButton && (loading ? <IconLoading /> : <IconSearch onClick={onSearch} />)}
suffix={
suffix !== undefined
? suffix
: !searchButton && (loading ? <IconLoading /> : <IconSearch onClick={onSearch} />)
}
onChange={(value, e) => {
setValue(value);
props.onChange && props.onChange(value, e);
Expand Down

0 comments on commit 8c95dc8

Please sign in to comment.