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

aria-selected attribute is not set correctly when switching tabs #254

Closed
chaitanyagupta opened this issue Nov 5, 2018 · 3 comments
Closed
Assignees
Labels
enhancement potential improvement

Comments

@chaitanyagupta
Copy link
Contributor

When a user selects a tab, the active tab element should set its attribute aria-selected=true and all other tabs should set aria-selected=false. bootstrap.js does this and at least one popular theme relies on this.

For demo, take a look at the following pages:

  1. http://deftask-design.deftask.com.s3-website.us-east-2.amazonaws.com/bootstrap/index.html#features
    This uses bootstrap.js and you'll see that both tabs are switched correctly and the active tab is highlighted.

  2. Now look at http://deftask-design.deftask.com.s3-website.us-east-2.amazonaws.com/bn-tab-aria-selected-bug/index.html#features
    This uses bootstrap-native alongwith my fixes from Fix clicks on child elements of a tab #253. You will notice that tabs switch correctly but the active tab does not get highlighted correctly.

  3. Lastly look at http://deftask-design.deftask.com.s3-website.us-east-2.amazonaws.com/bn-tab-click-fix/index.html#features
    This uses the fixed bootstrap native from the previous example alongwith a little bit of event handling that sets aria-selected when tab is hidden or shown. In this example tabs switch correctly and the active tab is also highlighted correctly on switching.

The event handling code which fixes the issue is this:

document.querySelectorAll('[role=tab]').forEach(function (node) {
    node.addEventListener('shown.bs.tab', function (e) {
        e.currentTarget.setAttribute('aria-selected', true);
    });
    node.addEventListener('hidden.bs.tab', function (e) {
        e.currentTarget.setAttribute('aria-selected', false);
    });
});

The reason I have filed an issue is because I don't need to use this event handling code when using bootstrap.js. Only with bootstrap-native do I need it. So I think this should be fixed.

I am not sure what would be the correct way to fix this in code, which is why I have filed an issue and not a PR.

@thednp
Copy link
Owner

thednp commented Nov 5, 2018

Will look into it, thanks for reporting.

@thednp thednp added the enhancement potential improvement label Dec 3, 2018
thednp added a commit that referenced this issue Dec 3, 2018
* V4 fixed missing `aria-selected` from Tab #254
* V3 fixed missing `aria-expanded` from Tab #254
* further updates for #253
* documentation fixes and updates
thednp added a commit that referenced this issue Dec 3, 2018
* V4 fixed missing `aria-selected` from Tab #254
* V3 fixed missing `aria-expanded` from Tab #254
* further updates for #253
* documentation fixes and updates
@thednp
Copy link
Owner

thednp commented Dec 3, 2018

@chaitanyagupta please test latest master and let me know how it goes :)

@thednp thednp closed this as completed Dec 3, 2018
@chaitanyagupta
Copy link
Contributor Author

Hi @thednp I checked it and its fixed! Thanks you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement potential improvement
Projects
None yet
Development

No branches or pull requests

2 participants