[Vuejs]-Can I use Bulma dropdown in Bulma tabs?

2👍

To get a dropdown working inside Bulma’s tabs, you need to adjust the overflow CSS in the tabs div. I’m not sure why I had to set overflow-x and overflow-y to get this working properly, but I did.

When the dropdown is active:

overflow-x : visible;
overflow-y : visible;

When the dropdown is not active, reset to their defaults:

overflow-y : hidden;
overflow-x : auto;
👤jeff m

1👍

Yes you can with a little amount of fiddling

There are mainly 2 problems :-

Problem 1

As bulma tabs container is flexbox, and the list of tabs are child of this flexbox, the dropdown will not be visible as it overflows out of flexbox container.
If you add overflow-y:visible to tabs container div, scrolling will happen which is not the behaviour we need

Solution

To fix this, the contents to be shown on tab selection should also come inside the tabs container as second child, so that dropdown button/link in list of
tabs has the space to show the dropdown when clicked/hovered.

#tab-container {
 flex-direction: column;
 height: 500px;
 width: 100%
}

#content-child {
 flex-grow: 1;
 width: 100%
}

#list-child {
 flex-grow: 0; //should be set to 0 as it will take up vertical space (it is set to 1 in bulma)
 width: 100%;
}

Problem 2

When dropdown is used within bulma tabs, the anchor tags in dropdown gets styled by those specified for anchor tags in tabs.This is one of the main issue.
The dropdown shown thus will be styled very differently.

Solution

Bulma dropdown also allows us to insert div inside.
We can make use of this to overcome problem 1.
Just add this css for divs inside dropdown so as to make it behave like links.

div.dropdown-item.is-active {
  background-color: rgba(55, 122, 195, 0.95);
  color: #fff;
}

div.dropdown-item {
  padding-right: 3rem;
  text-align: left;
  white-space: nowrap;
  width: 100%;
  cursor: pointer;
  text-decoration: none;
}

div.dropdown-item:hover {
  background-color: whitesmoke;
  color: #0a0a0a;
}

Complete solution can be seen below and you can change as required for your use case.

div.dropdown-item.is-active {
  background-color: rgba(55, 122, 195, 0.95);
  color: #fff;
}

div.dropdown-item {
  padding-right: 3rem;
  text-align: left;
  white-space: nowrap;
  width: 100%;
  cursor: pointer;
  text-decoration: none;
}

div.dropdown-item:hover {
  background-color: whitesmoke;
  color: #0a0a0a;
}

#content-child {
  flex-grow: 1;
  width: 100%
}

#tab-container {
  flex-direction: column;
  height: 500px;
  width: 100%
}

#list-child {
  flex-grow: 0;
  width: 100%;
}
<link href="https://cdn.jsdelivr.net/npm/bulma@0.8.1/css/bulma.min.css" rel="stylesheet" />


<div class="tabs is-boxed" id="tab-container">
  <ul id="list-child">
    <li><a>Pictures</a></li>
    <li><a>Music</a></li>
    <li><a>Videos</a></li>
    <li><a>Documents</a></li>
    <li class="dropdown is-active">
      <div class="dropdown-trigger">
        <a class="has-text-right custom-padding" aria-haspopup="true" aria-controls="dropdown-menu">
            Drop Down
          </a>
      </div>

      <div class="dropdown-menu" id="dropdown-menu" role="menu">
        <div class="dropdown-content">
          <div class="dropdown-item">Dropdown item</div>
          <div class="  dropdown-item">Other dropdown item</div>
          <div class="  dropdown-item is-active">Active dropdown item</div>
          <div class="  dropdown-item">Other dropdown item</div>
          <hr class="dropdown-divider" />
          <div class="  dropdown-item">With a divider</div>
        </div>
      </div>
    </li>
  </ul>
  <div id="content-child">
    content
  </div>
</div>
👤spc

Leave a comment