Skip to content

Commit 8e8dad8

Browse files
megumi_imaimegumi_imai
megumi_imai
authored and
megumi_imai
committed
Close dropdown on clear button click in Bootstrap 5
1 parent 939e94b commit 8e8dad8

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

Diff for: js/bootstrap-select.js

+4
Original file line numberDiff line numberDiff line change
@@ -2663,6 +2663,10 @@
26632663

26642664
that.createView(false);
26652665
}
2666+
// toggle to close the dropdown if it is currently open
2667+
if (version.major > 4 && that.$menu.hasClass(classNames.SHOW)) {
2668+
that.$menu.removeClass(classNames.SHOW);
2669+
}
26662670
}
26672671

26682672
this.$button.on('click.bs.dropdown.data-api', function (e) {

Diff for: tests/bootstrap4.html

+13
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,19 @@
326326
</select>
327327
</div>
328328
</div>
329+
330+
<hr>
331+
<div class="form-group row">
332+
<label class="col-lg-4 control-label">allow clear and prevent menu open</label>
333+
<div class="col-lg-8">
334+
<select id="allow-clear" class="selectpicker" data-allow-clear="true">
335+
<option>One</option>
336+
<option>Two</option>
337+
<option>Three</option>
338+
</select>
339+
</div>
340+
</div>
341+
329342
</div>
330343

331344
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

Diff for: tests/bootstrap5.html

+13
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,19 @@ <h5>Set the title attribute on options to display alternative text when the opti
336336
</select>
337337
</div>
338338
</div>
339+
340+
<hr>
341+
<div class="form-group row">
342+
<label class="col-lg-4 control-label">allow clear and prevent menu open</label>
343+
<div class="col-lg-8">
344+
<select id="allow-clear" class="selectpicker" data-allow-clear="true">
345+
<option>One</option>
346+
<option>Two</option>
347+
<option>Three</option>
348+
</select>
349+
</div>
350+
</div>
351+
339352
</div>
340353

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

0 commit comments

Comments
 (0)