Skip to content

Commit c61c5f1

Browse files
Merge pull request #11903 from creative-commoners/pulls/6/sr-pagination
ENH Improve screen reader support of pagination
2 parents 9c2acb1 + d3fa9e1 commit c61c5f1

File tree

3 files changed

+40
-4
lines changed

3 files changed

+40
-4
lines changed

lang/en.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ en:
203203
Page: Page
204204
Previous: Previous
205205
View: View
206+
Pagination: Pagination
207+
PaginationForTitle: Pagination for {title}
208+
InputTitle: 'Current page, currently {current} of {total}'
206209
SilverStripe\Forms\GridField\GridFieldViewButton:
207210
VIEW: View
208211
SilverStripe\Forms\HTMLEditor\TinyMCEConfig:

src/Forms/GridField/GridFieldPaginator.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,13 @@ public function getTemplateParameters(GridField $gridField)
283283
'LastPage' => $lastPage,
284284
'FirstShownRecord' => $firstShownRecord,
285285
'LastShownRecord' => $lastShownRecord,
286-
'NumRecords' => $totalRows
286+
'NumRecords' => $totalRows,
287+
'InputTitle' => _t(
288+
__CLASS__ . '.InputTitle',
289+
'Current page, currently {current} of {total}',
290+
['current' => $state->currentPage, 'total' => $totalPages]
291+
),
292+
'AriaLabel' => $this->getAriaLabel($gridField),
287293
]);
288294
}
289295
}
@@ -325,4 +331,25 @@ public function getItemsPerPage()
325331
{
326332
return $this->itemsPerPage;
327333
}
334+
335+
/**
336+
* An accessible ARIA label using the GridField's title or model name.
337+
*/
338+
private function getAriaLabel(GridField $gridField): string
339+
{
340+
$title = $gridField->Title();
341+
if (!$title) {
342+
try {
343+
$modelClass = $gridField->getModelClass();
344+
$title = $modelClass::singleton()->i18n_plural_name();
345+
} catch (LogicException) {
346+
return _t(__CLASS__ . '.Pagination', 'Pagination');
347+
}
348+
}
349+
return _t(
350+
__CLASS__ . '.PaginationForTitle',
351+
'Pagination for {title}',
352+
['title' => $title]
353+
);
354+
}
328355
}

templates/SilverStripe/Forms/GridField/GridFieldPaginator_Row.ss

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,22 @@
22
<td class="grid-field__paginator bottom-all" colspan="$Colspan">
33
<% if $OnlyOnePage %>
44
<% else %>
5-
<div class="grid-field__paginator__controls datagrid-pagination">
5+
<nav aria-label="$AriaLabel"
6+
class="grid-field__paginator__controls datagrid-pagination"
7+
>
68
$FirstPage $PreviousPage
79
<span class="pagination-page-number">
810
<%t SilverStripe\\Forms\\GridField\\GridFieldPaginator.Page 'Page' %>
9-
<input class="text no-change-track" title="Current page" value="$CurrentPageNum" data-skip-autofocus="true" />
11+
<input class="text no-change-track"
12+
title="$InputTitle"
13+
value="$CurrentPageNum"
14+
data-skip-autofocus="true"
15+
/>
1016
<%t SilverStripe\\Forms\\GridField\\GridFieldPaginator.OF 'of' is 'Example: View 1 of 2' %>
1117
$NumPages
1218
</span>
1319
$NextPage $LastPage
14-
</div>
20+
</nav>
1521
<% end_if %>
1622
<span class="grid-field__paginator_numbers pagination-records-number">
1723
<%t SilverStripe\\Forms\\GridField\\GridFieldPaginator.View 'View' is 'Verb. Example: View 1 of 2' %>

0 commit comments

Comments
 (0)