Skip to content

Commit

Permalink
Merge pull request #5240 from SamHecquet/fix/radio-aria-describedby
Browse files Browse the repository at this point in the history
fix(radio): add aria-describedby to improve accessibility
  • Loading branch information
segunadebayo committed Dec 15, 2021
2 parents 2bc045a + f6fd9d8 commit b983e4c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/olive-lemons-lay.md
@@ -0,0 +1,5 @@
---
"@chakra-ui/radio": patch
---

Add `aria-describedby` to the radio props to improve accessibility
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

1 comment on commit b983e4c

@vercel
Copy link

@vercel vercel bot commented on b983e4c Dec 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.