Skip to content

Commit ac463d3

Browse files
committed
Merge branch 'develop' of github.com:uswds/uswds into cm-disabled-forms-styles
2 parents a218bb9 + fae7f1a commit ac463d3

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

packages/usa-header/src/index.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ const toggleNav = (active) => {
106106
closeButton.focus();
107107
} else if (
108108
!safeActive &&
109-
document.activeElement === closeButton &&
110-
menuButton
109+
menuButton &&
110+
getComputedStyle(menuButton).display !== 'none'
111+
111112
) {
112-
// The mobile nav was just deactivated, and focus was on the close
113-
// button, which is no longer visible. We don't want the focus to
113+
// The mobile nav was just deactivated. We don't want the focus to
114114
// disappear into the void, so focus on the menu button if it's
115115
// visible (this may have been what the user was just focused on,
116116
// if they triggered the mobile nav by mistake).
@@ -147,7 +147,10 @@ const focusNavButton = (event) => {
147147

148148
// Only shift focus if within dropdown
149149
if (!event.target.matches(NAV_CONTROL)) {
150-
parentNavItem.querySelector(NAV_CONTROL).focus();
150+
const navControl = parentNavItem.querySelector(NAV_CONTROL)
151+
if (navControl) {
152+
navControl.focus()
153+
}
151154
}
152155
};
153156

packages/usa-icon/src/usa-icon.twig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
<div class="display-flex flex-wrap margin-top-5">
77
{% for item in icons.items %}
88
<div role="region" aria-atomic="true" class="font-sans-xl position-relative icon-example border-1px border-base-lighter hover:text-white hover:bg-primary-vivid hover:border-primary-darker " data-meta="{{ item.name }} {{ item.meta }}" aria-label="{{ item.name }} icon.">
9-
<button type="button" onclick="copyHTML(this)" class="bg-transparent cursor-pointer text-no-underline text-black display-flex width-card height-card flex-align-center flex-align-center border-0 flex-column flex-justify-center padding-2 hover:text-white" aria-label="Copy to clipboard" style="-webkit-user-select: text; -moz-user-select: text; -ms-user-select: text; user-select: text;">
9+
<button type="button" onclick="copyHTML(this)" class="bg-transparent cursor-pointer text-no-underline text-black display-flex width-card height-card flex-align-center flex-align-center border-0 flex-column flex-justify-center padding-2 hover:text-white" aria-label="Copy icon to clipboard" style="-webkit-user-select: text; -moz-user-select: text; -ms-user-select: text; user-select: text;">
1010
<svg class="usa-icon" aria-hidden="true" focusable="false" role="img">
1111
<use xlink:href="{{ icons.img_path }}/sprite.svg#{{ item.name }}"></use>
1212
</svg>
1313
<span class="font-sans-3xs margin-top-2 display-block" aria-hidden="true">{{ item.name }}</span>
1414
</button>
15-
<span aria-live="assertive" style="pointer-events:none" class="message-holder bottom-1 position-absolute font-sans-3xs text-bold display-block text-center left-0 width-full" aria-label="{{ item.name }}"></span>
15+
<span aria-live="assertive" style="pointer-events:none" class="message-holder bottom-1 position-absolute font-sans-3xs text-bold display-block text-center left-0 width-full"></span>
1616
</div>
1717
{% endfor %}
1818
</div>
@@ -42,7 +42,6 @@ function copyHTML(el){
4242
4343
message = document.createElement("span");
4444
message.setAttribute("id", "icon-copy-notice");
45-
message.setAttribute("aria-live", "assertive");
4645
message.innerHTML = "Copied to clipboard!";
4746
4847
/* Copy the text inside the text field */

packages/usa-nav/src/test/navigation.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ describe("navigation toggle", () => {
3232
let sandbox;
3333
let header;
3434
let nav;
35+
let navPrimary;
3536
let navControl;
3637
let overlay;
3738
let closeButton;
@@ -47,6 +48,7 @@ describe("navigation toggle", () => {
4748
navigation.on();
4849
header = body.querySelector(".usa-header");
4950
nav = body.querySelector(".usa-nav");
51+
navPrimary = body.querySelector(".usa-nav__primary");
5052
navControl = body.querySelector(".usa-nav__link");
5153
overlay = body.querySelector(".usa-overlay");
5254
closeButton = body.querySelector(".usa-nav__close");
@@ -150,6 +152,15 @@ describe("navigation toggle", () => {
150152
assert.strictEqual(accordionButton.getAttribute("aria-expanded"), "false");
151153
});
152154

155+
it("hides the nav when the Escape key is hit", () => {
156+
menuButton.click();
157+
navControl.focus();
158+
EVENTS.escape(navPrimary)
159+
assert.strictEqual(isVisible(nav), false);
160+
assert.strictEqual(isVisible(overlay), false);
161+
assert.strictEqual(document.activeElement, menuButton)
162+
});
163+
153164
it("collapses dropdowns when focus leaves nav", () => {
154165
menuButton.click();
155166
navLink.click();

0 commit comments

Comments
 (0)