Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/BaseSelect/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { AlignType, BuildInPlacements } from '@rc-component/trigger';
import { clsx } from 'clsx';
import { getDOM, isNonNullable, useEvent } from '@rc-component/util';
import { getDOM, isNonNullable, isReactRenderable, useEvent } from '@rc-component/util';
import type { ScrollConfig, ScrollTo } from '@rc-component/virtual-list';
import * as React from 'react';
import { useAllowClear } from '../hooks/useAllowClear';
Expand Down Expand Up @@ -360,7 +360,7 @@ const BaseSelect = React.forwardRef<BaseSelectRef, BaseSelectProps>((props, ref)

// ============================== Open ==============================
// Not trigger `open` when `notFoundContent` is empty
const emptyListContent = !notFoundContent && emptyOptions;
const emptyListContent = !isReactRenderable(notFoundContent) && emptyOptions;

const [rawOpen, mergedOpen, triggerOpen, lockOptions] = useOpen(
defaultOpen || false,
Expand Down
8 changes: 5 additions & 3 deletions src/OptionList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { clsx } from 'clsx';
import { KeyCode, omit, pickAttrs, useMemo } from '@rc-component/util';
import { isReactRenderable, KeyCode, omit, pickAttrs, useMemo } from '@rc-component/util';
import List, { type ListRef, type ScrollConfig } from '@rc-component/virtual-list';
import * as React from 'react';
import { useEffect } from 'react';
Expand Down Expand Up @@ -446,10 +446,12 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
const mergedLabel = getLabel(item);

const iconVisible =
!menuItemSelectedIcon || typeof menuItemSelectedIcon === 'function' || selected;
!isReactRenderable(menuItemSelectedIcon) ||
typeof menuItemSelectedIcon === 'function' ||
selected;

// https://github.com/ant-design/ant-design/issues/34145
const content = typeof mergedLabel === 'number' ? mergedLabel : mergedLabel || value;
const content = isReactRenderable(mergedLabel) ? mergedLabel : value;
// https://github.com/ant-design/ant-design/issues/26717
let optionTitle = isTitleType(content) ? content.toString() : undefined;
if (title !== undefined) {
Expand Down
5 changes: 1 addition & 4 deletions src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,7 @@ const Select = React.forwardRef<BaseSelectRef, SelectProps<any, DefaultOptionTyp
// https://github.com/ant-design/ant-design/issues/25057
if (!mode && mergedValues.length === 1) {
const firstValue = mergedValues[0];
if (
firstValue.value === null &&
(firstValue.label === null || firstValue.label === undefined)
) {
if (firstValue.value === null && !isNonNullable(firstValue.label)) {
return [];
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/SelectInput/Content/SingleContent.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { isNonNullable } from '@rc-component/util';
import { clsx } from 'clsx';
import Input from '../Input';
import { useSelectInputContext } from '../context';
Expand Down Expand Up @@ -64,10 +65,7 @@ const SingleContent = React.forwardRef<HTMLInputElement, SharedContentProps>(

// ========================== Render ==========================
const showHasValueCls =
displayValue &&
displayValue.label !== null &&
displayValue.label !== undefined &&
String(displayValue.label).trim() !== '';
displayValue && isNonNullable(displayValue.label) && String(displayValue.label).trim() !== '';

// Render value
// Only render value when not using custom input in combobox mode
Expand Down
37 changes: 37 additions & 0 deletions tests/renderability.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';
import { render } from '@testing-library/react';
import Select from '../src';

it('opens an empty dropdown containing zero', () => {
const { baseElement } = render(<Select open options={[]} notFoundContent={0} />);
expect(baseElement.querySelector('.rc-select-item-empty').textContent).toBe('0');
});

it('only renders a zero selection icon on selected options', () => {
const { baseElement } = render(
<Select
open
mode="multiple"
value={['a']}
virtual={false}
menuItemSelectedIcon={0}
options={[
{ value: 'a', label: 'A' },
{ value: 'b', label: 'B' },
]}
/>,
);
expect(baseElement.querySelectorAll('.rc-select-item-option-state')).toHaveLength(1);
expect(
baseElement.querySelector('.rc-select-item-option-selected .rc-select-item-option-state')
.textContent,
).toBe('0');
});

it('keeps a zero option label in the dropdown and selected value', () => {
const { container, baseElement } = render(
<Select open value="a" options={[{ value: 'a', label: 0 }]} />,
);
expect(baseElement.querySelector('.rc-select-item-option-content').textContent).toBe('0');
expect(container.querySelector('.rc-select-content-has-value')).toBeTruthy();
});
Loading