question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to set dropdown boundary in Bootstrap 5

See original GitHub issue

Discussed in https://github.com/twbs/bootstrap/discussions/36383

<div type='discussions-op-text'>

Originally posted by SoftCircuits May 17, 2022 I had the following markup working in Bootstrap 4.

<div class="dropdown">
    <span type="button" class="dropdown" data-toggle="dropdown" data-boundary="viewport">
        <img src="~/images/menu.png" title="Menu" />
    </span>
    <div class="dropdown-menu dropdown-menu-right">
        <a asp-page="AddBol" class="dropdown-item">Manual Entry</a>
    </div>
</div>

However, when I upgraded to Bootstrap 5, the dropdown no longer opens.

I figured out that I need to change the data-toggle attribute to use the data-bs-toggle attribute instead. Now the dropdown works.

However, the data-boundary="viewport" attribute no longer works. This attribute allows the dropdown to extend outside the container element. As it is now, the dropdown is cut off when its bounds fall outside of the container.

I tried using data-bs-boundary="viewport" and data-bs-boundary="body" as suggested in this Stackoverflow question.

Does anyone know how to use this attribute in Bootstrap 5?

</div>

More Details

I have a dropdown within a table. It works fine unless the table is empty, in which case the dropdown is clipped where it would extend outside of the table area.

This was fixed before by setting data-boundary="viewport". But I upgraded to Bootstrap 5 and now the problem is back.

I tried updating this attribute to data-bs-boundary="viewport" but that has no effect.

Does anyone know the reason? Is this related to popper? Where I should post about this?

Thanks. Below is my markup (it’s ASP.NET/Razor Pages).

<div class="table-responsive">
    <table class="table table-striped">
        <thead>
            <tr>
                <th>@Html.DisplayNameFor(m => m.TruckBols[0].TruckNumber)</th>
                <th>@Html.DisplayNameFor(m => m.TruckBols[0].BoxNumber)</th>
                <th>@Html.DisplayNameFor(m => m.TruckBols[0].PurchaseOrder)</th>
                <th>@Html.DisplayNameFor(m => m.TruckBols[0].Product)</th>
                <th>@Html.DisplayNameFor(m => m.TruckBols[0].InboundWeight)</th>
                <th>@Html.DisplayNameFor(m => m.TruckBols[0].ArrivalTime)</th>
                <th class="text-end">
                    <div class="dropdown">
                        <span type="button" class="dropdown" data-bs-toggle="dropdown" data-bs-boundary="viewport">
                            <img src="~/images/menu.png" title="Menu" />
                        </span>
                        <div class="dropdown-menu dropdown-menu-right">
                            <a asp-page="AddBol" class="dropdown-item">Manual Entry</a>
                        </div>
                    </div>
                </th>
            </tr>
        </thead>
        <tbody>
            @if (truckCount > 0)
            {
                foreach (TruckSummaryModel truck in Model.TruckBols!)
                {
                    <tr>
                        <td>@Html.DisplayFor(m => truck.TruckNumber)</td>
                        <td>@Html.DisplayFor(m => truck.BoxNumber)</td>
                        <td>@Html.DisplayFor(m => truck.PurchaseOrder)</td>
                        <td>@Html.DisplayFor(m => truck.Product)</td>
                        <td>@Formatter.Number(truck.InboundWeight)</td>
                        <td>@truck.GetFormattedArrivalTime(Model.UserContext.TimeZoneId)</td>
                        <td class="text-end">
                            <a asp-page="ArriveTruck" asp-route-id="@truck.Id"><img src="/images/edit.png" title="Edit" /></a>
                            <a asp-page="DepartTruck" asp-route-id="@truck.Id"><img src="/images/depart.png" title="Depart Truck" /></a>
                        </td>
                    </tr>
                }
            }
        </tbody>
    </table>

This online example demonstrates the issue.

https://codepen.io/korki43/pen/mdRGgMK?editors=1000

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
kadsyycommented, Jun 14, 2022

Try adding ‘position-static’ class inside here

<div class="dropdown position-static">

Please try if its work on other browser as well.

0reactions
GreathostRocommented, Nov 24, 2022

After more than a few hours and various attempts I found the working version:

const dropdowns = document.querySelectorAll('.dropdown-toggle')
const dropdown = [...dropdowns].map((dropdownToggleEl) => new bootstrap.Dropdown(dropdownToggleEl, {
    popperConfig(defaultBsPopperConfig) {
        return { ...defaultBsPopperConfig, strategy: 'fixed' };
    }
}));
Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to set dropdown boundary in Bootstrap 5
I see two possible solutions: 1. Change the Popper version via CDN. According to the most upvoted answer from this question, this happens ......
Read more >
[Best solution]-Unable to set dropdown boundary in Bootstrap 5
According to the most upvoted answer from this question, this happens because of the Popper version. Boostrap 4.6 uses Popper 1.16.1 (link) while...
Read more >
Dropdowns · Bootstrap v5.1
Configure the auto close behavior of the dropdown: true - the dropdown will be closed by clicking outside or inside the dropdown menu....
Read more >
Dropdowns - Bootstrap
Overflow constraint boundary of the dropdown menu. Accepts the values of 'viewport' , 'window' , 'scrollParent' , or an HTMLElement reference (JavaScript only) ......
Read more >
Dropdowns · Bootstrap v5.3
Single button · div class="dropdown"> · button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"> · button> ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found