Skip to content

Commit 01305bd

Browse files
committed
fix: handle number 0 as valid label in SingleContent
- Fix logic bug where number 0 was incorrectly excluded from has-value className - Update condition to explicitly check null, undefined, and empty string - Add test case for number 0 value display
1 parent 89c8e26 commit 01305bd

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/SelectInput/Content/SingleContent.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ const SingleContent = React.forwardRef<HTMLInputElement, SharedContentProps>(
8888
<div
8989
className={clsx(
9090
`${prefixCls}-content`,
91-
displayValue && displayValue.label && `${prefixCls}-content-has-value`,
91+
displayValue &&
92+
displayValue.label !== null &&
93+
displayValue.label !== undefined &&
94+
displayValue.label !== '' &&
95+
`${prefixCls}-content-has-value`,
9296
mergedSearchValue && `${prefixCls}-content-has-search-value`,
9397
hasOptionStyle && `${prefixCls}-content-has-option-style`,
9498
classNames?.content,

tests/Select.test.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,16 @@ describe('Select.Basic', () => {
282282
expect(container.querySelector('.rc-select-content-has-value')).toBeFalsy();
283283
});
284284

285+
it('should add -content-has-value className when value is number 0', () => {
286+
const { container } = render(
287+
<Select value={0}>
288+
<Option value={0}>0</Option>
289+
<Option value="1">1</Option>
290+
</Select>,
291+
);
292+
expect(container.querySelector('.rc-select-content-has-value')).toBeTruthy();
293+
});
294+
285295
it('should default select the right option', () => {
286296
const { container } = render(
287297
<Select defaultValue="2">

0 commit comments

Comments
 (0)