ADA Compliance, aria-current, Accessibility, Accessbile Menu
Permalink 1 user found helpful
PHP is not my strong suit. I have this code on a view.php file within a blocks > autonav folder. I'm trying to add: aria-current="page" to the current page <li> and <a> on the main menu. I don't want "aria-current="" on the other <li> and <a> items. This is what I've come up with, but does not work:
Any help is appreciated.
... foreach ($navItems as $ni) { $classes = array(); $airaCurrent = array(); if ($ni->isCurrent) { //class for the page currently being viewed $classes[] = 'drop-selected' ; $ariaCurrent[] = 'aria-current="page"'; } ... echo '<nav class="drop_down_menu" aria-labelledby="mainmenulabel"><ul>'; //opens the top-level menu foreach ($navItems as $ni) { echo '<li class="' . $ni->classes . '" ' . $ni->airaCurrent . '>'; //opens a nav item $name = (isset($translate) && $translate == true) ? t($ni->name) : $ni->name; echo '<a href="' . $ni->url . '" target="' . $ni->target . '" class="' . $ni->classes . '" '. $ni->ariaCurrent .'>' . $name . '</a>';
Any help is appreciated.
You can try this:
- add an "ariaCurrentPage" property to the $ni object and set the value of the property to 'aria-current="page"'
- display the "ariaCurrentPage" value