From e664cba9fbedf580882ca0fc35b1788f0b9f1d56 Mon Sep 17 00:00:00 2001 From: lucataglia Date: Fri, 19 May 2023 18:56:26 +0200 Subject: [PATCH] bugfix on corner case --- packages/react-json-tree/src/JSONNestedNode.tsx | 6 ++++-- packages/react-json-tree/src/index.tsx | 1 + packages/react-json-tree/src/types.ts | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/react-json-tree/src/JSONNestedNode.tsx b/packages/react-json-tree/src/JSONNestedNode.tsx index 2f035e38..fe82a169 100644 --- a/packages/react-json-tree/src/JSONNestedNode.tsx +++ b/packages/react-json-tree/src/JSONNestedNode.tsx @@ -111,8 +111,9 @@ export default function JSONNestedNode(props: Props) { nodeTypeIndicator, shouldExpandNodeInitially, shouldExpandNode, - styling, + setShouldExpandNode, setEnableDefaultButton, + styling, } = props; const [expanded, setExpanded] = useState( @@ -135,8 +136,9 @@ export default function JSONNestedNode(props: Props) { if (expandable) { setExpanded(!expanded); setEnableDefaultButton(true); + setShouldExpandNode(undefined) } - }, [expandable, expanded, setEnableDefaultButton]); + }, [expandable, expanded, setEnableDefaultButton, setShouldExpandNode]); const renderedChildren = expanded || (hideRoot && level === 0) diff --git a/packages/react-json-tree/src/index.tsx b/packages/react-json-tree/src/index.tsx index 9b5a6d68..9ba8d18b 100644 --- a/packages/react-json-tree/src/index.tsx +++ b/packages/react-json-tree/src/index.tsx @@ -79,6 +79,7 @@ export function JSONTree({ shouldExpandNodeInitially={shouldExpandNodeInitially} shouldExpandNode={shouldExpandNode} setEnableDefaultButton={setEnableDefaultButton} + setShouldExpandNode={setShouldExpandNode} hideRoot={hideRoot} getItemString={getItemString} postprocessValue={postprocessValue} diff --git a/packages/react-json-tree/src/types.ts b/packages/react-json-tree/src/types.ts index 27e4f806..71943a35 100644 --- a/packages/react-json-tree/src/types.ts +++ b/packages/react-json-tree/src/types.ts @@ -54,6 +54,7 @@ export interface CommonExternalProps { collectionLimit: number; sortObjectKeys: SortObjectKeys; setEnableDefaultButton: any; + setShouldExpandNode: any; } export interface CommonInternalProps extends CommonExternalProps {