Skip to content

Commit

Permalink
fix: do not collapse top level on Collapse All in json samples (#1209)
Browse files Browse the repository at this point in the history
* fix: update collapseAll method
to avoid collapsing whole object/array

* fix: remove extra "slice()" call
  • Loading branch information
Oleksiy Kachynskyy authored Mar 20, 2020
1 parent c6eaa02 commit 830371b
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions src/components/JsonViewer/JsonViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@ class Json extends React.PureComponent<JsonProps> {

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');
}
};
Expand Down

0 comments on commit 830371b

Please sign in to comment.