Performance: Dropdown button basics
Dropdown buttons affect interaction responsiveness and visual stability during user clicks.
<div class="dropdown"> <button class="btn btn-primary dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false"> Dropdown </button> <ul class="dropdown-menu"> <li><a class="dropdown-item" href="#">Item 1</a></li> <li><a class="dropdown-item" href="#">Item 2</a></li> </ul> </div>
<button class="btn btn-primary" onclick="document.getElementById('menu').style.display='block'">Dropdown</button> <div id="menu" style="display:none; position:absolute; background:#fff; border:1px solid #ccc;"> <a href="#">Item 1</a> <a href="#">Item 2</a> </div>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual inline style toggle | Minimal DOM nodes | Multiple reflows per toggle | High paint cost due to layout thrashing | [X] Bad |
| Bootstrap dropdown component | Minimal DOM nodes with semantic structure | Single reflow per toggle | Lower paint cost with compositing | [OK] Good |
dropdown button in Bootstrap?btn, a style class like btn-primary, and dropdown-toggle to work properly.btn btn-primary dropdown-toggle. Others miss or misorder classes.<button class="btn btn-secondary dropdown-toggle" type="button" data-toggle="dropdown">Menu</button> <div class="dropdown-menu"> <a class="dropdown-item" href="#">Action</a> </div>
data-bs-toggle="dropdown" instead of the older data-toggle="dropdown".dropdown-menu can be a div; a with dropdown-item is correct.data-bs-toggle="dropdown" for toggling dropdowns, not data-toggle.button elements with dropdown-toggle and a or button tags with dropdown-item inside dropdown-menu ensures keyboard accessibility and closes menu on click.data-bs-toggle="dropdown" (BS5 correct) with proper button.dropdown-toggle and a.dropdown-item that auto-closes the menu.button with dropdown-toggle and data-bs-toggle="dropdown", and a tags with dropdown-item inside dropdown-menu -> Option Aa tag for toggle or span for itemsPass the test and this pattern moves unknown