diff --git a/.gitignore b/.gitignore index fcce11f..0d057cb 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,5 @@ xcuserdata yarn.lock package-lock.json _ts2js -es/ \ No newline at end of file +es/ +.vscode \ No newline at end of file diff --git a/src/Cascader.tsx b/src/Cascader.tsx index 2ade0a5..23bfb6a 100644 --- a/src/Cascader.tsx +++ b/src/Cascader.tsx @@ -36,11 +36,7 @@ class Cascader extends React.Component { value[i] = data.value; } value.length = i; - if (!('value' in this.props)) { - this.setState({ - value, - }); - } + this.setState({ value }); if (this.props.onChange) { this.props.onChange(value); } diff --git a/tests/simple.spec.tsx b/tests/simple.spec.tsx index fe43218..6d12630 100644 --- a/tests/simple.spec.tsx +++ b/tests/simple.spec.tsx @@ -45,4 +45,15 @@ describe('simple', () => { div); instance.onValueChange(['02', '02-2'], 1); }); + + it('test cascade effect', () => { + + instance = ReactDOM.render( + , + div); + + instance.onValueChange(['02', '01-1'], 0); + + expect(instance.state.value).to.eql(['02', '02-1', '02-1-1']); + }); });