JSFiddle - React, Tailwind, and code Playground

by _sir

HTML

<p>Step instructions</p>
<button class="raaccordion">What can go wrong</button>
<div class="rapanel">
  <p>Description 1</p>
  <button class="raaccordion">Solution 1</button>
  <div class="nestedrapanel">
    <p>Description</p>
  </div>
  <p>Description 2</p>
  <button class="raaccordion">Solution 2</button>
  <div class="nestedrapanel">
    <p>Description</p>
  </div>
</div>

CSS

button.raaccordion {
  background-color: #0099d8;
  color: #FFFFFF;
  cursor: pointer;
  padding: 10px;
  width: 100%;
  border: none;
  border-radius: 8px;
  text-align: center;
  outline: none;
  font-size: 15px;
  transition: 0.4s;
  margin-top: 0px;
  margin-bottom: 0px;
}

button.raaccordion.active,
button.raaccordion:hover {
  background-color: #0087bf;
}

div.rapanel {
  padding: 0 18px;
  background-color: #EBEBEB;
  border-radius: 8px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease-out;
  border-style: none;
  border-color: #535556;
  margin-top: 2px;
  margin-bottom: 2px;
}

div.nestedrapanel {
  padding: 0 18px;
  background-color: #d2d2d2;
  border-radius: 8px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease-out;
  border-style: none;
  border-color: #535556;
  margin-top: 2px;
  margin-bottom: 2px;
}

button.raaccordion:after {
  content: '\002B';
  color: #FFF;
  font-weight: bold;
  float: right;
  margin-left: 5px;
}

button.raaccordion.active:after {
  content: "\2212";
  color: #FFF;
  font-weight: bold;
  float: right;
  margin-left: 5px;
}

JavaScript

var acc = document.getElementsByClassName("raaccordion");
var i;

for (i = 0; i < acc.length; i++) {
  acc[i].onclick = function() {
    this.classList.toggle("active");
    var panel = this.nextElementSibling;
    if (panel.style.maxHeight) {
      panel.style.maxHeight = null;
    } else {
      panel.style.maxHeight = panel.scrollHeight + "px";
    }
  }
}