Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/SelectInput/Content/SingleContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const SingleContent = React.forwardRef<HTMLInputElement, SharedContentProps>(

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(() => {
Expand All @@ -34,7 +35,7 @@ const SingleContent = React.forwardRef<HTMLInputElement, SharedContentProps>(
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;
Expand All @@ -43,7 +44,7 @@ const SingleContent = React.forwardRef<HTMLInputElement, SharedContentProps>(
}
}

if (displayValue && !titleValue) {
if (hasDisplayValue && !titleValue) {
titleValue = getTitle(displayValue);
}

Expand All @@ -64,7 +65,7 @@ const SingleContent = React.forwardRef<HTMLInputElement, SharedContentProps>(

// ========================== Render ==========================
// Render value
const renderValue = displayValue ? (
const renderValue = hasDisplayValue ? (
hasOptionStyle ? (
<div
className={clsx(`${prefixCls}-content-value`, optionClassName)}
Expand All @@ -88,7 +89,7 @@ const SingleContent = React.forwardRef<HTMLInputElement, SharedContentProps>(
<div
className={clsx(
`${prefixCls}-content`,
displayValue && `${prefixCls}-content-has-value`,
hasDisplayValue && `${prefixCls}-content-has-value`,
mergedSearchValue && `${prefixCls}-content-has-search-value`,
hasOptionStyle && `${prefixCls}-content-has-option-style`,
classNames?.content,
Expand Down
7 changes: 7 additions & 0 deletions tests/placeholder.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,11 @@ describe('Select placeholder', () => {
});
expect(container.querySelector('.rc-select-placeholder').textContent).toBe('placeholder');
});

it('should have content-has-value class when value is empty string', () => {
const { container } = render(
<Select value="" placeholder="placeholder" options={[{ value: '', label: '' }]} />,
);
expect(container.querySelector('.rc-select-content-has-value')).toBeTruthy();
});
});
Loading