Skip to content

Commit

Permalink
fix: not crash on string value (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
zombieJ authored Mar 3, 2022
1 parent a15810e commit 51035ee
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Cascader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ function toRawValues(value: ValueType): SingleValueType[] {
return value;
}

return value.length === 0 ? [] : [value];
return (value.length === 0 ? [] : [value]).map(val => (Array.isArray(val) ? val : [val]));
}

const Cascader = React.forwardRef<CascaderRef, InternalCascaderProps>((props, ref) => {
Expand Down
4 changes: 4 additions & 0 deletions tests/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -892,4 +892,8 @@ describe('Cascader.Basic', () => {
wrapper.find(`li[data-path-key]`).at(1).simulate('click');
});
});

it('not crash when value type is not array', () => {
mount(<Cascader value={'bamboo' as any} />);
});
});

1 comment on commit 51035ee

@vercel
Copy link

@vercel vercel bot commented on 51035ee Mar 3, 2022

Choose a reason for hiding this comment

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

Please sign in to comment.