third_party/aria-practices/src/content/patterns/radio/examples/radio-rating.html
Following is an example of a rating input that demonstrates the Radio Group Pattern. The rating is indicated by the number of stars selected by the user.
Similar examples include:
aria-valuetext to make it easy for assistive technology users to understand the meaning of the current value chosen on a ten-point satisfaction scale.aria-activedescendant for managing keyboard focus.tabindex for managing keyboard focus.Rating
To enhance perceivability when operating the radios, visual keyboard focus and hover are styled using CSS:
To ensure the borders of the stars and the focus ring have sufficient contrast with the background when high contrast settings invert colors, the color of the borders are synchronized with the color of the text content. For example, the color of the focus ring border is set to match the foreground color of high contrast mode text by specifying the CSS currentcolor value for the stroke property of the inline SVG polygon to draw the star borders and rect element used to draw the focus ring border. To make the background of the polygon and rect elements match the high contrast background color, the fill-opacity attribute of the rect is set to zero. If specific colors were instead used to specify the stroke and fill properties, those colors would remain the same in high contrast mode, which could lead to insufficient contrast between the star and the background or even make them invisible if their color matched the high contrast mode background.
Note: The SVG element needs to have the CSS forced-color-adjust property set to auto for the currentcolor value to be updated in high contrast mode. Some browsers do not use auto for the default value.
| Key | Function |
|---|---|
| Tab |
radio button in the radiogroup.radio button is not checked, focus moves to the first radio button in the group.| | Space |
radio button with focus is not checked, changes the state to checked.|
| Down arrow
Right arrow |
radio button in the group.radio button, moves focus to the first radio button.|
| Up arrow
Left arrow |
radio button in the group.radio button, moves focus to and checks the last radio button.|
| Role | Attributes | Element | Usage |
|---|---|---|---|
none | svg | The use of the none role on the SVG element ensures assistive technologies do not interpret the SVG element as an image or some other role. | |
radiogroup | div |
div element as a container for a group of radio buttons.|
| | aria-labelledby="ID_REFERENCE" | div | Refers to the element that contains the label of the radio group. |
| radio | | g | Identifies the g element as an ARIA radio button. |
| | aria-label="name" | g | Defines an accessible name that identifies the number of stars associated with the radio button (e.g. "one star", two stars", ..). |
| | tabindex="-1" | g |
|
| | tabindex="0" | g |
|
| | aria-checked="false" | g |
radio buttons which are not checked.[aria-checked="false"]) are used to synchronize the visual states with the value of the aria-checked attribute.::before pseudo-element is used to indicate visual state of unchecked radio buttons to support high contrast settings in operating systems and browsers.|
| | aria-checked="true" | g |
radio button which is checked.[aria-checked="true"]) are used to synchronize the visual states with the value of the aria-checked attribute.::before pseudo-element is used to indicate visual state of checked radio buttons to support high contrast settings in operating systems and browsers.|
To copy the following HTML code, please open it in CodePen.