Performance: Navigation bar patterns
MEDIUM IMPACT
Navigation bar patterns affect page load speed and interaction responsiveness, especially on mobile devices.
<nav class="flex flex-col"> <ul> <li> <button aria-expanded="false" aria-controls="menu" class="px-4 py-2" id="menu-button">Menu</button> <ul id="menu" class="hidden bg-white shadow-lg" role="menu" aria-labelledby="menu-button"> <li><a href="#" class="block px-4 py-2">Item 1</a></li> <li><a href="#" class="block px-4 py-2">Item 2</a></li> <li><a href="#" class="block px-4 py-2">Item 3</a></li> </ul> </li> </ul> </nav> <script> const btn = document.getElementById('menu-button'); const menu = document.getElementById('menu'); btn.addEventListener('click', () => { const expanded = btn.getAttribute('aria-expanded') === 'true'; btn.setAttribute('aria-expanded', String(!expanded)); menu.classList.toggle('hidden'); }); </script>
<nav class="flex flex-col"> <ul> <li class="group relative"> <button class="px-4 py-2">Menu</button> <ul class="absolute hidden group-hover:block bg-white shadow-lg"> <li><a href="#" class="block px-4 py-2">Item 1</a></li> <li><a href="#" class="block px-4 py-2">Item 2</a></li> <li><a href="#" class="block px-4 py-2">Item 3</a></li> </ul> </li> </ul> </nav>
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Hover-based dropdown with absolute positioning | High (nested lists) | Multiple on hover | High (shadows, repaint) | [X] Bad |
| Click-toggle dropdown with minimal DOM | Low (flat structure) | Single on toggle | Low (simple styles) | [OK] Good |