Skip to content

Commit

Permalink
A few ARIA updates (#732)
Browse files Browse the repository at this point in the history
* Leaf nodes must use aria-expanded=false. The logic was there but needed to be moved, because Fancytree treats leaf nodes as expanded in the data model

* Correction: leaf nodes are sometimes marked as expanded in the data model, sometimes not. So let's make the logic robust and first child whether something is a leaf node. If so, remove aria-expanded. Once we know it's not a leaf node, we can use hasChildren as that is reliable.

* Set aria-expanded=false for lazy nodes since they likely have children

* Use <li> for ARIA instead of first child of it

* Use hasChildren === false, do some cleanup of old code

* Some cleanup
  • Loading branch information
aleventhal authored and mar10 committed May 11, 2017
1 parent 1a6c664 commit 76b8a21
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/jquery.fancytree.ariagrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ $.ui.fancytree.registerExtension({
$tr.removeAttr( "aria-hidden" );
}
// this.debug("nodeRenderStatus: " + this.$activeTd + ", " + $tr.attr("aria-expanded"));
// In cell-mode, move aria-expanded attribute from TR to its parent TD
// In cell-mode, move aria-expanded attribute from TR to first child TD
if ( this.$activeTd && $tr.attr( "aria-expanded" ) != null ) {
$tr.remove( "aria-expanded" );
$tr.find( "td" ).eq( this.nodeColumnIdx )
Expand Down
36 changes: 11 additions & 25 deletions src/jquery.fancytree.js
Original file line number Diff line number Diff line change
Expand Up @@ -3389,20 +3389,14 @@ $.extend(Fancytree.prototype,
node.li = document.createElement("li");
node.li.ftnode = node;

// if(aria){
// $(node.li).attr("role", "treeitem");
// }
if( node.key && opts.generateIds ){
node.li.id = opts.idPrefix + node.key;
}
node.span = document.createElement("span");
node.span.className = "fancytree-node";
if( aria && !node.tr ) {
$(node.span).attr("role", "treeitem");
$(node.li).attr("role", "treeitem");
}
// if(aria){
// $(node.li).attr("aria-labelledby", "ftal_" + opts.idPrefix + node.key);
// }
node.li.appendChild(node.span);

// Create inner HTML for the <span> (expander, checkbox, icon, and title)
Expand Down Expand Up @@ -3502,7 +3496,7 @@ $.extend(Fancytree.prototype,
*/
nodeRenderTitle: function(ctx, title) {
// set node connector images, links and text
var id, icon, nodeTitle, role, tabindex, tooltip,
var icon, nodeTitle, role, tabindex, tooltip,
node = ctx.node,
tree = ctx.tree,
opts = ctx.options,
Expand Down Expand Up @@ -3582,14 +3576,10 @@ $.extend(Fancytree.prototype,
tooltip = opts.tooltip === true ? node.title : opts.tooltip.call(tree, node);
}
tooltip = tooltip ? " title='" + _escapeTooltip(tooltip) + "'" : "";
// id = aria ? " id='ftal_" + opts.idPrefix + node.key + "'" : "";
id = "";
// role = "";
role = ""; // (aria && !node.tr) ? " role='treeitem'" : "";
tabindex = opts.titlesTabbable ? " tabindex='0'" : "";

nodeTitle = "<span " + role + " class='fancytree-title'" +
id + tooltip + tabindex + ">" +
nodeTitle = "<span class='fancytree-title'" +
tooltip + tabindex + ">" +
(opts.escapeTitles ? _escapeHtml(node.title) : node.title) +
"</span>";
}
Expand Down Expand Up @@ -3617,8 +3607,6 @@ $.extend(Fancytree.prototype,
hasChildren = node.hasChildren(),
isLastSib = node.isLastSibling(),
aria = opts.aria,
// $ariaElem = aria ? $(node[tree.ariaPropName]) : null,
// $ariaElem = $(node.span).find(".fancytree-title"),
cn = opts._classNames,
cnList = [],
statusElem = node[tree.statusClassPropName];
Expand All @@ -3628,7 +3616,7 @@ $.extend(Fancytree.prototype,
return;
}
if( aria ) {
$ariaElem = node.tr ? $(node.tr) : $(node.span); //.find(".fancytree-title");
$ariaElem = $(node.tr || node.li);
}
// Build a list of class names that we will add to the node <span>
cnList.push(cn.node);
Expand All @@ -3643,16 +3631,14 @@ $.extend(Fancytree.prototype,
if( tree.focusNode === node ){
cnList.push(cn.focused);
}
// node.debug("aria", node.expanded, aria, $ariaElem);
if( node.expanded ){
cnList.push(cn.expanded);
if(aria){
$ariaElem.attr("aria-expanded", true);
}
if( aria ){
if (hasChildren !== false) {
$ariaElem.attr("aria-expanded", Boolean(node.expanded));
}
}else if( aria ){
if( hasChildren ) {
$ariaElem.attr("aria-expanded", false);
} else {
else {
$ariaElem.removeAttr("aria-expanded");
}
}
Expand Down Expand Up @@ -3988,7 +3974,7 @@ $.extend(Fancytree.prototype,
if( opts.aria ){
// Set active descendant to node's span ID (create one, if needed)
$(tree.$container).attr("aria-activedescendant",
$( node.tr || node.span ).uniqueId().attr("id"));
$( node.tr || node.li ).uniqueId().attr("id"));
// "ftal_" + opts.idPrefix + node.key);
}
// $(node.span).find(".fancytree-title").focus();
Expand Down

0 comments on commit 76b8a21

Please sign in to comment.