Skip to content

Commit

Permalink
Improve accessibility of the title of the settings
Browse files Browse the repository at this point in the history
Before every setting page had the same title and this is causing issues
for screenreaders since they can't differenciate the title of page. Now
a new variable is available for apps to declare the page subtitle.

This new variable is implemented for the settings app and while at it I
added a bit more type hinting to the stuff I touched :)

Signed-off-by: Carl Schwan <[email protected]>
  • Loading branch information
CarlSchwan committed Nov 24, 2021
1 parent 70f9e5e commit 45ecafe
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
4 changes: 4 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,7 @@

AddDefaultCharset utf-8
Options -Indexes
#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####

ErrorDocument 403 /
ErrorDocument 404 /
36 changes: 24 additions & 12 deletions apps/settings/lib/Controller/CommonSettingsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use OCP\IGroupManager;
use OCP\INavigationManager;
use OCP\IUserSession;
use OCP\Settings\IIconSection;
use OCP\Settings\IManager as ISettingsManager;
use OCP\Settings\ISettings;

Expand All @@ -53,11 +54,13 @@ trait CommonSettingsTrait {
/** @var ISubAdmin */
private $subAdmin;

/** @var ?IIconSection */
private $activeSection = null;

/**
* @param string $currentSection
* @return array
* @return array{forms: array{personal: array, admin: array}}
*/
private function getNavigationParameters($currentType, $currentSection) {
private function getNavigationParameters(string $currentType, string $currentSection): array {
$templateParameters = [
'personal' => $this->formatPersonalSections($currentType, $currentSection),
'admin' => []
Expand All @@ -73,9 +76,13 @@ private function getNavigationParameters($currentType, $currentSection) {
];
}

/**
* @param IIconSection[][] $sections
* @psam-param 'admin'|'personal' $type
* @return list<array{anchor: string, section-name: string, active: bool, icon: string}>
*/
protected function formatSections(array $sections, string $currentSection, string $type, string $currentType): array {
$templateParameters = [];
/** @var \OCP\Settings\IIconSection[] $prioritizedSections */
foreach ($sections as $prioritizedSections) {
foreach ($prioritizedSections as $section) {
if ($type === 'admin') {
Expand All @@ -92,6 +99,10 @@ protected function formatSections(array $sections, string $currentSection, strin
$active = $section->getID() === $currentSection
&& $type === $currentType;

if ($active) {
$this->activeSection = $section;
}

$templateParameters[] = [
'anchor' => $section->getID(),
'section-name' => $section->getName(),
Expand All @@ -105,21 +116,17 @@ protected function formatSections(array $sections, string $currentSection, strin

protected function formatPersonalSections(string $currentType, string $currentSections): array {
$sections = $this->settingsManager->getPersonalSections();
$templateParameters = $this->formatSections($sections, $currentSections, 'personal', $currentType);

return $templateParameters;
return $this->formatSections($sections, $currentSections, 'personal', $currentType);
}

protected function formatAdminSections(string $currentType, string $currentSections): array {
$sections = $this->settingsManager->getAdminSections();
$templateParameters = $this->formatSections($sections, $currentSections, 'admin', $currentType);

return $templateParameters;
return $this->formatSections($sections, $currentSections, 'admin', $currentType);
}

/**
* @param array<int, list<\OCP\Settings\ISettings>> $settings
* @return array
* @return array{content: string}
*/
private function formatSettings(array $settings): array {
$html = '';
Expand All @@ -133,11 +140,16 @@ private function formatSettings(array $settings): array {
return ['content' => $html];
}

private function getIndexResponse($type, $section) {
private function getIndexResponse(string $type, string $section): TemplateResponse {
$this->navigationManager->setActiveEntry('settings');
$templateParams = [];
$templateParams = array_merge($templateParams, $this->getNavigationParameters($type, $section));
$templateParams = array_merge($templateParams, $this->getSettings($section));
if ($this->activeSection !== null) {
$templateParams = array_merge($templateParams, [
'pageTitle' => $this->activeSection->getName()
]);
}

return new TemplateResponse('settings', 'settings/frame', $templateParams);
}
Expand Down
1 change: 1 addition & 0 deletions core/templates/layout.user.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<meta charset="utf-8">
<title>
<?php
p(!empty($_['pageTitle'])?$_['pageTitle'].' - ':'');
p(!empty($_['application'])?$_['application'].' - ':'');
p($theme->getTitle());
?>
Expand Down

0 comments on commit 45ecafe

Please sign in to comment.