Skip to content

Commit e8cdfab

Browse files
authored
fix: should display text properly if text is number 0 (#718)
1 parent 64c9ff5 commit e8cdfab

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed

src/OptionList.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,8 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, OptionListP
3131
_,
3232
ref,
3333
) => {
34-
const {
35-
prefixCls,
36-
id,
37-
open,
38-
multiple,
39-
searchValue,
40-
toggleOpen,
41-
notFoundContent,
42-
onPopupScroll,
43-
} = useBaseProps();
34+
const { prefixCls, id, open, multiple, searchValue, toggleOpen, notFoundContent, onPopupScroll } =
35+
useBaseProps();
4436
const {
4537
flattenOptions,
4638
onActiveValue,
@@ -306,7 +298,8 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, OptionListP
306298
const iconVisible =
307299
!menuItemSelectedIcon || typeof menuItemSelectedIcon === 'function' || selected;
308300

309-
const content = mergedLabel || value;
301+
// https://github.com/ant-design/ant-design/issues/34145
302+
const content = typeof mergedLabel === 'number' ? mergedLabel : mergedLabel || value;
310303
// https://github.com/ant-design/ant-design/issues/26717
311304
let optionTitle =
312305
typeof content === 'string' || typeof content === 'number'

tests/Select.test.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,25 @@ describe('Select.Basic', () => {
506506
jest.useRealTimers();
507507
});
508508

509+
it('should render 0 as text properly', () => {
510+
const data = [
511+
{ text: 0, value: '=0' },
512+
{ text: 1, value: '=1' },
513+
];
514+
515+
const wrapper = mount(
516+
<Select style={{ width: 120 }} open>
517+
{data.map((d) => (
518+
<Select.Option value={d.value} key={d.value}>
519+
{d.text}
520+
</Select.Option>
521+
))}
522+
</Select>,
523+
);
524+
525+
expect(wrapper.find('.rc-select-item-option-content').first().text()).toEqual('0');
526+
});
527+
509528
describe('focus', () => {
510529
let handleFocus;
511530
let wrapper;

0 commit comments

Comments
 (0)