Skip to content

Commit 3a39359

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

File tree

5 files changed

+59
-5
lines changed

5 files changed

+59
-5
lines changed

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_CHILD_PAGES_ROOT: 'Toggle child pages of top level'
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: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
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+
<ul id="subtree-0" role="group">
3+
<li id="record-0"
4+
data-id="0"
5+
class="Root nodelete"
6+
role="treeitem"
7+
aria-level="1"
8+
<%-- aria-expanded value is handled via JS --%>
9+
aria-expanded="false"
10+
><ins class="jstree-icon font-icon-right-dir"
11+
role="button"
12+
tabindex="0"
13+
aria-controls="subtree-0"
14+
aria-label="<%t SilverStripe\CMS\Controllers\CMSMain.TOGGLE_CHILD_PAGES_ROOT 'Toggle child pages of top level' %>"
15+
>&nbsp;</ins><strong>$rootTitle</strong>
316
<% end_if %>
417
<% if $limited %>
518
<ul><li class="readonly">
619
<span class="item">
720
<%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>)
21+
(<a href="{$listViewLink.ATT}"
22+
class="subtree-list-link"
23+
data-id="$node.ID"
24+
data-pjax-target="Content"
25+
><%t SilverStripe\\CMS\\Controllers\\CMSMain.SHOW_AS_LIST 'show as list' %></a>)
926
</span>
1027
</li></ul>
1128
<% else_if $children %>
12-
<ul>
29+
<ul id="subtree-{$node.ID}" role="group">
1330
<% loop $children %><% include SilverStripe\\CMS\\Controllers\\CMSMain_TreeNode Controller=$Top.Controller %><% end_loop %>
1431
</ul>
1532
<% end_if %>

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

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

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ $ExtraTreeTools
1010
</a>
1111

1212
<div class="cms-tree <% if $TreeIsFiltered %>filtered-list<% end_if %>"
13+
role="tree"
1314
data-url-tree="$LinkWithSearch($Link('getsubtree')).ATT"
1415
data-url-savetreenode="$Link('savetreenode').ATT"
1516
data-url-updatetreenodes="$Link('updatetreenodes').ATT"
@@ -26,6 +27,7 @@ $ExtraTreeTools
2627
</div>
2728
<% else %>
2829
<div class="cms-tree flexbox-area-grow <% if $TreeIsFiltered %>filtered-list<% end_if %>"
30+
role="tree"
2931
data-url-tree="$LinkWithSearch($Link('getsubtree')).ATT"
3032
data-url-savetreenode="$Link('savetreenode').ATT"
3133
data-url-updatetreenodes="$Link('updatetreenodes').ATT"

0 commit comments

Comments
 (0)