Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/BaseInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ const BaseInput = React.forwardRef<HolderRef, BaseInputProps>((props, ref) => {
// ================== Clear Icon ================== //
let clearIcon: ReactNode = null;
if (allowClear) {
const needClear = !disabled && !readOnly && value;
const needClear =
!disabled &&
!readOnly &&
value &&
!(typeof allowClear === 'object' && allowClear.disabled);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null 也是 object

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

外层的 if (allowClear) 已经确保不为 null 了,因此这里就没有再判断了

const clearIconCls = `${prefixCls}-clear-icon`;
const iconNode =
typeof allowClear === 'object' && allowClear?.clearIcon
Expand Down
5 changes: 3 additions & 2 deletions src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface CommonInputProps {
prefix?: CSSProperties;
suffix?: CSSProperties;
};
allowClear?: boolean | { clearIcon?: ReactNode };
allowClear?: boolean | { disabled?: boolean; clearIcon?: ReactNode };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

antd 里有没有类似的属性?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

antd 里是直接 import 的这个类型复用了

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我意思是 antd 里是否有 config 里带有 enabled or disabled 的属性可以参考一下。免得未来这个名字出现多种情况

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

搜索了一下,大部分使用的是 disabled,比如 useClosable:

interface ClosableCollection {
  closable?: ClosableType;
  closeIcon?: ReactNode;
  disabled?: boolean;
}

比如 WaveConfig:

export interface WaveConfig {
  disabled?: boolean;
  showEffect?: ShowWaveEffect;
}

而 enabled 只有一处使用:

export interface MaskConfig {
  enabled?: boolean;
  blur?: boolean;
  closable?: boolean;
}

}

type DataAttr = Record<`data-${string}`, string>;
Expand Down Expand Up @@ -86,7 +86,8 @@ export interface CountConfig {
}

export interface InputProps
extends CommonInputProps,
extends
CommonInputProps,
Omit<
InputHTMLAttributes<HTMLInputElement>,
'size' | 'prefix' | 'type' | 'value'
Expand Down