Skip to content

Commit 7a70001

Browse files
committed
fix: preserve zero-valued suffix content
1 parent 507a041 commit 7a70001

2 files changed

Lines changed: 31 additions & 3 deletions

File tree

‎src/Input.tsx‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { clsx } from 'clsx';
2-
import { omit, triggerFocus, type InputFocusOptions } from '@rc-component/util';
2+
import {
3+
isReactRenderable,
4+
omit,
5+
triggerFocus,
6+
type InputFocusOptions,
7+
} from '@rc-component/util';
38
import React, {
49
forwardRef,
510
useEffect,
@@ -236,15 +241,16 @@ const Input = forwardRef<InputRef, InputProps>((props, ref) => {
236241

237242
const getSuffix = () => {
238243
// Max length value
239-
if (suffix || countConfig.show) {
244+
if (isReactRenderable(suffix) || countConfig.show) {
240245
return (
241246
<>
242247
{countConfig.show && (
243248
<span
244249
className={clsx(
245250
`${prefixCls}-show-count-suffix`,
246251
{
247-
[`${prefixCls}-show-count-has-suffix`]: !!suffix,
252+
[`${prefixCls}-show-count-has-suffix`]:
253+
isReactRenderable(suffix),
248254
},
249255
classNames?.count,
250256
)}

‎tests/renderability.test.tsx‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react';
2+
import { render } from '@testing-library/react';
3+
import Input from '../src';
4+
5+
describe('suffix renderability', () => {
6+
it('renders zero and applies the count suffix class', () => {
7+
const { container, rerender } = render(<Input suffix={0} />);
8+
expect(container.querySelector('.rc-input-suffix')).toHaveTextContent('0');
9+
rerender(<Input suffix={0} showCount />);
10+
expect(
11+
container.querySelector('.rc-input-show-count-has-suffix'),
12+
).toBeTruthy();
13+
});
14+
15+
it.each([null, undefined, false, ''])(
16+
'does not wrap an empty suffix %s',
17+
(suffix) => {
18+
const { container } = render(<Input suffix={suffix} />);
19+
expect(container.querySelector('.rc-input-suffix')).toBeNull();
20+
},
21+
);
22+
});

0 commit comments

Comments
 (0)