From 830371b5d1edf4ba7a138b3b3d78148d020e0349 Mon Sep 17 00:00:00 2001 From: Oleksiy Kachynskyy Date: Fri, 20 Mar 2020 15:05:07 +0200 Subject: [PATCH] fix: do not collapse top level on Collapse All in json samples (#1209) * fix: update collapseAll method to avoid collapsing whole object/array * fix: remove extra "slice()" call --- 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..d42c9df7 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, 1); + + for (const expanded of elementsArr) { (expanded.parentNode as Element)!.classList.add('collapsed'); } };