Skip to content

Commit 8b492cf

Browse files
authored
Radio: Remove aria-required and aria-invalid (#5760)
1 parent 63ca6f2 commit 8b492cf

File tree

3 files changed

+5
-42
lines changed

3 files changed

+5
-42
lines changed

.changeset/red-lies-vanish.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@primer/react": minor
3+
---
4+
5+
Radio: Removes `aria-invalid` and `aria-required` from `Radio`, as they are not supported on the element's role.

packages/react/src/Radio/Radio.tsx

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type {ChangeEventHandler, InputHTMLAttributes, ReactElement} from 'react'
22
import React, {useContext} from 'react'
33
import type {SxProp} from '../sx'
4-
import type {FormValidationStatus} from '../utils/types/FormValidationStatus'
54
import {RadioGroupContext} from '../RadioGroup/RadioGroup'
65
import {clsx} from 'clsx'
76
import classes from './Radio.module.css'
@@ -35,10 +34,6 @@ export type RadioProps = {
3534
* Indicates whether the radio button must be checked before the form can be submitted
3635
*/
3736
required?: boolean
38-
/**
39-
* Only used to inform ARIA attributes. Individual radio inputs do not have validation styles.
40-
*/
41-
validationStatus?: FormValidationStatus
4237
} & InputHTMLAttributes<HTMLInputElement> &
4338
SxProp
4439

@@ -54,7 +49,6 @@ const Radio = React.forwardRef<HTMLInputElement, RadioProps>(
5449
onChange,
5550
sx: sxProp = defaultSxProp,
5651
required,
57-
validationStatus,
5852
value,
5953
className,
6054
...rest
@@ -77,7 +71,6 @@ const Radio = React.forwardRef<HTMLInputElement, RadioProps>(
7771

7872
if (sxProp !== defaultSxProp) {
7973
return (
80-
// eslint-disable-next-line github/a11y-role-supports-aria-props
8174
<Box
8275
as="input"
8376
sx={sxProp}
@@ -89,8 +82,6 @@ const Radio = React.forwardRef<HTMLInputElement, RadioProps>(
8982
checked={checked}
9083
aria-checked={checked ? 'true' : 'false'}
9184
required={required}
92-
aria-required={required ? 'true' : 'false'}
93-
aria-invalid={validationStatus === 'error' ? 'true' : 'false'}
9485
onChange={handleOnChange}
9586
className={clsx(className, sharedClasses.Input, classes.Radio)}
9687
{...rest}
@@ -99,7 +90,6 @@ const Radio = React.forwardRef<HTMLInputElement, RadioProps>(
9990
}
10091

10192
return (
102-
// eslint-disable-next-line github/a11y-role-supports-aria-props
10393
<input
10494
type="radio"
10595
value={value}
@@ -109,8 +99,6 @@ const Radio = React.forwardRef<HTMLInputElement, RadioProps>(
10999
checked={checked}
110100
aria-checked={checked ? 'true' : 'false'}
111101
required={required}
112-
aria-required={required ? 'true' : 'false'}
113-
aria-invalid={validationStatus === 'error' ? 'true' : 'false'}
114102
onChange={handleOnChange}
115103
className={clsx(className, sharedClasses.Input, classes.Radio)}
116104
{...rest}

packages/react/src/__tests__/Radio.test.tsx

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -150,34 +150,4 @@ describe('Radio', () => {
150150

151151
expect(radio).toHaveAttribute('aria-checked', 'true')
152152
})
153-
154-
it('renders an invalid aria state when validation prop indicates an error', () => {
155-
const handleChange = jest.fn()
156-
const {getByRole, rerender} = render(<Radio {...defaultProps} onChange={handleChange} />)
157-
158-
const radio = getByRole('radio') as HTMLInputElement
159-
160-
expect(radio).toHaveAttribute('aria-invalid', 'false')
161-
162-
rerender(<Radio {...defaultProps} onChange={handleChange} validationStatus="success" />)
163-
164-
expect(radio).toHaveAttribute('aria-invalid', 'false')
165-
166-
rerender(<Radio {...defaultProps} onChange={handleChange} validationStatus="error" />)
167-
168-
expect(radio).toHaveAttribute('aria-invalid', 'true')
169-
})
170-
171-
it('renders an aria state indicating the field is required', () => {
172-
const handleChange = jest.fn()
173-
const {getByRole, rerender} = render(<Radio {...defaultProps} onChange={handleChange} />)
174-
175-
const radio = getByRole('radio') as HTMLInputElement
176-
177-
expect(radio).toHaveAttribute('aria-required', 'false')
178-
179-
rerender(<Radio {...defaultProps} onChange={handleChange} required />)
180-
181-
expect(radio).toHaveAttribute('aria-required', 'true')
182-
})
183153
})

0 commit comments

Comments
 (0)