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
6 changes: 5 additions & 1 deletion src/SelectInput/Content/SingleContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ const SingleContent = React.forwardRef<HTMLInputElement, SharedContentProps>(
<div
className={clsx(
`${prefixCls}-content`,
displayValue && displayValue.label && `${prefixCls}-content-has-value`,
displayValue &&
displayValue.label !== null &&
displayValue.label !== undefined &&
displayValue.label !== '' &&
Comment on lines +92 to +94
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The condition to check for null and undefined can be simplified. Using the loose inequality operator != null checks for both null and undefined and is a common JavaScript idiom for this purpose. This makes the code more concise.

Suggested change
displayValue.label !== null &&
displayValue.label !== undefined &&
displayValue.label !== '' &&
displayValue.label != null && displayValue.label !== '' &&

`${prefixCls}-content-has-value`,
mergedSearchValue && `${prefixCls}-content-has-search-value`,
hasOptionStyle && `${prefixCls}-content-has-option-style`,
classNames?.content,
Expand Down
10 changes: 10 additions & 0 deletions tests/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,16 @@ describe('Select.Basic', () => {
expect(container.querySelector('.rc-select-content-has-value')).toBeFalsy();
});

it('should add -content-has-value className when value is number 0', () => {
const { container } = render(
<Select value={0}>
<Option value={0}>0</Option>
<Option value="1">1</Option>
</Select>,
);
expect(container.querySelector('.rc-select-content-has-value')).toBeTruthy();
});

it('should default select the right option', () => {
const { container } = render(
<Select defaultValue="2">
Expand Down
Loading