Custom tabindex in modal does not work
See original GitHub issueDescribe the bug
Elements with tabindex
> 0 in the modal are never activated.
Steps to reproduce the bug
- Create a modal with elements having
tabindex
> 0, ex:
<template>
<b-modal title="Some title" id="edit-text-element-modal">
<input tabindex=0 type="text" placeholder="Some input which can be tabbed">
<template v-slot:modal-footer>
<button tabindex="2">
Cancel
</button>
<button tabindex="1">
OK
</button>
</template>
</b-modal>
</template>
- Display it somehow, ex.
mounted() {
this.$bvModal.show("edit-text-element-modal");
}
- When modal is opened, try to navigate with TAB through all the tabable elements (here:
input
and twobutton
s) - Elements with
tabindex
> 0 are never focused.
Expected behavior
Elements with tabindex
> 0 are focused in the correct order, i.e. “OK” button, “Cancel” button, input field.
Versions
Libraries:
- BootstrapVue: 2.14.0
- Vue: 2.6.11
Environment:
- Device: Lenovo Thinkpad
- OS: Ubuntu 20.04.2 LTS
- Browser: Firefox
- Version: 85.0 x64
Additional context
In short, this behavior caused problems when I wanted to change tab order of the buttons (make OK button get focus first even if it’s later in the DOM).
After looking through the https://github.com/bootstrap-vue/bootstrap-vue/blob/dev/src/components/modal/modal.js, I think it’s caused by tabTraps with tabindex="0"
. TAB index starts at index 0 and cannot leave that “0 level”, because when it is about to do so, it’s reset to one of the tabTraps at stays at 0.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
tabindex="-1" not working on bootstrap modal - Stack Overflow
If I keep pressing the tab key, the focus is going to the background and able to focus on other links.
Read more >JavaScript - Bootstrap
Multiple open modals not supported. Be sure not to open a modal while another is still visible. Showing more than one modal at...
Read more >Tabbing problem with Modal Popup on Modal Popup - Telerik
When a modal RadWindow is shown all other focusable elements on the page get their tabIndex attributes set to -1 to achieve the...
Read more >Using tabindex - web.dev
tabindex can be applied to any element - although it is not ... Perhaps you're working on some new Custom Elements that resemble...
Read more >Keyboard-navigable JavaScript widgets - Accessibility | MDN
Warning: avoid using positive values for tabindex . Elements with a positive tabindex are put before the default interactive elements on the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
That CSS
order
should solve my problem. Thank you.Yep, it’s intended. I’ve set their tabidex values to
-1
(a.k.a: skipped by tabbing - but programmatically focusable). If I leave them focusable the footer buttons become un-focusable. I’m not sure why at this point.