third_party/aria-practices/src/content/patterns/radio/examples/radio-activedescendant.html
This example implements the features of the Radio Group Pattern for two radio groups -- one for choosing a pizza crust and another for choosing a delivery method. This implementation uses aria-activedescendant for informing assistive technologies which radio button has visual focus.
Similar examples include:
tabindex for managing keyboard focus.The radio button referenced by aria-activedescendant is scrolled into view when it is not visible in the graphical rendering. This can occur under many conditions, but is most common when people with visual impairments use a browser's zoom feature to increase the size of content.
Uses CSS attribute selectors for synchronizing aria-checked state with the visual state indicator.
Uses CSS :hover and :focus pseudo-classes for styling visual keyboard focus and hover.
Because transparent borders are visible on some systems with high contrast enabled, only the focused element has a visible border. When focusable elements are not focused, they have a 0-width border and additional padding equal in width to the border that is used to indicate focus.
To ensure the inline SVG radio button graphics in the CSS file have sufficient contrast with the background when high contrast settings change the color of text content, CSS forced-color-adjust is set to auto on the svg graphics. This causes the colors of the stroke and fill of the circle elements to be overridden by the high contrast color setting. To make the background of the circle elements match the high contrast background color, the fill-opacity attribute of the outer circle is set to zero and the stroke-opacity attribute of the inner circle is set to zero. If forced-color-adjust were not used to override the colors specified for the stroke and fill properties, those colors would remain the same in high contrast mode, which could lead to insufficient contrast between the radio circle elements and the background or even make them invisible if their color matched the high contrast mode background.
Note: The explicit setting of forced-color-adjust is necessary because some browsers do not use auto as the default value for SVG graphics.
NOTE: When visual focus is on a radio button in the radio group, DOM focus remains on the radio group container and the value of aria-activedescendant on the radio group refers to the radio button that is visually indicated as focused. Where the following descriptions of keyboard commands mention focus, they are referring to the visual focus indicator, not DOM focus. For more information about this focus management technique, see Managing Focus in Composites Using aria-activedescendant.
| 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 |
|---|---|---|---|
radiogroup | ul | Identifies the element as a container for a group of radio buttons. | |
aria-labelledby="[IDREF]" | ul | Refers to the element that contains the label of the radio group. | |
tabindex="0" | ul |
aria--activedescendant is used to manage focus as described below.|
| | aria-activedescendant="[IDREF]" | ul |
|
| radio | | li |
radio button.|
| | aria-checked="false" | li |
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" | li |
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.|
Learn how to interpret and use assistive technology support data
To copy the following HTML code, please open it in CodePen.