Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
D8CORE-3502 - a11y fixes for nav menu (#227)
Browse files Browse the repository at this point in the history
* D8CORE-3502 - a11y fixes for nav menu
* D8CORE-3502: replaced backed-out JS change for nav toggle.
* Fixed bug which affected aria-label in firefox.
* Wrapped aria-label changes in an observer to respond to opening or closing.
  • Loading branch information
imonroe authored May 6, 2021
1 parent 9938615 commit f1530b3
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion dist/css/base.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/base.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/behaviors.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions src/js/components/secondary-nav/buttons/SubNavToggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ export default class SubNavToggle {
// Assign the event dispatcher and event registry.
this.eventRegistry = this.createEventRegistry(options);
this.dispatch = new EventHandlerDispatch(element, this);

// Label the toggle to indicate which menu it opens
this.elem.setAttribute('aria-label', 'Open the ' + this.parentNav.elem.innerText.trim() + ' menu');

// Create an observer to watch if the toggled menu changes state.
var self = this;
this.observer = new MutationObserver(function () {
var verb = 'Close';
if (self.elem.getAttribute('aria-expanded') == 'false') {
verb = 'Open';
}
self.elem.setAttribute('aria-label', verb + ' the ' + self.parentNav.elem.innerText.trim() + ' menu');
});
this.observer.observe(this.elem, { attributeFilter: ['aria-expanded'] });
}

/**
Expand Down Expand Up @@ -60,6 +74,7 @@ export default class SubNavToggle {
};

return Object.assign(registryDefaults, options.eventRegistry);

}

/**
Expand Down
9 changes: 5 additions & 4 deletions src/js/components/secondary-nav/common/events/OnEsc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import EventAbstract from './EventAbstract';
import {createEvent} from '../../../../polyfills/createEvent';
import { createEvent } from '../../../../polyfills/createEvent';

/**
* OnEsc
Expand All @@ -18,22 +18,23 @@ export default class OnEsc extends EventAbstract {
if (this.item.getDepth() > 1) {
this.event.stopPropagation();
this.parentNav.closeSubNav();
node = this.getElement('parentItem');
node = this.getElement('parentItem').parentElement.getElementsByTagName('button')[0];
}
else {
if (this.isDesktop()) {
this.masterNav.closeAllSubNavs();
node = this.getElement('first', this.item.parentNode);
node = this.elem;
}
else {
var closeAllEvent = createEvent('closeAllMobileNavs', {bubbles: true, data: this.item});
var closeAllEvent = createEvent('closeAllMobileNavs', { bubbles: true, data: this.item });
this.elem.dispatchEvent(closeAllEvent);
}
}

if (node) {
node.focus();
}

}

}
2 changes: 2 additions & 0 deletions src/scss/components/multi-menu/_multi-menu.scss
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@
color: $su-color-black;
text-decoration: underline;
}

}
}

Expand Down Expand Up @@ -348,6 +349,7 @@
> .su-multi-menu__menu {
display: none;
}

}

// Expanded items state.
Expand Down
1 change: 0 additions & 1 deletion templates/menus/macros/nav-menu.twig
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
{% set list_attributes = list_attributes.addClass(class_prefix ~ "__item") %}
{% if item.below is not empty %}
{% set list_attributes = list_attributes.addClass(class_prefix ~ "__item--parent") %}
{% set link_attributes = link_attributes.setAttribute('aria-expanded', 'false') %}
{% endif %}
{% if item.in_active_trail == true %}
{% set list_attributes = list_attributes.addClass(class_prefix ~ "__item--active-trail") %}
Expand Down
1 change: 0 additions & 1 deletion templates/menus/macros/secondary-nav-menu.twig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
{% set list_attributes = list_attributes.addClass(class_prefix ~ "__item") %}
{% if item.below is not empty %}
{% set list_attributes = list_attributes.addClass(class_prefix ~ "__item--parent") %}
{% set link_attributes = link_attributes.setAttribute('aria-expanded', 'false') %}
{% endif %}
{% if item.in_active_trail == true %}
{% set list_attributes = list_attributes.addClass(class_prefix ~ "__item--active-trail") %}
Expand Down

0 comments on commit f1530b3

Please sign in to comment.