From ebe8626ba78af579f28fc722c77dda42c3d13a54 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Mon, 18 May 2020 12:53:00 -0400 Subject: [PATCH] Add aria attributes to selected menu items --- app/views/main-menu.php | 21 +++++++++++++++------ src/AnimeClient/MenuGenerator.php | 5 ++++- src/AnimeClient/Util.php | 25 ++++++++++++++++++++++++- 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/app/views/main-menu.php b/app/views/main-menu.php index 1f38d6ab..39d68032 100644 --- a/app/views/main-menu.php +++ b/app/views/main-menu.php @@ -14,7 +14,8 @@ $hasManga = stripos($_SERVER['REQUEST_URI'], 'manga') !== FALSE; a( $urlGenerator->defaultUrl($url_type), - $whose . ucfirst($url_type) . ' List' + $whose . ucfirst($url_type) . ' List', + ['aria-current'=> 'page'] ) ?> get("show_{$url_type}_collection")): ?> [a( @@ -35,7 +36,8 @@ $hasManga = stripos($_SERVER['REQUEST_URI'], 'manga') !== FALSE; a( $url->generate("{$url_type}.collection.view") . $extraSegment, - $whose . ucfirst($url_type) . ' Collection' + $whose . ucfirst($url_type) . ' Collection', + ['aria-current'=> 'page'] ) ?> get("show_{$other_type}_collection")): ?> [a( @@ -79,15 +81,22 @@ $hasManga = stripos($_SERVER['REQUEST_URI'], 'manga') !== FALSE; +get('util')->isViewPage() && ($hasAnime || $hasManga)): ?> + diff --git a/src/AnimeClient/MenuGenerator.php b/src/AnimeClient/MenuGenerator.php index a42a9787..d08aa64e 100644 --- a/src/AnimeClient/MenuGenerator.php +++ b/src/AnimeClient/MenuGenerator.php @@ -105,7 +105,10 @@ final class MenuGenerator extends UrlGenerator { $has = StringType::from($this->path())->contains($path); $selected = ($has && mb_strlen($this->path()) >= mb_strlen($path)); - $link = $this->helper->a($this->url($path), $title); + $linkAttrs = ($selected) + ? ['aria-current' => 'location'] + : []; + $link = $this->helper->a($this->url($path), $title, $linkAttrs); $attrs = $selected ? ['class' => 'selected'] diff --git a/src/AnimeClient/Util.php b/src/AnimeClient/Util.php index 7e4d6f37..d427c3d3 100644 --- a/src/AnimeClient/Util.php +++ b/src/AnimeClient/Util.php @@ -54,6 +54,29 @@ class Util { $this->setContainer($container); } + /** + * Absolutely equal? + * + * @param $left + * @param $right + * @return bool + */ + public static function eq($left, $right): bool + { + return $left === $right; + } + + /** + * Set aria-current attribute based on a condition check + * + * @param bool $condition + * @return string + */ + public static function ariaCurrent(bool $condition): string + { + return $condition ? 'true' : 'false'; + } + /** * HTML selection helper function * @@ -63,7 +86,7 @@ class Util { */ public static function isSelected(string $left, string $right): string { - return ($left === $right) ? 'selected' : ''; + return static::eq($left, $right) ? 'selected' : ''; } /**