Skip to content

Commit

Permalink
fix(nav-icon): accessibility, role=button when no href (#1593)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arturo Castillo Delgado authored Feb 17, 2023
1 parent 2356ffa commit 0387bde
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,13 @@ export class MenuFlyout {
const triggerSlot = this.hostElement.querySelector(
'[slot="trigger"]'
) as HTMLElement;
if (triggerSlot && triggerSlot.tagName.toUpperCase() === 'SCALE-BUTTON') {
const tagName = triggerSlot ? triggerSlot.tagName.toUpperCase() : '';
// TODO a different, more global, solution less dependent on tag names
// would be great…
if (triggerSlot && tagName === 'SCALE-BUTTON') {
this.trigger = triggerSlot.shadowRoot.querySelector('button');
} else if (triggerSlot && tagName === 'SCALE-NAV-ICON') {
this.trigger = triggerSlot.querySelector('a');
} else {
this.trigger = triggerSlot;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,13 @@ export class Header {
refUserMenuToggle={(el) => (this.userMenuToggle = el)}
badge={badge}
badgeLabel={badgeLabel}
onKeyDown={(event) => {
// Handle Spacebar separately because actual trigger is an <a>
if (event.key === ' ') {
(event.target as HTMLElement).click();
event.preventDefault();
}
}}
>
{shortName}
</scale-nav-icon>
Expand Down Expand Up @@ -356,6 +363,13 @@ export class Header {
}}
badge={badge}
badgeLabel={badgeLabel}
onKeyDown={(event) => {
// Handle Spacebar separately because actual trigger is an <a>
if (event.key === ' ') {
(event.target as HTMLElement).click();
event.preventDefault();
}
}}
>
{shortName}
</scale-nav-icon>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ exports[`nav-icon should match snapshot 1`] = `
<scale-nav-icon>
<!---->
<li class="meta-navigation__item">
<a class="meta-navigation__item-link" href="javascript:void(0);">
<a class="meta-navigation__item-link" href="javascript:void(0);" role="button">
<scale-icon-undefined class="meta-navigation__item-link-icon"></scale-icon-undefined>
<span class="meta-navigation__item-label"></span>
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export class NavIcon {
this.refUserMenuToggle
}
href={this.href}
role={this.href === 'javascript:void(0);' ? 'button' : null}
onClick={this.clickLink}
onKeyDown={(event) => {
if (!this.refMobileMenuToggle) {
Expand Down

0 comments on commit 0387bde

Please sign in to comment.