davidstutz / bootstrap-multiselect

JQuery multiselect plugin based on Twitter Bootstrap.
https://davidstutz.github.io/bootstrap-multiselect/
Other
3.67k stars 1.98k forks source link

Collapsible arrow(caret) is not changing open/close state #1210

Open Amitesh opened 3 years ago

Amitesh commented 3 years ago

In enableCollapsibleOptGroups option, the open/close caret is not changing it's state on the collapse of options below.

In below image we can see the caret state is same in open/close of group options.

Screen Shot 2021-08-15 at 4 28 53 PM

How we can align it with its state?

Thanks

Amitesh commented 3 years ago

I tried the below solution to fix it.

$(document).ready(function() {
  $('#example-enableCollapsibleOptGroups-new').multiselect({
    enableCollapsibleOptGroups: true
  });

  enhanceCollapsibleButton();
});

function enhanceCollapsibleButton() {
  $('#example-enableCollapsibleOptGroups-new').parent()
    .find('.multiselect-container .caret-container')
    .addClass('open');

  $('#example-enableCollapsibleOptGroups-new').parent()
    .find('.multiselect-container .caret-container')
    .click(function() {
      $(this).toggleClass('open close');
    });
}

Styles:

.multiselect-container .caret-container {
  position: relative;
  cursor: pointer;
}

.multiselect-container .caret-container.open,
.multiselect-container .caret-container.close {
  float: none;
  height: initial;
  width: initial;
  font-size: 1rem;
  padding: 0px 8px;
}

.multiselect-container .caret-container::after {
  display: block;
  position: absolute;
  top: 50%;
  right: -4px;
  -webkit-transform: translateY(-50%) rotate(0deg);
  transform: translateY(-50%) rotate(0deg);
  font-size: 1rem;
  transition: transform 0.2s;
}

.multiselect-container .caret-container.close::after {
  -webkit-transform: translateY(-50%) rotate(-90deg);
  transform: translateY(-50%) rotate(-90deg);
}

Stackblitz url - https://stackblitz.com/edit/bootstrap-multiselect-group-example

I hope this will be helpful.