diff --git a/components/form/__tests__/__snapshots__/demo.test.js.snap b/components/form/__tests__/__snapshots__/demo.test.js.snap index a6ec07b9f4..e2570853b0 100644 --- a/components/form/__tests__/__snapshots__/demo.test.js.snap +++ b/components/form/__tests__/__snapshots__/demo.test.js.snap @@ -7623,7 +7623,7 @@ exports[`renders ./components/form/demo/validate-static.md correctly 1`] = ` class="ant-form-item-control-input-content" > { [`${prefixCls}-affix-wrapper-rtl`]: direction === 'rtl', [`${prefixCls}-affix-wrapper-readonly`]: readOnly, [`${prefixCls}-affix-wrapper-borderless`]: !bordered, - // https://github.com/ant-design/ant-design/issues/27258 - [`${className}`]: !allowClear && className, + // className will go to addon wrapper + [`${className}`]: !hasAddon(this.props) && className, }); return ( { renderInputWithLabel(prefixCls: string, labeledElement: React.ReactElement) { const { addonBefore, addonAfter, style, size, className, direction } = this.props; // Not wrap when there is not addons - if (!addonBefore && !addonAfter) { + if (!hasAddon(this.props)) { return labeledElement; } @@ -156,8 +160,7 @@ class ClearableLabeledInput extends React.Component { ) : null; const addonAfterNode = addonAfter ? {addonAfter} : null; - const mergedWrapperClassName = classNames(`${prefixCls}-wrapper`, { - [wrapperClassName]: addonBefore || addonAfter, + const mergedWrapperClassName = classNames(`${prefixCls}-wrapper`, wrapperClassName, { [`${wrapperClassName}-rtl`]: direction === 'rtl', }); @@ -197,8 +200,9 @@ class ClearableLabeledInput extends React.Component { { [`${prefixCls}-affix-wrapper-rtl`]: direction === 'rtl', [`${prefixCls}-affix-wrapper-borderless`]: !bordered, + // className will go to addon wrapper + [`${className}`]: !hasAddon(this.props) && className, }, - className, ); return ( diff --git a/components/input/__tests__/Search.test.js b/components/input/__tests__/Search.test.js index 49f0546be6..9c1f936e0b 100644 --- a/components/input/__tests__/Search.test.js +++ b/components/input/__tests__/Search.test.js @@ -22,10 +22,8 @@ describe('Input.Search', () => { }); it('should support ReactNode suffix without error', () => { - const fn = () => { - mount(ok} />); - }; - expect(fn).not.toThrow(); + const wrapper = mount(ok} />); + expect(wrapper.render()).toMatchSnapshot(); }); it('should disable enter button when disabled prop is true', () => { diff --git a/components/input/__tests__/__snapshots__/Search.test.js.snap b/components/input/__tests__/__snapshots__/Search.test.js.snap index a2746d8e5d..b5936dcce5 100644 --- a/components/input/__tests__/__snapshots__/Search.test.js.snap +++ b/components/input/__tests__/__snapshots__/Search.test.js.snap @@ -45,6 +45,62 @@ exports[`Input.Search rtl render component should be rendered correctly in RTL d `; +exports[`Input.Search should support ReactNode suffix without error 1`] = ` + + + + + +
+ ok +
+
+
+ + + +
+
+`; + exports[`Input.Search should support addonAfter 1`] = ` `; - -exports[`Input.Search should support suffix 1`] = ` - - - - - - suffix - - - - - - - -`; diff --git a/components/input/__tests__/index.test.js b/components/input/__tests__/index.test.js index fce7dbf558..0268a9627b 100644 --- a/components/input/__tests__/index.test.js +++ b/components/input/__tests__/index.test.js @@ -76,6 +76,20 @@ describe('Input', () => { }); }); +describe('prefix and suffix', () => { + it('should support className when has suffix', () => { + const wrapper = mount(); + expect(wrapper.getDOMNode().className.includes('my-class-name')).toBe(true); + expect(wrapper.find('input').getDOMNode().className.includes('my-class-name')).toBe(false); + }); + + it('should support className when has prefix', () => { + const wrapper = mount(); + expect(wrapper.getDOMNode().className.includes('my-class-name')).toBe(true); + expect(wrapper.find('input').getDOMNode().className.includes('my-class-name')).toBe(false); + }); +}); + describe('As Form Control', () => { it('should be reset when wrapped in form.getFieldDecorator without initialValue', () => { const Demo = () => { @@ -110,13 +124,6 @@ describe('As Form Control', () => { }); }); -describe('Input.Search', () => { - it('should support suffix', () => { - const wrapper = mount(); - expect(wrapper.render()).toMatchSnapshot(); - }); -}); - describe('Input allowClear', () => { it('should change type when click', () => { const wrapper = mount(); @@ -189,4 +196,11 @@ describe('Input allowClear', () => { expect(wrapper.find('.ant-input-clear-icon-hidden').exists()).toBeTruthy(); }); }); + + // https://github.com/ant-design/ant-design/issues/27444 + it('should support className', () => { + const wrapper = mount(); + expect(wrapper.getDOMNode().className.includes('my-class-name')).toBe(true); + expect(wrapper.find('input').getDOMNode().className.includes('my-class-name')).toBe(false); + }); });