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( +