Skip to content

Commit

Permalink
Collapse component to add onChange event.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Nov 5, 2017
1 parent 56e4823 commit 6a12e81
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/collapse/Collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default class Collapse extends Component {
}
}
onItemClick(key) {
const { onChange } = this.props;
let activeKey = this.state.activeKey;
if (this.props.accordion) {
activeKey = activeKey[0] === key ? [] : [key];
Expand All @@ -35,7 +36,9 @@ export default class Collapse extends Component {
activeKey.push(key);
}
}
this.setState({ activeKey });
this.setState({ activeKey }, () => {
onChange && onChange(activeKey, this.props)
});
}
render() {
const { prefixCls, className, children, accordion, bordered, activeKey, showArrow, ...resetProps } = this.props;
Expand Down Expand Up @@ -74,6 +77,7 @@ Collapse.propTypes = {
prefixCls: PropTypes.string,
accordion: PropTypes.bool,
showArrow: PropTypes.bool,
onChange: PropTypes.func,
activeKey: PropTypes.oneOfType([
PropTypes.string,
PropTypes.arrayOf(PropTypes.string),
Expand Down

0 comments on commit 6a12e81

Please sign in to comment.