Skip to content

Commit db5525c

Browse files
authored
fix: mix logic (#51)
1 parent 117dd80 commit db5525c

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

src/hooks/useCount.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,20 @@ export default function useCount(
2525
showCount?: InputProps['showCount'],
2626
) {
2727
return React.useMemo<ForcedCountConfig>(() => {
28-
let mergedConfig = count;
29-
30-
if (!count) {
31-
mergedConfig = {
32-
show:
33-
typeof showCount === 'object' && showCount.formatter
34-
? showCount.formatter
35-
: !!showCount,
36-
};
28+
let mergedConfig: CountConfig = {};
29+
30+
if (showCount) {
31+
mergedConfig.show =
32+
typeof showCount === 'object' && showCount.formatter
33+
? showCount.formatter
34+
: !!showCount;
3735
}
3836

37+
mergedConfig = {
38+
...mergedConfig,
39+
...count,
40+
};
41+
3942
const { show, ...rest } = mergedConfig!;
4043

4144
return {

src/interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export interface InputProps
114114
string
115115
>;
116116
onPressEnter?: KeyboardEventHandler<HTMLInputElement>;
117-
/** @deprecated Use `count.show` instead */
117+
/** It's better to use `count.show` instead */
118118
showCount?:
119119
| boolean
120120
| {

tests/count.test.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,20 @@ describe('Input.Count', () => {
110110

111111
expect(container.querySelector('.rc-input-out-of-range')).toBeTruthy();
112112
});
113+
114+
it('mix usage', () => {
115+
const { container } = render(
116+
<Input
117+
showCount
118+
count={{
119+
max: 10,
120+
}}
121+
defaultValue="bamboo"
122+
/>,
123+
);
124+
expect(
125+
container.querySelector('.rc-input-show-count-suffix')?.textContent,
126+
).toEqual('6 / 10');
127+
});
113128
});
114129
});

0 commit comments

Comments
 (0)