we (web engine): Experimental web browser project to understand the limits of Claude

Focus management and tab navigation #150

open opened by pierrelf.com

Summary#

Implement focus tracking, tab-order navigation, and focus-related events and pseudo-classes.

Details#

Focus tracking#

  • Document.activeElement tracks the currently focused element
  • Only focusable elements can receive focus (form controls, elements with tabindex, <a> with href)
  • Clicking a focusable element moves focus to it
  • element.focus() and element.blur() methods

Tab navigation#

  • Tab key advances focus to next focusable element in tab order
  • Shift+Tab moves focus backwards
  • Tab order: elements with positive tabindex first (ascending), then DOM order for tabindex=0 and naturally focusable elements
  • Elements with tabindex=-1 are focusable via script but skipped in tab order

Events#

  • `focus` / `blur` events (don't bubble)
  • `focusin` / `focusout` events (bubble)

CSS pseudo-classes#

  • `:focus` matches the focused element
  • `:focus-visible` matches when focus should be visually indicated (keyboard navigation)
  • `:focus-within` matches ancestors of the focused element

Acceptance criteria#

  • `document.activeElement` correctly tracks focus
  • Tab/Shift+Tab cycles through focusable elements in correct order
  • `tabindex` attribute is respected for ordering and focusability
  • Focus/blur events fire correctly with proper bubbling behavior
  • `:focus`, `:focus-visible`, `:focus-within` pseudo-classes match correctly in selector matching
  • Focus ring renders around the focused element
  • Tests cover tab order, event dispatch, and pseudo-class matching

Dependencies#

  • Form element parsing and DOM interfaces
sign up or login to add to the discussion
Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:meotu43t6usg4qdwzenk4s2t/sh.tangled.repo.issue/3mihoyihg2o2b