Consider this example showing the YUI tree in action:
http://developer.yahoo.com/yui/examples/treeview/tv_edit.html
- Select the title in orange ("TreeView Control: Inline Editing of TreeView Node Labels").
- Hit tab a first time: the link "View example in new window" is selected.
Hit tab a second time: this selects an anchor inside the tree.
Label 0 not highlighted http://img.skitch.com/20091218-61eqs6gcngp8ay56s1pba3jhb.png
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 http://img.skitch.com/20091218-es5xh4g4k41d8s133hay65ufrr.png
The issue is that the background of the current item is not highlighted on step 3 above (but it is when navigating through t开发者_运维知识库he 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 "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
);
}
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.
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.
精彩评论