Skip to content

Commit 1d05442

Browse files
committed
ENH Add aria attrs to site tree
1 parent 0bf24cc commit 1d05442

File tree

6 files changed

+74
-6
lines changed

6 files changed

+74
-6
lines changed

client/dist/js/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/src/legacy/CMSMain.Tree.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,14 @@ $.entwine('ss.tree', function($) {
183183
}
184184
});
185185

186+
// Add role="tree" to the root level <ul> for accessibility
187+
// This needs to be done with JS as jstree will override any attributes set server-side
188+
$('.cms-tree > ul').entwine({
189+
onmatch: function() {
190+
this.attr('role', 'tree');
191+
}
192+
});
193+
186194
// Scroll tree down to context of the current page, if it isn't
187195
// already visible
188196
$('.cms-tree a.jstree-clicked').entwine({

code/Controllers/CMSMain.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,13 @@ protected function getTreeNodeCustomisations()
593593
'title' => $node->Title,
594594
]
595595
),
596+
'ToggleTitle' => _t(
597+
CMSMain::class . '.TOGGLE_CHILD_PAGES',
598+
'Toggle child pages of {title}',
599+
[
600+
'title' => $node->Title,
601+
]
602+
),
596603
'TreeTitle' => DBHTMLText::create()->setValue($this->getRecordTreeMarkup($node)),
597604
];
598605
};

lang/en.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ en:
8888
SAVEDRAFT: Save
8989
SEARCHRESULTS: 'Search results'
9090
SHOW_AS_LIST: 'show as list'
91+
TOGGLE_CHILD_PAGES: 'Toggle child pages of {title}'
92+
TOGGLE_SITE_TREE: 'Toggle site tree'
9193
TOO_MANY_PAGES: 'Too many pages'
9294
TOO_MANY_RECORDS: 'Too many records'
9395
TREE_NO_TITLE: '(no title)'

templates/SilverStripe/CMS/Controllers/Includes/CMSMain_SubTree.ss

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,38 @@
11
<% if not $node.IsInDB %><%-- Only render root node if it's the true root --%>
2-
<ul><li id="record-0" data-id="0" class="Root nodelete"><ins class="jstree-icon font-icon-right-dir" tabindex="0">&nbsp;</ins><strong>$rootTitle</strong>
2+
<%-- This <ul> will have any attributes set here overrideen by JS in jstree
3+
CMSMain.Tree.js will set this <ul> to have tree="role"
4+
--%>
5+
<ul>
6+
<li id="record-0"
7+
data-id="0"
8+
class="Root nodelete"
9+
role="treeitem"
10+
aria-level="1"
11+
<%-- aria-expanded value is handled via JS --%>
12+
aria-expanded="false"
13+
><ins class="jstree-icon font-icon-right-dir"
14+
role="button"
15+
tabindex="0"
16+
aria-controls="subtree-0"
17+
aria-label="<%t SilverStripe\CMS\Controllers\CMSMain.TOGGLE_SITE_TREE 'Toggle site tree' %>"
18+
>&nbsp;</ins><strong>$rootTitle</strong>
319
<% end_if %>
420
<% if $limited %>
521
<ul><li class="readonly">
622
<span class="item">
723
<%t SilverStripe\\CMS\\Controllers\\CMSMain.TOO_MANY_RECORDS 'Too many records' %>
8-
(<a href="{$listViewLink.ATT}" class="subtree-list-link" data-id="$node.ID" data-pjax-target="Content"><%t SilverStripe\\CMS\\Controllers\\CMSMain.SHOW_AS_LIST 'show as list' %></a>)
24+
(<a href="{$listViewLink.ATT}"
25+
class="subtree-list-link"
26+
data-id="$node.ID"
27+
data-pjax-target="Content"
28+
><%t SilverStripe\\CMS\\Controllers\\CMSMain.SHOW_AS_LIST 'show as list' %></a>)
929
</span>
1030
</li></ul>
1131
<% else_if $children %>
12-
<ul>
32+
<ul id="subtree-{$node.ID}"
33+
role="group"
34+
<% if $node.Title %>aria-label="{$node.Title.ATT}"<% end_if %>
35+
>
1336
<% loop $children %><% include SilverStripe\\CMS\\Controllers\\CMSMain_TreeNode Controller=$Top.Controller %><% end_loop %>
1437
</ul>
1538
<% end_if %>

templates/SilverStripe/CMS/Controllers/Includes/CMSMain_TreeNode.ss

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
1-
<li id="record-{$node.ID}" data-id="{$node.ID}" data-recordtype="{$node.ClassName}" class="$markingClasses $extraClass"><ins class="jstree-icon font-icon-right-dir" tabindex="0">&nbsp;</ins>
2-
<a href="{$Controller.LinkRecordEdit($node.ID).ATT}" title="{$Title.ATT}"><ins class="jstree-icon font-icon-drag-handle">&nbsp;</ins>
1+
<li id="record-{$node.ID}"
2+
data-id="{$node.ID}"
3+
data-recordtype="{$node.ClassName}"
4+
class="$markingClasses $extraClass"
5+
role="none"
6+
>
7+
<% if $children.count %>
8+
<ins class="jstree-icon font-icon-right-dir"
9+
role="button"
10+
tabindex="0"
11+
aria-controls="subtree-{$node.ID}"
12+
aria-label="{$ToggleTitle.ATT}"
13+
>&nbsp;</ins>
14+
<% else %>
15+
<%-- jstree will add an icon here regardless, so add one that has aria-hidden
16+
Note we can't use use display:none!important here as it breaks the layout
17+
--%>
18+
<ins class="jstree-icon" aria-hidden="true"></ins>
19+
<% end_if %>
20+
<a href="{$Controller.LinkRecordEdit($node.ID).ATT}"
21+
title="{$Title.ATT}"
22+
role="treeitem"
23+
aria-owns="subtree-{$node.ID}"
24+
aria-level="$level"
25+
<%-- $children is an ArrayList, so no extra DB query is triggered here --%>
26+
<% if $children.count %>
27+
<%-- aria-expanded value is handled via JS --%>
28+
aria-expanded="false"
29+
<% end_if %>
30+
><ins class="jstree-icon font-icon-drag-handle">&nbsp;</ins>
331
<span class="text">{$TreeTitle}</span>
432
</a>
533
$SubTree

0 commit comments

Comments
 (0)