Skip to content

Commit 20d5ef1

Browse files
zombieJclaude
andauthored
fix: Select with `` value (#1207)
* Revert "fix: use strict null/undefined check for display value in single select (#1205)" This reverts commit f781118. * fix: check displayValue label before adding -content-has-value className Ensures the -content-has-value className is only added when displayValue has a truthy label property, preventing the class from being added when value is empty or null. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 95fea7c commit 20d5ef1

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/SelectInput/Content/SingleContent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const SingleContent = React.forwardRef<HTMLInputElement, SharedContentProps>(
8888
<div
8989
className={clsx(
9090
`${prefixCls}-content`,
91-
displayValue && `${prefixCls}-content-has-value`,
91+
displayValue && displayValue.label && `${prefixCls}-content-has-value`,
9292
mergedSearchValue && `${prefixCls}-content-has-search-value`,
9393
hasOptionStyle && `${prefixCls}-content-has-option-style`,
9494
classNames?.content,

tests/Select.test.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,15 @@ describe('Select.Basic', () => {
273273
expect(container.querySelector('.rc-select-content-has-option-style')).toBeTruthy();
274274
});
275275

276+
it('should not add -content-has-value className when value is empty string', () => {
277+
const { container } = render(
278+
<Select value="">
279+
<Option value="1">One</Option>
280+
</Select>,
281+
);
282+
expect(container.querySelector('.rc-select-content-has-value')).toBeFalsy();
283+
});
284+
276285
it('should default select the right option', () => {
277286
const { container } = render(
278287
<Select defaultValue="2">

0 commit comments

Comments
 (0)