====== 2.3.2. Simulated radio buttons ======
===== Purpose =====
“Simulated” radio buttons do not use the standard HTML form elements for radio buttons, namely the '' '' fields. Simulated radio buttons are often used because they are more visually attractive.
Unlike checkboxes that permit multiple selections, only one radio button can be selected in a group of radio buttons.
===== Basic HTML code =====
The basic HTML code uses standard radio buttons:
Without JavaScript, a standard form is shown to the user.
===== Behaviour with JavaScript =====
With JavaScript, the behaviour of the simulated radio buttons must be the same as for standard radio buttons.
The scripts must handle the following points:
* The '''' elements and their content are replaced by the text that was initially in the '' '' tag.
* An image that represents an unselected radio button is added before each label. This image includes the following technical features:
* The attribute value ''aria-hidden="true"'' is applied to the image to hide it from users of screen readers.
* The ''alt'' attribute of the image describes the status of the radio button; for example, ''alt=”not selected “''.
* The ''role="radiogroup"'' attribute is applied to the container of the radio buttons. In the example, the '''' tag is used.
* The ''role="radio"'' attribute is applied to each of the radio buttons. In the example, '''' tags are used.
* The ''aria-checked="false"'' is applied to each of the radio buttons by default. This attribute value then changes dynamically to ''true'' when the radio button is selected and ''false'' when it is not.
* The radio buttons can be selected either by clicking on them or by using the ''space'' key when the focus is set on the radio button.
* By default, the ''tabindex="0"'' attribute is applied to the first and last radio buttons in the group, so that the user can set the focus either at the start or the end of the group of radio buttons. The ''tabindex="-1"'' attribute is applied to the other radio buttons in order to prevent access from the keyboard by default.
* As soon as a radio button is selected, the ''tabindex'' attribute of this button is set to ''0'' while the value for ''tabindex'' is set at ''-1'' for the other buttons in the group.
* When the focus is positioned on one of the radio buttons:
* Pressing on the ''Up arrow'' or ''Left arrow'' key moves the focus to the previous button, and selects it. If the focus was set on the first button in the group, then the last button in the group is selected.
* Pressing on the ''Down arrow'' or ''Right arrow'' moves the focus to the next radio button, and selects it. If the focus was set on the last button in the group, then the first button in the group is selected.
* Finally, if the checkboxes are preceded by a question, instruction, or important indication for understanding the meaning of the checkboxes, the ''aria-labelledby'' attribute is applied to the container of the checkboxes. The value of this attribute is retrieved from the ''id'' associated with the question, instruction, etc.
The resulting code in JavaScript is as follows:
===== Démonstration =====
* [[http://accede.info/demos/en/demo-boutons-radio-simules-accessibles-en/|Online demo of simulated radio buttons]].