Show descriptions
At a point during the research, the scope of this study os shifted from the “radio button” to the “radio button group”, because there is no particular strong use case for a standalone “radio button”, and also because this use case is against the W3 Specification, the actual component to be considered is the “radio button group”, being composed of two or more radio buttons.
Also based on this fact and on the current state of the design systems, a more final anatomy was proposed.
This section shows the proposed visual constituents for the Radio Button Group, which is here considered to be the actual component, while the radio buttons are a part of the group.
The above anatomy is regular enough to be assembled in a way similar to (but more complex than) a <select>
. Attributes set on the group would allow the developer to set the whole group as “disabled”, “readonly”, vertically or horizontally laid out, types of display (like buttons, radio buttons, combobox, etc), and attributes set on the radio buttons would set their specific states, as we do with <option>
tags. It is important to understand that the function of radio buttons is almost the same as a <select>
tag, and this is why the comparison makes sense.
However, by being so regular and requiring a specific HTML structure, we would lose structural flexibility. For this, here is another proposal.
If the above proposal would accept other nodes as valid children, or at least a set of attributes that could replace some of the nodes (eg. an aria-label
to replace the “Group Label”), the flexibility could be reestablished, by allowing the construction of more complex layouts, eg. semantic differential scales, such as:
This could be achieved by combining table elements with radio button inputs and grouping attributes.
One could say it’s exactly the same behavior we have nowadays, because the radio buttons are bound together by the name
attribute. However, the current structure still depends on a fieldset
tag to visually group and label the collective of radio buttons, and this requirement prevents us from doing that exact table layout with actual tables, because we can’t use the fieldsets to group rows and put a legend
inside it as well.
Today, the structure of such semantic differential scale could be represented like this:
Question | Answer 1 | Answer 2 | … |
---|---|---|---|
(table cell) | (input name=1)(label) | (input name=1)(label) | … |
(table cell) | (input name=2)(label) | (input name=2)(label) | … |
Each field has its label
(or could have an aria-label
), but the group itself has no formal label. This could be solved by having a way of binding a label to a group by using attributes, like this:
Question | Answer 1 | Answer 2 | … |
---|---|---|---|
(groupLabel labels=1) | (input name=1)(label) | (input name=1)(label) | … |
(groupLabel labels=1) | (input name=2)(label) | (input name=2)(label) | … |
The above case creates a new tag (or an unsemantic tag with a new aria-attribute) that labels the whole group by referring to its name.
Another alternative would be:
Question | Answer 1 | Answer 2 | … |
---|---|---|---|
(input name=1) | (option group=1) | (option group=1) | … |
(input name=1) | (option group=3) | (option group=2) | … |
In this case the label is the actual input, and it could have an appearance of a simple text. The answers, on the other hand, could be an alternative use for the <option>
tag, with an attribute to reference the name of the input. Selecting an option would change the value of the input.
The two main approaches presented above should be analysed in order to decide
<select>
tag that would make it behave visually like radio buttons