[whatwg] Focus management

Simon Fraser smfr at mac.com
Fri May 4 13:26:21 PDT 2007


Some web applications may need more control over focus than is offered  
by
the existing focus management proposal:
<http://www.whatwg.org/specs/web-apps/current-work/#focus>

Specifically, it's hard to write JavaScript that has more explicit  
control
over focus changes. Functionality that is missing (but often included in
native UI toolkits) includes:

* Focus chain queries
     need the ability to ask the document what the next/previous  
focusable
     element is from a given element, or from null (first/last focusable
     element).

* Is element focusable
     need to be able to ask an element if it can take focus.  
Focusability is
     currently some function of element type, tabindex, visibility,
     contentEditability, UA preferenes etc, and it's hard to write JS
     that computes this.

* Explicit advance/rewind focus
     need to be able to move focus to the next/previous focusable
     element without having explicit knowledge of what the next
     element is (this mirrors what happens when the user hits the Tab
     or Shift-Tab keys).

     (If nextFocus()/previousFocus() are available, this could be  
achieved with
         document.nextFocus(document.activeElement).focus(),
      but that seems a little long-winded.)

In addition, I'd like to see a few clarifications in the "Focus  
management"
section of the Web Applications draft:

* What does focus() do on an unfocusable element? Does the previously
   focused element remain focused?

* document.activeElement has some ambiguities:
     - Is it valid when the window does not have focus?
     - IE has a setActive() method that changes the activeElement, but
         does not change the focus. So the activeElement is not always
         the focused element.

* how does display: none or visibility: hidden interact with focus?
     - if a focused element becomes unrendered, does focus move to the
       next focusable element?
     - can non-rendered elements be focused?

Finally I'd like to see some discussion around focus() and window  
activation.
window.focus() obviously (and annoyingly) activates the window, but  
should
focussing an element inside a window raise the window? What happens if
that window is a hidden tab in a tabbed browser?

Simon





More information about the whatwg mailing list