Skip to content

Commit

Permalink
fix(checkbox): render 0 number option as string (#2925)
Browse files Browse the repository at this point in the history
  • Loading branch information
NWYLZW authored May 25, 2024
1 parent 0122e61 commit 2c50854
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/checkbox/CheckboxGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,17 @@ const CheckboxGroup = <T extends CheckboxGroupValue = CheckboxGroupValue>(props:
<CheckContext.Provider value={context}>
{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 (
<Checkbox key={index} label={vs} value={vs}>
<Checkbox key={index} label={v} value={v}>
{v}
</Checkbox>
);
}
case 'number': {
const vs = v as number;
return (
<Checkbox key={index} label={vs} value={vs}>
{v}
<Checkbox key={index} label={v} value={v}>
{String(v)}
</Checkbox>
);
}
Expand Down
4 changes: 4 additions & 0 deletions src/checkbox/__tests__/checkbox.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,17 @@ describe('CheckboxGroup', () => {
{ value: '广州', label: '广州', disabled: true },
{ value: '北京', label: '北京', name: '北京' },
1,
0,
'重庆',
{ label: '全选', checkAll: true },
]}
></Checkbox.Group>,
);
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', () => {
Expand Down

0 comments on commit 2c50854

Please sign in to comment.