Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accessibility issue with ngbNav #4398

Closed
hussein2690 opened this issue Oct 13, 2022 · 4 comments · Fixed by #4488
Closed

Accessibility issue with ngbNav #4398

hussein2690 opened this issue Oct 13, 2022 · 4 comments · Fixed by #4488

Comments

@hussein2690
Copy link

hussein2690 commented Oct 13, 2022

Bug description:

The accessibility test require us to add role="tablist" to the <ul> element and by adding that we have to add role="tab" to the <li> element

Adding role="tablist" to the <ul> and adding role="tab" to the<li> will fix the accessibility issue with <li> for the issue shown in the screenshot below

image

However this will cause another issue with <a> element we are rendering inside the <li> and that because ngbNavLink directive will target the <a> and add another role="tab" to the <a> element, so now the <a> element with role="tab" is looking for perant element with role="tablist" see screenshot below

image

<ul ngbNav #navWide="ngbNav" role="tablist" [destroyOnHide]="false" tabResponsive class="nav-tabs" [(activeId)]="showFirstTab">
       <li ngbNavItem [ngbNavItem]="1" role="tab" >
            <a ngbNavLink>
                     Test
             </a>
        </li>
</ul>

Link to minimally-working StackBlitz that reproduces the issue:

https://stackblitz.com/edit/angular-54mh4h?file=src%2Fmain.ts

You can run an accessibility test with a lighthouse or axe DevTools

Versions of Angular, ng-bootstrap

Angular: 13

ng-bootstrap: 11

@maxokorokov
Copy link
Member

maxokorokov commented Oct 17, 2022

Hey, @hussein2690, could you please confirm that what you're suggesting is "we should not put role=tab on the <a>, element, but should put it on the <li> instead"?

Could you please provide some references to a11y docs/tools you're using?

Also you can workaround it:

@maxokorokov
Copy link
Member

note: maybe the solution would be adding role=presentation on the <li> element as in https://getbootstrap.com/docs/5.1/components/navs-tabs/#javascript-behavior

@stephanieleary
Copy link
Contributor

This is the same issue reported in #4090 and #4204. The ng-bootstrap examples often use <a> tags when they should use <button> The Bootstrap 5 nav examples do not exhibit the same errors because they are using <button>. #4206 addresses this by making it possible to use <button> in a nav item, but the docs and existing code will need to be updated , or role="tab" should be moved to the ngbNavItem directive. Having everyone update their code to <button> will be more consistent with Bootstrap 5 markup, but makes for an annoying upgrade.

@hussein2690 did mention the relevant testing tool: axe DevTools.

For background, see https://www.digitala11y.com/links-vs-buttons-a-perennial-problem/ and
https://speakerdeck.com/marcysutton/the-links-vs-buttons-showdown?slide=17 for guidelines on when to use which. The short version is: links when the user will be taken to another page with a full refresh, buttons when the user will stay on the current page but some content will change.

@stephanieleary
Copy link
Contributor

stephanieleary commented Oct 28, 2022

#4414 is incomplete, but demonstrates the simplest solution for this bug: adding <button> to the selector for [ngbNavLink], and adding role="presentation" to [ngbNavItem].

maxokorokov added a commit to maxokorokov/ng-bootstrap that referenced this issue Apr 3, 2023
For the non-ng-container-based markup a `role="presentation"` should be added on the `li` elements.

Fixes ng-bootstrap#4398
maxokorokov added a commit to maxokorokov/ng-bootstrap that referenced this issue Apr 3, 2023
For the non-ng-container-based markup a `role="presentation"` should be added on the `li` elements.

Fixes ng-bootstrap#4398
@maxokorokov maxokorokov added this to the 14.1.0 milestone Apr 3, 2023
maxokorokov added a commit to maxokorokov/ng-bootstrap that referenced this issue Apr 3, 2023
For the non-ng-container-based markup a `role="presentation"` should be added on the `li` elements.

Fixes ng-bootstrap#4398
maxokorokov added a commit that referenced this issue Apr 3, 2023
For the non-ng-container-based markup a `role="presentation"` should be added on the `li` elements.

Fixes #4398
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants