Course contentsShow
← Web Development
Lesson 1093 of 2,98219. Keyboard Navigation and FocusFree lesson

Dropdown and Popup Focus

Managing focus when opening dropdowns, tooltips, and popups, including arrow key navigation patterns.

Dropdown and Popup Focus

You'll learn how to manage focus when revealing dropdown menus, tooltips, and popups to ensure keyboard users don't lose their place.

When a user opens a dropdown or popup, their keyboard focus should move naturally into that new context. Without proper focus management, keyboard users would have to tab through the entire page to reach content that just appeared visually right in front of them.

How Focus Should Move

When a dropdown or popup opens, focus should typically move to one of these places:

  1. The first focusable element inside (a search field, menu item, or button)
  2. The container itself (using tabindex="-1" on a wrapper element)
  3. Nowhere — for simple tooltips that are purely informational

Arrow Key Navigation in Dropdowns

Once focus is inside a dropdown menu, arrow keys should let users navigate between options:

  • Up/Down arrows move through menu items vertically
  • Enter/Space activates the current selection
  • Escape closes the dropdown and returns focus to the trigger button

This builds on the roving tabindex pattern you've learned — only one menu item should be focusable at a time via Tab, but arrow keys move a visual focus indicator between items.

Returning Focus on Close

When the user closes the dropdown (via Escape, clicking outside, or selecting an option), focus must return to the element that opened it — typically the trigger button. This prevents keyboard users from being dumped back at the top of the page.

Key Takeaway: When opening dropdowns or popups, immediately move focus inside them, support arrow key navigation for menu-like structures, and always return focus to the trigger element when closing.