diff --git a/docs/examples/allow-clear.tsx b/docs/examples/allow-clear.tsx index d9cfd68..99c5e13 100644 --- a/docs/examples/allow-clear.tsx +++ b/docs/examples/allow-clear.tsx @@ -12,18 +12,12 @@ const Demo: FC = () => { return (
- +

= (props) => { focused, triggerFocus, allowClear, - clearIcon, value, handleReset, hidden, @@ -43,6 +42,11 @@ const BaseInput: FC = (props) => { } const needClear = !disabled && !readOnly && value; const clearIconCls = `${prefixCls}-clear-icon`; + const iconNode = + typeof allowClear === 'object' && allowClear?.clearIcon + ? allowClear.clearIcon + : '✖'; + return ( = (props) => { role="button" tabIndex={-1} > - {clearIcon} + {iconNode} ); }; diff --git a/src/Input.tsx b/src/Input.tsx index 30198de..5e26e44 100644 --- a/src/Input.tsx +++ b/src/Input.tsx @@ -125,7 +125,6 @@ const Input = forwardRef((props, ref) => { 'inputClassName', 'wrapperClassName', 'htmlSize', - 'clearIcon', ]); return ( { return ( } @@ -100,4 +99,20 @@ describe('BaseInput', () => { expect(onChange).toHaveBeenCalledTimes(1); expect(inputEl!.value).toBe(''); }); + + it('should display clearIcon correctly', () => { + const { container, rerender } = render( + } allowClear />, + ); + const clearIcon = container.querySelector('.rc-input-clear-icon'); + expect(clearIcon?.innerHTML).toBe('✖'); + rerender( + } + allowClear={{ clearIcon: 'clear' }} + />, + ); + expect(clearIcon?.innerHTML).toBe('clear'); + }); }); diff --git a/tests/__snapshots__/index.test.tsx.snap b/tests/__snapshots__/index.test.tsx.snap index 91dc9fd..e60e247 100644 --- a/tests/__snapshots__/index.test.tsx.snap +++ b/tests/__snapshots__/index.test.tsx.snap @@ -17,7 +17,9 @@ exports[`Input allowClear should change type when click 1`] = ` class="rc-input-clear-icon" role="button" tabindex="-1" - /> + > + ✖ +
@@ -40,7 +42,9 @@ exports[`Input allowClear should change type when click 2`] = ` class="rc-input-clear-icon rc-input-clear-icon-hidden" role="button" tabindex="-1" - /> + > + ✖ + @@ -63,7 +67,9 @@ exports[`Input allowClear should not show icon if defaultValue is undefined or e class="rc-input-clear-icon rc-input-clear-icon-hidden" role="button" tabindex="-1" - /> + > + ✖ + @@ -86,7 +92,9 @@ exports[`Input allowClear should not show icon if defaultValue is undefined or e class="rc-input-clear-icon rc-input-clear-icon-hidden" role="button" tabindex="-1" - /> + > + ✖ + @@ -109,7 +117,9 @@ exports[`Input allowClear should not show icon if value is undefined or empty st class="rc-input-clear-icon rc-input-clear-icon-hidden" role="button" tabindex="-1" - /> + > + ✖ + @@ -132,7 +142,9 @@ exports[`Input allowClear should not show icon if value is undefined or empty st class="rc-input-clear-icon rc-input-clear-icon-hidden" role="button" tabindex="-1" - /> + > + ✖ +