mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-01 11:39:28 +08:00
refactor: rewrite Transfer search with hooks (#28895)
* Refac: rewrite transfer search with hook * [CodeFactor] Apply fixes to commit 3ad857f [ci skip] [skip ci] * chore: minor change in search Co-authored-by: codefactor-io <support@codefactor.io>
This commit is contained in:
parent
9daf50f3a9
commit
19f3e6cdae
@ -13,50 +13,41 @@ export interface TransferSearchProps {
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
export default class Search extends React.Component<TransferSearchProps, any> {
|
||||
static defaultProps = {
|
||||
placeholder: '',
|
||||
};
|
||||
export default function Search(props: TransferSearchProps) {
|
||||
const { placeholder = '', value, prefixCls, disabled, onChange, handleClear } = props;
|
||||
|
||||
handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const { onChange } = this.props;
|
||||
if (onChange) {
|
||||
onChange(e);
|
||||
}
|
||||
};
|
||||
const handleChange = React.useCallback(
|
||||
(e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
onChange?.(e);
|
||||
},
|
||||
[onChange],
|
||||
);
|
||||
|
||||
handleClear = (e: React.MouseEvent<HTMLAnchorElement>) => {
|
||||
const handleClearFn = (e: React.MouseEvent<HTMLAnchorElement>) => {
|
||||
e.preventDefault();
|
||||
const { handleClear, disabled } = this.props;
|
||||
if (!disabled && handleClear) {
|
||||
handleClear(e);
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
const { placeholder, value, prefixCls, disabled } = this.props;
|
||||
const icon =
|
||||
value && value.length > 0 ? (
|
||||
<a className={`${prefixCls}-action`} onClick={this.handleClear}>
|
||||
return (
|
||||
<>
|
||||
<Input
|
||||
placeholder={placeholder}
|
||||
className={prefixCls}
|
||||
value={value}
|
||||
onChange={handleChange}
|
||||
disabled={disabled}
|
||||
/>
|
||||
{value && value.length > 0 ? (
|
||||
<a className={`${prefixCls}-action`} onClick={handleClearFn}>
|
||||
<CloseCircleFilled />
|
||||
</a>
|
||||
) : (
|
||||
<span className={`${prefixCls}-action`}>
|
||||
<SearchOutlined />
|
||||
</span>
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Input
|
||||
placeholder={placeholder}
|
||||
className={prefixCls}
|
||||
value={value}
|
||||
onChange={this.handleChange}
|
||||
disabled={disabled}
|
||||
/>
|
||||
{icon}
|
||||
</>
|
||||
);
|
||||
}
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user