First off, I know there is a duplicate, but I have tried the solution and it does not work for me.
So, I need a faux-segmented control to be tabbable, or at least keyboard selectable. Getting the tab key to highlight the button is easy - I just add
tabindex="0"
To the element I want to be tabbable. Problem is, while I can get it to give the barely perceptible blue outline, I cannot select the button that's highlighted.
The solution proposed in the other question was to make my radio buttons visible with an opacity of zero, but that failed to do anything but ruin the buttons spacing.
The last pertinent I can think of is that the radio buttons themselves are set to.
display:none
Just to be absoluetly clear, selecting this with the mouse works fine - keyboard controls do not work. So, any ideas?
Page code, just in case you need it
<p class="segmented-control">
@foreach (var ruby in RubricData)
{
<input type="radio" id="@ruby.Id" ng-model="rubricStandardId" value="@ruby.Id"/>
<label for="@ruby.Id" class="sc-label" style="background-color:@ruby.RubricHexColor;" tabindex="0">@ruby.RubricSymbol
<span class="sc-tooltip">@ruby.RubricStandard</span></label>
}
</p>
You can use the label to wrap the input, and hide the input.
If I understand what you're trying to accomplish, you would style the input's label to reflect the state of the visually hidden radio input (such as: not focused and not checked, focused but not checked, focused and checked).
When you first tab into the radio control, the first option will be focused but not selected. You can then either check/select the first option by pressing spacebar or you can check/select an adjacent option using the arrow keys.
Pressing tab from within the radio control will bring you to the next tabbable element on the page, not the next option in the radio control.
Also, in your code above (OP), your radio input elements are missing a name attribute which means that each of your radio inputs that your for loop produces are treated as individual controls as opposed to multiple options for one control.
And according to WebAIM on keyboard accessibility testing and tabindex, only non-link and non-form elements need tabindex="0":
Run the code snippet below to see a working example. The snippet <p> text will provide some more reference.