From 51035ee4c4df5d7924cd9e8f0efccbac4eaa1055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Thu, 3 Mar 2022 14:39:12 +0800 Subject: [PATCH] fix: not crash on string value (#251) --- src/Cascader.tsx | 2 +- tests/index.spec.tsx | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Cascader.tsx b/src/Cascader.tsx index dea1fdb4..7ea4597c 100644 --- a/src/Cascader.tsx +++ b/src/Cascader.tsx @@ -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((props, ref) => { diff --git a/tests/index.spec.tsx b/tests/index.spec.tsx index 488fb5ab..d1525ab2 100644 --- a/tests/index.spec.tsx +++ b/tests/index.spec.tsx @@ -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(); + }); });