From 810313b5d3e3853a811634c62b2205d73c01f751 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Fri, 13 Feb 2026 01:22:13 +0800 Subject: [PATCH] fix: use strict null/undefined check for display value in single select Empty string values should be treated as valid values (having a display value), not as missing values. This fixes the content-has-value class not being applied when the value is an empty string. Co-Authored-By: Claude Opus 4.6 --- src/SelectInput/Content/SingleContent.tsx | 9 +++++---- tests/placeholder.test.tsx | 7 +++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/SelectInput/Content/SingleContent.tsx b/src/SelectInput/Content/SingleContent.tsx index 3a731a38..d5237f8c 100644 --- a/src/SelectInput/Content/SingleContent.tsx +++ b/src/SelectInput/Content/SingleContent.tsx @@ -19,6 +19,7 @@ const SingleContent = React.forwardRef( const combobox = mode === 'combobox'; const displayValue = displayValues[0]; + const hasDisplayValue = displayValue !== null && displayValue !== undefined; // Implement the same logic as the old SingleSelector const mergedSearchValue = React.useMemo(() => { @@ -34,7 +35,7 @@ const SingleContent = React.forwardRef( let style: React.CSSProperties | undefined; let titleValue: string | undefined; - if (displayValue && selectContext?.flattenOptions) { + if (hasDisplayValue && selectContext?.flattenOptions) { const option = selectContext.flattenOptions.find((opt) => opt.value === displayValue.value); if (option?.data) { className = option.data.className; @@ -43,7 +44,7 @@ const SingleContent = React.forwardRef( } } - if (displayValue && !titleValue) { + if (hasDisplayValue && !titleValue) { titleValue = getTitle(displayValue); } @@ -64,7 +65,7 @@ const SingleContent = React.forwardRef( // ========================== Render ========================== // Render value - const renderValue = displayValue ? ( + const renderValue = hasDisplayValue ? ( hasOptionStyle ? (
(
{ }); expect(container.querySelector('.rc-select-placeholder').textContent).toBe('placeholder'); }); + + it('should have content-has-value class when value is empty string', () => { + const { container } = render( +