Skip to content

Commit 06be31f

Browse files
authored
fix: should correct render when has addon and prefix (#36)
1 parent 8cde73f commit 06be31f

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

src/BaseInput.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ const BaseInput: FC<BaseInputProps> = (props) => {
7272
value,
7373
hidden,
7474
className:
75-
classNames(inputElement.props?.className, className) || undefined,
75+
classNames(
76+
inputElement.props?.className,
77+
!hasPrefixSuffix(props) && !hasAddon(props) && className,
78+
) || null,
7679
style: {
7780
...inputElement.props?.style,
7881
...inputStyle,
@@ -148,10 +151,9 @@ const BaseInput: FC<BaseInputProps> = (props) => {
148151
<span className={mergedGroupClassName} style={style} hidden={hidden}>
149152
<span className={mergedWrapperClassName}>
150153
{addonBefore && <span className={addonCls}>{addonBefore}</span>}
151-
{cloneElement(inputElement, {
154+
{cloneElement(element, {
152155
style: inputStyle ?? null,
153156
hidden: null,
154-
value,
155157
})}
156158
{addonAfter && <span className={addonCls}>{addonAfter}</span>}
157159
</span>

tests/BaseInput.test.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,16 @@ describe('BaseInput', () => {
203203
container.querySelector('input')?.classList.contains('test-base'),
204204
).toBeFalsy();
205205
});
206+
207+
it('should correct render with prefix and addon', () => {
208+
const { container } = render(
209+
<BaseInput
210+
prefixCls="rc-input"
211+
prefix="prefix"
212+
addonBefore="addon"
213+
inputElement={<input />}
214+
/>,
215+
);
216+
expect(container).toMatchSnapshot();
217+
});
206218
});

tests/__snapshots__/BaseInput.test.tsx.snap

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,36 @@ exports[`BaseInput prefix and suffix should render properly 1`] = `
7474
</div>
7575
`;
7676

77+
exports[`BaseInput should correct render with prefix and addon 1`] = `
78+
<div>
79+
<span
80+
class="rc-input-group-wrapper"
81+
>
82+
<span
83+
class="rc-input-wrapper rc-input-group"
84+
>
85+
<span
86+
class="rc-input-group-addon"
87+
>
88+
addon
89+
</span>
90+
<span
91+
class="rc-input-affix-wrapper"
92+
>
93+
<span
94+
class="rc-input-prefix"
95+
>
96+
prefix
97+
</span>
98+
<input
99+
value=""
100+
/>
101+
</span>
102+
</span>
103+
</span>
104+
</div>
105+
`;
106+
77107
exports[`BaseInput should render perfectly 1`] = `
78108
<div>
79109
<input

0 commit comments

Comments
 (0)