diff --git a/src/BaseInput.tsx b/src/BaseInput.tsx index ae4ff4d..4cee233 100644 --- a/src/BaseInput.tsx +++ b/src/BaseInput.tsx @@ -45,12 +45,17 @@ const BaseInput: FC = (props) => { } }; + const hasAffix = hasPrefixSuffix(props); + let element: ReactElement = cloneElement(inputElement, { value, + className: + clsx(inputElement.props.className, !hasAffix && classNames?.variant) || + null, }); // ================== Prefix & Suffix ================== // - if (hasPrefixSuffix(props)) { + if (hasAffix) { // ================== Clear Icon ================== // let clearIcon: ReactNode = null; if (allowClear) { @@ -92,6 +97,7 @@ const BaseInput: FC = (props) => { }, classes?.affixWrapper, classNames?.affixWrapper, + classNames?.variant, ); const suffixNode = (suffix || allowClear) && ( diff --git a/src/interface.ts b/src/interface.ts index c2b289b..0270361 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -26,6 +26,7 @@ export interface CommonInputProps { suffix?: string; groupWrapper?: string; wrapper?: string; + variant?: string; }; styles?: { affixWrapper?: CSSProperties; diff --git a/tests/BaseInput.test.tsx b/tests/BaseInput.test.tsx index 55cc543..21a890c 100644 --- a/tests/BaseInput.test.tsx +++ b/tests/BaseInput.test.tsx @@ -236,4 +236,35 @@ describe('BaseInput', () => { expect(container.firstChild).toHaveClass('rc-input-group-wrapper-disabled'); }); + + it('variant cls', () => { + const { container, rerender } = render( + + + , + ); + + expect(container.querySelector('.rc-input-affix-wrapper')).toHaveClass( + 'test-variant', + ); + expect(container.querySelector('input')).not.toHaveClass('test-variant'); + + rerender( + + + , + ); + + expect(container.querySelector('.rc-input-affix-wrapper')).toBeFalsy(); + expect(container.querySelector('input')).toHaveClass('test-variant'); + }); });