Skip to content

Commit

Permalink
fix: mix logic (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ authored Sep 28, 2023
1 parent 117dd80 commit db5525c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
21 changes: 12 additions & 9 deletions src/hooks/useCount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,20 @@ export default function useCount(
showCount?: InputProps['showCount'],
) {
return React.useMemo<ForcedCountConfig>(() => {
let mergedConfig = count;

if (!count) {
mergedConfig = {
show:
typeof showCount === 'object' && showCount.formatter
? showCount.formatter
: !!showCount,
};
let mergedConfig: CountConfig = {};

if (showCount) {
mergedConfig.show =
typeof showCount === 'object' && showCount.formatter
? showCount.formatter
: !!showCount;
}

mergedConfig = {
...mergedConfig,
...count,
};

const { show, ...rest } = mergedConfig!;

return {
Expand Down
2 changes: 1 addition & 1 deletion src/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export interface InputProps
string
>;
onPressEnter?: KeyboardEventHandler<HTMLInputElement>;
/** @deprecated Use `count.show` instead */
/** It's better to use `count.show` instead */
showCount?:
| boolean
| {
Expand Down
15 changes: 15 additions & 0 deletions tests/count.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,20 @@ describe('Input.Count', () => {

expect(container.querySelector('.rc-input-out-of-range')).toBeTruthy();
});

it('mix usage', () => {
const { container } = render(
<Input
showCount
count={{
max: 10,
}}
defaultValue="bamboo"
/>,
);
expect(
container.querySelector('.rc-input-show-count-suffix')?.textContent,
).toEqual('6 / 10');
});
});
});

0 comments on commit db5525c

Please sign in to comment.