views:

73

answers:

3

Consider this example showing the YUI tree in action:

http://developer.yahoo.com/yui/examples/treeview/tv%5Fedit.html

  1. Select the title in orange ("TreeView Control: Inline Editing of TreeView Node Labels").
  2. Hit tab a first time: the link "View example in new window" is selected.
  3. Hit tab a second time: this selects an anchor inside the tree.

    Label 0 not highlighted

  4. From there you can use the up/down keys to navigate through the tree. The current item is always highlighted with a background color.

    Label 1 is highlighted

The issue is that the background of the current item is not highlighted on step 3 above (but it is when navigating through the tree on step 4). Is this a bug of the YUI tree, or is there a way to programmatically highlight the current item when the tree receives the focus?

A: 

This fails for me entirely (using Google Chrome), but looking at the code the tree is a warren of nested tables - I'd avoid this like the plague if you're serious about accessibility.

graphicdivine
I understand that using HTML tables can cause problems to screen readers, but my goal here is just to make the tree view usable with the keyboard (which is part of "accessibility" in general, but granted, is a very specific feature).
Alessandro Vernet
The initial pale-blue-background highlight on the current element is being applied as a class (ygtvfocus) to several < td >s. Since the tabbing through the document will only focus on < a >s, you would need to resort to some fiendish javascript to replicate this.In short - tabbing doesn't work. Arrows do. Tabbing is a default browser behaviour targeting < a > tags, YUI Tree is a custom interface using arrow keys. Two incompatible but overlapping systems. YUI is trying to reinvent the wheel. Using tables.
graphicdivine
A: 

The node will lose focus when element on the page that can accept focus is clicked. Clicking on a node in the tree will give that node focus. Every node instance has a focus() method, so you can manually focus any node in the tree whenever you like -- this is exactly what that example is doing to highlight the second node.

Adam Moore
Adam, thank you for responding. Yes: if you click on a node, if get the focus and gets a background color, as expected. Ditto if you move from node to node using the keyboard direction keys. What doesn't seem to work is setting the background color of the node when it gets the focus by hitting tab (coming from somewhere else on the page), rather than clicking on that node. This 1 min screencast shows this: http://screencast.com/t/NDY3YTFh. Does this make more sense?
Alessandro Vernet
Adam, I found a solution to this issue, which I posted as an answer to this question.
Alessandro Vernet
A: 

A "fix" for this is to register a listener on anchors inside the node, when an anchor gets the focus to find the corresponding node, and call node.focus(). Adding the following to render() in treeview.js does the trick:

var anchors = this.getEl().getElementsByTagName("a");
for (var anchorIndex = 0; anchorIndex < anchors.length; anchorIndex++) {
    var anchor = anchors[anchorIndex];
    Event.on(
     anchor,
     'focus',
     function (ev) {
         var target = Event.getTarget(ev);
         var node = this.getNodeByElement(target);
         node.focus();
        },
        this,
        true
    );
}
Alessandro Vernet