fix: Input can not be hidden when prefix is set (#33706)

* fix: Input can not be hidden when prefix is set

* test: jest case for #33692

Co-authored-by: hydraZty <hydra_zty@163.com>
This commit is contained in:
hydraZty 2022-01-13 16:23:27 +08:00 committed by GitHub
parent 2d484bbe47
commit aecf52e4b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 0 deletions

View File

@ -29,6 +29,7 @@ interface BasicProps {
focused?: boolean;
readOnly?: boolean;
bordered: boolean;
hidden?: boolean;
}
/** This props only for input. */
@ -104,6 +105,7 @@ class ClearableLabeledInput extends React.Component<ClearableInputProps> {
style,
readOnly,
bordered,
hidden,
} = this.props;
if (!hasPrefixSuffix(this.props)) {
return cloneElement(element, {
@ -132,6 +134,7 @@ class ClearableLabeledInput extends React.Component<ClearableInputProps> {
className={affixWrapperCls}
style={style}
onMouseUp={this.onInputMouseUp}
hidden={hidden}
>
{prefixNode}
{cloneElement(element, {

View File

@ -97,6 +97,18 @@ describe('prefix and suffix', () => {
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 hidden when has prefix or suffix', () => {
const wrapper = mount(
<>
<Input prefix="prefix" hidden className="prefix-with-hidden" />
<Input suffix="suffix" hidden className="suffix-with-hidden" />
</>,
);
expect(wrapper.find('.prefix-with-hidden').at(0).getDOMNode().hidden).toBe(true);
expect(wrapper.find('.suffix-with-hidden').at(0).getDOMNode().hidden).toBe(true);
});
});
describe('As Form Control', () => {