UPDATE The following problem occurs even after trying out the suggestions here. The latest code snippet demonstrates all 3 approaches of hiding a Radio Button and breaking ↓ / ↑ (Up/Down arrow keys) keyboard navigation in the radio group in Firefox & IE.
Suppose I have a Radio Group, each radio button with its label in a DIV. I use the arrow keys (up/down) to browse my radio buttons once at least one of them has focus.
One of the radio buttons in my Radio Group is hidden. It's in a DIV which has display:none;
(but I also tried visibility:hidden
and position:fixed;opacity:0
as possible alternatives).
I noticed that in Chrome, I can still use the up/down arrows to traverse the focused list without problems, but in Firefox and IE my navigation breaks when the focus is supposed to shift to the radiobutton over the hidden one.
To see this, do the following in this snippet:
1) In Firefox or IE vs. Chrome, first select Radio Button #1 with the mouse (in each column, to see each approach)
2) Now use the ↓ key to navigate to the end of the list: see that it breaks in Firefox and IE, but works in Chrome. The group is deselected and you lose focus in Firefox and IE.
3) You can also try it from the end in reverse order, it'll break the same way.
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min.js"></script>
<table>
<tr>
<td>
<span style="font-weight:bold;">With display:none</span>
</td>
<td>
<span style="font-weight:bold;">With visibility:hidden</span>
</td>
<td>
<span style="font-weight:bold;">With position:fixed;opacity:0;</span>
</td>
</tr>
<tr>
<td>
<div>
<input id="opt1a" type="radio" name="group" value="option1">
<label for="opt1a">Option 1</label>
</div>
<div>
<input id="opt2a" type="radio" name="group" value="option2">
<label for="opt2a">Option 2</label>
</div>
<div>
<input id="opt3a" type="radio" name="group" value="option3">
<label for="opt3a">Option 3</label>
</div>
<div style="display:none;">
<input id="optSecret" type="radio" name="group" value="optionSecret">
<label for="optSecreta">Secret Option</label>
</div>
<div>
<input id="opt5a" type="radio" name="group" value="option5">
<label for="opt5a">Option 5</label>
</div>
</td>
<td>
<div>
<input id="opt1b" type="radio" name="group2" value="option1">
<label for="opt1b">Option 1</label>
</div>
<div>
<input id="opt2b" type="radio" name="group2" value="option2">
<label for="opt2b">Option 2</label>
</div>
<div>
<input id="opt3b" type="radio" name="group2" value="option3">
<label for="opt3b">Option 3</label>
</div>
<div style="visibility:hidden;">
<input id="optSecretb" type="radio" name="group2" value="optionSecret">
<label for="optSecretb">Secret Option</label>
</div>
<div>
<input id="opt5b" type="radio" name="group2" value="option5">
<label for="opt5b">Option 5</label>
</div>
</td>
<td>
<div>
<input id="opt1c" type="radio" name="group3" value="option1">
<label for="opt1c">Option 1</label>
</div>
<div>
<input id="opt2c" type="radio" name="group3" value="option2">
<label for="opt2c">Option 2</label>
</div>
<div>
<input id="opt3c" type="radio" name="group3" value="option3">
<label for="opt3c">Option 3</label>
</div>
<div style="position:fixed;opacity:0;">
<input id="optSecretc" type="radio" name="group3" value="optionSecret">
<label for="optSecretc">Secret Option</label>
</div>
<div>
<input id="opt5c" type="radio" name="group3" value="option5">
<label for="opt5c">Option 5</label>
</div>
</td>
</tr>
</table>
Status:
display:none;
breaks the cycle over the hidden Radio Button, but collapses the space;visibility:hidden
breaks the cycle over the hidden Radio Button, but preserves the space;position:fixed;opacity:0
breaks the cycle once (temporary trap) but then resumes after pressing Arrow Up/Down to continue. But normal cycling is still broken.
display: none
, partially for this very reason. The solutions in the marked duplicate are the way to go. – Eskridgevisibility:hidden
gives the same behavior, only with taking up space.position:fixed;opacity:0;
keeps the cycle BUT with the trap of temporary loss in that radio button, so you do lose focus and then have to press Down twice. I'd be able to show this if we could re-open the thread. Could you remove your "duplicate" designation and allow me to post further info, this question is still outstanding. – Vein