From 2c5085487e2eff756cb5577c0606fddbe20bb931 Mon Sep 17 00:00:00 2001 From: YiJie <51358815+NWYLZW@users.noreply.github.com> Date: Sat, 25 May 2024 14:48:55 +0800 Subject: [PATCH] fix(checkbox): render `0` number option as string (#2925) --- src/checkbox/CheckboxGroup.tsx | 14 +++++--------- src/checkbox/__tests__/checkbox.test.tsx | 4 ++++ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/checkbox/CheckboxGroup.tsx b/src/checkbox/CheckboxGroup.tsx index a80f3608ff..9427761f93 100644 --- a/src/checkbox/CheckboxGroup.tsx +++ b/src/checkbox/CheckboxGroup.tsx @@ -152,21 +152,17 @@ const CheckboxGroup = (props: {useOptions ? options.map((v: any, index) => { - const type = typeof v; - switch (type) { - case 'string': { - const vs = v as string; + switch (typeof v) { + case 'string': return ( - + {v} ); - } case 'number': { - const vs = v as number; return ( - - {v} + + {String(v)} ); } diff --git a/src/checkbox/__tests__/checkbox.test.tsx b/src/checkbox/__tests__/checkbox.test.tsx index 9a2a7b2d14..c73dc64044 100644 --- a/src/checkbox/__tests__/checkbox.test.tsx +++ b/src/checkbox/__tests__/checkbox.test.tsx @@ -76,6 +76,7 @@ describe('CheckboxGroup', () => { { value: '广州', label: '广州', disabled: true }, { value: '北京', label: '北京', name: '北京' }, 1, + 0, '重庆', { label: '全选', checkAll: true }, ]} @@ -83,6 +84,9 @@ describe('CheckboxGroup', () => { ); fireEvent.click(container.firstChild.lastChild); expect(container.firstChild.firstChild).toHaveClass('t-is-checked'); + const options = container.firstChild.childNodes; + // 0 is rendered as string '0' + expect(options.item(4).textContent).toBe('0'); }); test('value is string', () => {