Add onExpand callback

This commit is contained in:
Ann Balina 2020-11-19 22:21:38 +02:00
parent c980eadec7
commit 779abfb2fa
2 changed files with 6 additions and 0 deletions

View File

@ -95,6 +95,7 @@ interface Props extends CircularPropsPassedThroughJSONNestedNode {
nodeTypeIndicator: string; nodeTypeIndicator: string;
createItemString: (data: any, collectionLimit: number) => string; createItemString: (data: any, collectionLimit: number) => string;
expandable: boolean; expandable: boolean;
onExpand?: () => void;
} }
interface State { interface State {
@ -131,6 +132,7 @@ export default class JSONNestedNode extends React.Component<Props, State> {
sortObjectKeys: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]), sortObjectKeys: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]),
isCircular: PropTypes.bool, isCircular: PropTypes.bool,
expandable: PropTypes.bool, expandable: PropTypes.bool,
onExpand: PropTypes.func
}; };
static defaultProps = { static defaultProps = {
@ -234,6 +236,9 @@ export default class JSONNestedNode extends React.Component<Props, State> {
handleClick = () => { handleClick = () => {
if (this.props.expandable) { if (this.props.expandable) {
if (this.props.onExpand && this.state.expanded) {
this.props.onExpand();
}
this.setState({ expanded: !this.state.expanded }); this.setState({ expanded: !this.state.expanded });
} }
}; };

View File

@ -20,6 +20,7 @@ interface Props extends CircularPropsPassedThroughJSONTree {
data: any; data: any;
theme?: Theme; theme?: Theme;
invertTheme: boolean; invertTheme: boolean;
onExpand?: () => void;
} }
interface State { interface State {