[Vuejs]-Bootstrap Vue Animate Dropdowns

0👍

It’s pretty hard to achieve a clean slide-up/down animation because BootstrapVue uses display:none/block to hide/show the dropdown menu. What you can do it’s manipulate the max-height of the element as explained here.

I added an ‘animated’ class to the parent element, for example your b-navbar to select which dropdown has to be animated. Then i removed display: none from the default status of the dropdown and hidden it setting its max-height and padding to 0 and its border to none. When you click the button the dropdown gets the class ‘show’so you can give it a max-height different than 0, as explained in the answer i’ve linked to you, you have to set it higher than the actual height of the dropdown menu otherwise it gets cropped out.

.animated {
    .dropdown-menu {
        overflow: hidden;
        display: block!important;
        max-height: 0!important;
        &:not(.show) {
            padding: 0;
            border: none;
        }
        &.show {
            transition: max-height 300ms ease-in-out;
            max-height: 500px!important; //this must have to be higher than the max height of the dropdown list
        }
    }
}

0👍

Just came across this same issue.

Ended up following with previous example, but this one works for both up/down transitions and doesn’t mess with overflows in case you want to add triangles.

.dropdown-menu {
    border: 1px solid #ebeef5;
    box-shadow: 0 5px 25px 0 rgba(0, 0, 0, 0.25);

    // Slide down transtion

    display: block !important;

    &:not(.show) {
        padding: 0px;
        border-width: 0px;
        border-color: transparent;
        box-shadow: none;

        transition: padding 1.3s ease, border-width 1.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
    }

    > li {
        max-height: 0px;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }

    &.show {
        > li {
            max-height: 100px;
        }
    }

    // Add chevron to top

    &[x-placement^="bottom"] {
        &::before {
            content:"";
            position: absolute;
            right: 11px;
            top: -5px;
            width: 0;
            height: 0;
            border-style: solid;
            border-width: 0 5px 5px 5px;
            border-color: transparent transparent #fff transparent;
            z-index: 99999999;
        }
    }

    // Add chevron to bottom

    &[x-placement^="top"] {
        &::after {
            content:"";
            position: absolute;
            right: 11px;
            bottom: -5px;
            width: 0;
            height: 0;
            border-style: solid;
            border-width: 5px 5px 0 5px;
            border-color: #fff transparent transparent transparent;
            z-index: 99999999;
        }
    }
}

Leave a comment