I have a header with a bootstrap dropdown component and I am trying to enable keyboard navigation to that element by using tabindex. The following is the html and simple css:
HTML:
<span class="pull-right">
<span class="help-menu dropdown">
<span class="dropdown-toggle" data-toggle="dropdown" role="button">
<span class="help-header" tab-index="0">Help</span>
</span>
<ul class="dropdown-menu pull-right" tabindex="-1" role="menu">
<li tabindex="-1"><a [href]="/help.html" target="_blank">Docs</a></li>
</ul>
</span>
</span>
CSS:
.help-header{
&:after{
content: "\25BE"; //caret should be displayed!
}
}
.help-menu{
display: inline-block;
cursor: pointer;
background: aqua;
margin-top: 10px;
margin-right: 20px;
}
Here is the Fiddle link
Now, the Help doesn't get focus when I do a tab. But when I remove the tabindex from help-header class and apply it to either the span with class pull-right or the span with class help-menu and dropdown, the Help text gets the focus on tab. Even though, that gets the focus, I can't see the dropdown on hitting enter or space or the down arrow.
I'm really not sure how to make this work. I have been trying to figure it out since a while but I failed.
Am I missing any core concept of the tabindex here. Could anyone please help me or point me to a right direction.
Thanks a lot.
Cheers.