Skip to content

Commit

Permalink
fix(radio): add aria-describedby to improve accessibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel Hecquet authored and Samuel Hecquet committed Dec 13, 2021
1 parent 6386a43 commit c9266df
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/radio/src/use-radio.ts
Expand Up @@ -70,6 +70,10 @@ export interface UseRadioProps {
* @internal
*/
"data-radiogroup"?: any
/**
* Refers to the `id` of the element that labels the radio element.
*/
"aria-describedby"?: string
}

export function useRadio(props: UseRadioProps = {}) {
Expand All @@ -87,6 +91,7 @@ export function useRadio(props: UseRadioProps = {}) {
value,
id: idProp,
"data-radiogroup": dataRadioGroup,
"aria-describedby": ariaDescribedBy,
...htmlProps
} = props

Expand Down Expand Up @@ -216,6 +221,7 @@ export function useRadio(props: UseRadioProps = {}) {
"aria-disabled": ariaAttr(trulyDisabled),
"aria-required": ariaAttr(isRequired),
"data-readonly": dataAttr(isReadOnly),
"aria-describedby": ariaDescribedBy,
style: visuallyHiddenStyle,
}
},
Expand All @@ -235,6 +241,7 @@ export function useRadio(props: UseRadioProps = {}) {
isReadOnly,
isRequired,
isInvalid,
ariaDescribedBy,
],
)

Expand Down

0 comments on commit c9266df

Please sign in to comment.