diff --git a/src/BaseInput.tsx b/src/BaseInput.tsx index c8c6176..3bca08b 100644 --- a/src/BaseInput.tsx +++ b/src/BaseInput.tsx @@ -74,7 +74,11 @@ const BaseInput = React.forwardRef((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); const clearIconCls = `${prefixCls}-clear-icon`; const iconNode = typeof allowClear === 'object' && allowClear?.clearIcon diff --git a/src/interface.ts b/src/interface.ts index 58a3d9c..1b142dc 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -33,7 +33,7 @@ export interface CommonInputProps { prefix?: CSSProperties; suffix?: CSSProperties; }; - allowClear?: boolean | { clearIcon?: ReactNode }; + allowClear?: boolean | { disabled?: boolean; clearIcon?: ReactNode }; } type DataAttr = Record<`data-${string}`, string>; @@ -86,7 +86,8 @@ export interface CountConfig { } export interface InputProps - extends CommonInputProps, + extends + CommonInputProps, Omit< InputHTMLAttributes, 'size' | 'prefix' | 'type' | 'value' diff --git a/tests/index.test.tsx b/tests/index.test.tsx index 4e4567c..a27875d 100644 --- a/tests/index.test.tsx +++ b/tests/index.test.tsx @@ -278,6 +278,17 @@ describe('Input allowClear', () => { }); }); + it('should not support allowClear when allowClear is disabled', () => { + const { container } = render( + , + ); + expect(container.querySelector('.rc-input-clear-icon-hidden')).toBeTruthy(); + }); + it('classNames and styles should work', () => { const { container } = render( <>