This is an old question and from what I see it was posted given bootstrap 3. Still I am posting my use case just in case it helps someone else today.
I had a similar requirement for a bootstrap 4.5 drop down menu I have been working on. I needed some of drop down menu items to be inactive/disabled, so clicking on them would not result in the drop down menu to close. I managed to resolve this by utilising the clickEvent property of the hide.bs.dropdown event. The clickEvent property holds the Event Object of the original click event. The use case described is similar in the sense that is can be solved using the same approach.
Here is a jsfiddle using the clickEvent property to determine the original element trigerring the click event and keep the drop down menu open conditionally. In this case, it is a button somewhere on the page, unrelated to the dropdown menu.
https://jsfiddle.net/oc2bdmvr/
Based on bootstrap documentation:
https://getbootstrap.com/docs/5.0/getting-started/download/
"hide.bs.dropdown and hidden.bs.dropdown events have a clickEvent
property (only when the original Event type is click) that contains an
Event Object for the click event."
For my specific use case, I used JQuery to parse the DOM and figure out if the drop down item being clicked should result in closing the dropdown menu or not. My drop down items were also more complicated than just list items, i.e they were panels holding child objects, any of which could trigger a mouse click event. I have pasted below a code snipet that worked for me. Here is a jsfiddle link for the same: https://jsfiddle.net/z6gyjaps/
$(".dropdown").on("hide.bs.dropdown", function(e) {
if (e && e.clickEvent && e.clickEvent.target) {
let target = $(e.clickEvent.target);
if (!target.hasClass("dropdown-item")) {
// This is useful when your drop down items container complex hierarchies.
// JQuery parents() will find the first ancestor in the DOM hierarchy using some selector.
target = target.parents(".dropdown-item");
}
if (target.length > 0 && target.hasClass("inactive")) {
return false;
}
}
return true;
});
.dropdown-item-header {
font-weight: bold;
}
.dropdown-item-content {
margin: 20px;
}
.dropdown-item.inactive {
cursor: default !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/js/bootstrap.bundle.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet"/>
<div class="dropdown">
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenu2" data-bs-toggle="dropdown" aria-expanded="false">
Dropdown
</button>
<ul class="dropdown-menu" aria-labelledby="dropdownMenu2">
<li><button class="dropdown-item" type="button">Action</button></li>
<li><button class="dropdown-item inactive" type="button">Disabled action</button></li>
<li>
<div class="dropdown-item inactive">
<div class="dropdown-item-header">
Some Disabled complex item
</div>
<div class="dropdown-item-content">
Some contrent
</div>
</div>
</li>
<li><button class="dropdown-item" type="button">Something else here</button></li>
</ul>
</div>