From 9d7249e4bc95b4a1cc941f4a518b9f8f8b34db9b Mon Sep 17 00:00:00 2001 From: Oleksiy Kachynskyy Date: Fri, 20 Mar 2020 13:40:29 +0200 Subject: [PATCH] fix: update collapseAll method to avoid collapsing whole object/array --- src/components/JsonViewer/JsonViewer.tsx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/components/JsonViewer/JsonViewer.tsx b/src/components/JsonViewer/JsonViewer.tsx index bf735299..95f4ce94 100644 --- a/src/components/JsonViewer/JsonViewer.tsx +++ b/src/components/JsonViewer/JsonViewer.tsx @@ -57,11 +57,10 @@ class Json extends React.PureComponent { collapseAll = () => { const elements = this.node.getElementsByClassName('collapsible'); - for (const expanded of Array.prototype.slice.call(elements)) { - // const collapsed = elements[i]; - if ((expanded.parentNode as Element)!.classList.contains('redoc-json')) { - continue; - } + // skip first item to avoid collapsing whole object/array + const elementsArr = Array.prototype.slice.call(elements).slice(1); + + for (const expanded of elementsArr) { (expanded.parentNode as Element)!.classList.add('collapsed'); } };