Script

var toggle = new Toggle({
  blur: true,
  buttonClassExpanded: 'toggle-btn-active',
  buttonSelector: 'a',
  parentClass: 'toggle-parent',
  singleSibling: true,
  targetSelector: '.menu ul ul'
})

HTML

<nav class="menu">
  <ul>
    <li>
      <a href="#">Pie</a>
      <ul>
        <li><a href="#">Apple Pie</a></li>
        <li>
          <a href="#">Cherry Pie</a>
          <ul>
            <li><a href="#">With Pastry Crust</a></li>
            <li><a href="#">With Graham Cracker Crust</a></li>
          </ul>
        </li>
        <li><a href="#">Pumpkin Pie</a></li>
        <li><a href="#">Chocolate Pie</a></li>
      </ul>
    </li>
    <li>
      <a href="#">Cake</a>
      <ul>
        <li>
          <a href="#">Vanilla Cake</a>
          <ul>
            <li><a href="#">With Vanilla Icing</a></li>
            <li><a href="#">With Chocolate Icing</a></li>
            <li><a href="#">With Sprinkles</a></li>
          </ul>
        </li>
        <li><a href="#">Chocolate Cake</a></li>
        <li><a href="#">Fruit Cake</a></li>
      </ul>
    </li>
    <li><a href="#">Ice Cream</a></li>
  </ul>
</nav>

CSS

/* Hide collapsed */
[aria-expanded="false"] {
  display: none;
}

/* Horizontal menu */
.menu > ul > li {
  display: inline-block;
}

/* Dropdown menus */
.toggle-parent {
  position: relative;
}
.toggle-parent > ul {
  left: 0;
  position: absolute;
  top: 100%;
}

/* Deep dropdown menus (pop-out right) */
.toggle-parent .toggle-parent > ul {
  left: 100%;
  top: 0;
}

/* Add icon to parents */
.toggle-parent > a::after {
  content: '\f107'; /* Font Awesome 'angle-down' */
  display: inline-block;
  font-family: 'FontAwesome';
  margin-left: 0.5rem;
  transition: transform 0.3s ease;
}

/* Add different icon to deep parents */
.toggle-parent .toggle-parent > a::after {
  content: '\f105'; /* Font Awesome 'angle-right' */
}

/* Flip the icon */
.toggle-parent > a.toggle-btn-active::after {
  transform: rotate(180deg);
}