Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close dropdown on clear button click in Bootstrap 5 #2878

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions js/bootstrap-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -2663,6 +2663,10 @@

that.createView(false);
}
// toggle to close the dropdown if it is currently open
if (version.major > 4 && that.$menu.hasClass(classNames.SHOW)) {
that.$menu.removeClass(classNames.SHOW);
}
}

this.$button.on('click.bs.dropdown.data-api', function (e) {
Expand Down
13 changes: 13 additions & 0 deletions tests/bootstrap4.html
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,19 @@
</select>
</div>
</div>

<hr>
<div class="form-group row">
<label class="col-lg-4 control-label">allow clear and prevent menu open</label>
<div class="col-lg-8">
<select id="allow-clear" class="selectpicker" data-allow-clear="true">
<option>One</option>
<option>Two</option>
<option>Three</option>
</select>
</div>
</div>

</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
Expand Down
13 changes: 13 additions & 0 deletions tests/bootstrap5.html
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,19 @@ <h5>Set the title attribute on options to display alternative text when the opti
</select>
</div>
</div>

<hr>
<div class="form-group row">
<label class="col-lg-4 control-label">allow clear and prevent menu open</label>
<div class="col-lg-8">
<select id="allow-clear" class="selectpicker" data-allow-clear="true">
<option>One</option>
<option>Two</option>
<option>Three</option>
</select>
</div>
</div>

</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
Expand Down
Loading