Skip to content

Commit c202b82

Browse files
authored
refactor/style (#39)
* refactor: better style logic * refactor: better style logic
1 parent b627d80 commit c202b82

File tree

3 files changed

+142
-21
lines changed

3 files changed

+142
-21
lines changed

src/BaseInput.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ const BaseInput: FC<BaseInputProps> = (props) => {
7676
) || null,
7777
style: {
7878
...inputElement.props?.style,
79+
...(!hasPrefixSuffix(props) && !hasAddon(props) ? style : {}),
7980
},
8081
});
8182

@@ -108,7 +109,7 @@ const BaseInput: FC<BaseInputProps> = (props) => {
108109
element = (
109110
<span
110111
className={affixWrapperCls}
111-
style={style}
112+
style={!hasAddon(props) ? style : undefined}
112113
hidden={!hasAddon(props) && hidden}
113114
onClick={onInputClick}
114115
{...dataAttrs?.affixWrapper}

tests/__snapshots__/index.test.tsx.snap

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
exports[`Input allowClear classNames and styles should work 1`] = `
44
<div>
55
<span
6-
class="rc-input-affix-wrapper"
6+
class="rc-input-affix-wrapper custom-class"
7+
style="background-color: red;"
78
>
89
<span
910
class="rc-input-prefix custom-prefix"
@@ -30,6 +31,74 @@ exports[`Input allowClear classNames and styles should work 1`] = `
3031
suffix
3132
</span>
3233
</span>
34+
<span
35+
class="rc-input-group-wrapper custom-class"
36+
style="background-color: red;"
37+
>
38+
<span
39+
class="rc-input-wrapper rc-input-group"
40+
>
41+
<span
42+
class="rc-input-affix-wrapper"
43+
>
44+
<span
45+
class="rc-input-prefix custom-prefix"
46+
style="color: blue;"
47+
>
48+
prefix
49+
</span>
50+
<input
51+
class="rc-input custom-input"
52+
style="color: red;"
53+
type="text"
54+
value="123"
55+
/>
56+
<span
57+
class="rc-input-suffix custom-suffix"
58+
style="color: yellow;"
59+
>
60+
<span
61+
class="rc-input-show-count-suffix rc-input-show-count-has-suffix custom-count"
62+
style="color: green;"
63+
>
64+
3
65+
</span>
66+
suffix
67+
</span>
68+
</span>
69+
<span
70+
class="rc-input-group-addon"
71+
>
72+
addon
73+
</span>
74+
</span>
75+
</span>
76+
<input
77+
class="rc-input custom-input custom-class"
78+
style="color: red; background-color: red;"
79+
type="text"
80+
value="123"
81+
/>
82+
<span
83+
class="rc-input-group-wrapper custom-class"
84+
style="background-color: red;"
85+
>
86+
<span
87+
class="rc-input-wrapper rc-input-group"
88+
>
89+
<input
90+
class="rc-input custom-input"
91+
style="color: red;"
92+
type="text"
93+
value="123"
94+
/>
95+
<span
96+
class="rc-input-group-addon"
97+
>
98+
addon
99+
</span>
100+
</span>
101+
</span>
33102
</div>
34103
`;
35104

tests/index.test.tsx

Lines changed: 70 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -242,25 +242,76 @@ describe('Input allowClear', () => {
242242

243243
it('classNames and styles should work', () => {
244244
const { container } = render(
245-
<Input
246-
value="123"
247-
showCount
248-
prefixCls="rc-input"
249-
prefix="prefix"
250-
suffix="suffix"
251-
classNames={{
252-
input: 'custom-input',
253-
prefix: 'custom-prefix',
254-
suffix: 'custom-suffix',
255-
count: 'custom-count',
256-
}}
257-
styles={{
258-
input: { color: 'red' },
259-
prefix: { color: 'blue' },
260-
suffix: { color: 'yellow' },
261-
count: { color: 'green' },
262-
}}
263-
/>,
245+
<>
246+
<Input
247+
value="123"
248+
showCount
249+
prefixCls="rc-input"
250+
prefix="prefix"
251+
suffix="suffix"
252+
className="custom-class"
253+
style={{ backgroundColor: 'red' }}
254+
classNames={{
255+
input: 'custom-input',
256+
prefix: 'custom-prefix',
257+
suffix: 'custom-suffix',
258+
count: 'custom-count',
259+
}}
260+
styles={{
261+
input: { color: 'red' },
262+
prefix: { color: 'blue' },
263+
suffix: { color: 'yellow' },
264+
count: { color: 'green' },
265+
}}
266+
/>
267+
<Input
268+
value="123"
269+
addonAfter="addon"
270+
showCount
271+
prefixCls="rc-input"
272+
prefix="prefix"
273+
suffix="suffix"
274+
className="custom-class"
275+
style={{ backgroundColor: 'red' }}
276+
classNames={{
277+
input: 'custom-input',
278+
prefix: 'custom-prefix',
279+
suffix: 'custom-suffix',
280+
count: 'custom-count',
281+
}}
282+
styles={{
283+
input: { color: 'red' },
284+
prefix: { color: 'blue' },
285+
suffix: { color: 'yellow' },
286+
count: { color: 'green' },
287+
}}
288+
/>
289+
<Input
290+
value="123"
291+
prefixCls="rc-input"
292+
className="custom-class"
293+
style={{ backgroundColor: 'red' }}
294+
classNames={{
295+
input: 'custom-input',
296+
}}
297+
styles={{
298+
input: { color: 'red' },
299+
}}
300+
/>
301+
<Input
302+
value="123"
303+
prefixCls="rc-input"
304+
className="custom-class"
305+
addonAfter="addon"
306+
style={{ backgroundColor: 'red' }}
307+
classNames={{
308+
input: 'custom-input',
309+
}}
310+
styles={{
311+
input: { color: 'red' },
312+
}}
313+
/>
314+
</>,
264315
);
265316
expect(container).toMatchSnapshot();
266317
});

0 commit comments

Comments
 (0)