Skip to content

Commit

Permalink
Support different path length in Cascader (#1529)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpylua authored Nov 10, 2020
1 parent 719b915 commit bf903a8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
38 changes: 14 additions & 24 deletions packages/zent/src/cascader/demos/4.multiple.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ en-US:
import { MenuCascader } from 'zent';

class Simple extends React.Component {

state = {
value: [
['330000', '330100', '330106'],
Expand All @@ -50,8 +49,8 @@ class Simple extends React.Component {
{
value: '330107',
label: '{i18n.yh}',
}
]
},
],
},
{
value: '330200',
Expand All @@ -60,10 +59,10 @@ class Simple extends React.Component {
{
value: '330206',
label: '{i18n.lw}',
}
]
}
]
},
],
},
],
},
{
value: '120000',
Expand All @@ -72,24 +71,18 @@ class Simple extends React.Component {
{
value: '120100',
label: '{i18n.be}',
children: [
{
value: '120111',
label: '{i18n.al}'
}
]
}
]
}
]
}
},
],
},
],
};

onChange = (value, selectedOptions, meta) => {
console.log(value, selectedOptions, meta)
console.log(value, selectedOptions, meta);
this.setState({
value,
});
}
};

render() {
return (
Expand All @@ -104,8 +97,5 @@ class Simple extends React.Component {
}
}

ReactDOM.render(
<Simple />
, mountNode
);
ReactDOM.render(<Simple />, mountNode);
```
7 changes: 6 additions & 1 deletion packages/zent/src/cascader/forest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,12 @@ export class Forest {
const { value } = startNode;

return this.reducePath((acc, path) => {
if (path[idx].value === value && (!predicate || predicate(path))) {
// Paths may have different lengths
if (
path.length > idx &&
path[idx].value === value &&
(!predicate || predicate(path))
) {
acc.push(path);
}

Expand Down

0 comments on commit bf903a8

Please sign in to comment.