Skip to content

Commit d200ad5

Browse files
Fix 1413 - Remove readonly from radio and checkboxes. Use aria-readonly instead. (#1414)
1 parent 224e2d4 commit d200ad5

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

packages/@react-aria/checkbox/test/useCheckboxGroup.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ describe('useCheckboxGroup', () => {
218218
expect(checkboxes[0]).not.toHaveAttribute('disabled');
219219
});
220220

221-
it('sets readOnly on each checkbox', () => {
221+
it('sets aria-readonly="true" on each checkbox', () => {
222222
let {getAllByRole} = render(
223223
<CheckboxGroup
224224
groupProps={{label: 'Favorite Pet', isReadOnly: true}}
@@ -230,9 +230,9 @@ describe('useCheckboxGroup', () => {
230230
);
231231

232232
let checkboxes = getAllByRole('checkbox') as HTMLInputElement[];
233-
expect(checkboxes[0]).toHaveAttribute('readonly');
234-
expect(checkboxes[0]).toHaveAttribute('readonly');
235-
expect(checkboxes[0]).toHaveAttribute('readonly');
233+
expect(checkboxes[0]).toHaveAttribute('aria-readonly', 'true');
234+
expect(checkboxes[1]).toHaveAttribute('aria-readonly', 'true');
235+
expect(checkboxes[2]).toHaveAttribute('aria-readonly', 'true');
236236
});
237237

238238
it('should not update state for readonly checkbox', () => {

packages/@react-aria/radio/src/useRadio.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export function useRadio(props: RadioAriaProps, state: RadioGroupState, ref: Ref
8686
name: radioGroupNames.get(state),
8787
tabIndex,
8888
disabled: isDisabled,
89-
readOnly: isReadOnly,
89+
'aria-readonly': isReadOnly || undefined,
9090
required: isRequired,
9191
checked,
9292
value,

packages/@react-aria/toggle/src/useToggle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ export function useToggle(props: AriaToggleProps, state: ToggleState, ref: RefOb
6767
'aria-invalid': validationState === 'invalid' || undefined,
6868
'aria-errormessage': props['aria-errormessage'],
6969
'aria-controls': props['aria-controls'],
70+
'aria-readonly': isReadOnly || undefined,
7071
onChange,
7172
disabled: isDisabled,
7273
required: isRequired,
73-
readOnly: isReadOnly,
7474
value,
7575
name,
7676
type: 'checkbox',

packages/@react-spectrum/checkbox/test/CheckboxGroup.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ describe('CheckboxGroup', () => {
197197
expect(checkboxes[2]).not.toHaveAttribute('disabled');
198198
});
199199

200-
it('sets readOnly on each checkbox', () => {
200+
it('sets aria-readonly="true" on each checkbox', () => {
201201
let {getAllByRole} = render(
202202
<Provider theme={theme}>
203203
<CheckboxGroup label="Favorite Pet" isReadOnly>
@@ -209,9 +209,9 @@ describe('CheckboxGroup', () => {
209209
);
210210

211211
let checkboxes = getAllByRole('checkbox');
212-
expect(checkboxes[0]).toHaveAttribute('readonly');
213-
expect(checkboxes[1]).toHaveAttribute('readonly');
214-
expect(checkboxes[2]).toHaveAttribute('readonly');
212+
expect(checkboxes[0]).toHaveAttribute('aria-readonly', 'true');
213+
expect(checkboxes[1]).toHaveAttribute('aria-readonly', 'true');
214+
expect(checkboxes[2]).toHaveAttribute('aria-readonly', 'true');
215215
});
216216

217217
it('should not update state for readonly checkbox', () => {

packages/@react-spectrum/provider/test/Provider.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ describe('Provider', () => {
7474
let checkbox = getByLabelText('Test Checkbox');
7575
let switchComponent = getByLabelText('Test Switch');
7676

77-
expect(switchComponent).toHaveAttribute('readonly');
78-
expect(checkbox).toHaveAttribute('readonly');
77+
expect(switchComponent).toHaveAttribute('aria-readonly', 'true');
78+
expect(checkbox).toHaveAttribute('aria-readonly', 'true');
7979

8080
act(() => {
8181
userEvent.click(checkbox);

packages/@react-spectrum/radio/test/Radio.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,9 @@ describe('Radios', function () {
272272
let radios = getAllByRole('radio');
273273
expect(radioGroup).toBeTruthy();
274274
expect(radios.length).toBe(3);
275-
expect(radios[0]).toHaveAttribute('readonly');
276-
expect(radios[1]).toHaveAttribute('readonly');
277-
expect(radios[2]).toHaveAttribute('readonly');
275+
expect(radios[0]).toHaveAttribute('aria-readonly', 'true');
276+
expect(radios[1]).toHaveAttribute('aria-readonly', 'true');
277+
expect(radios[2]).toHaveAttribute('aria-readonly', 'true');
278278

279279
let cats = getByLabelText('Cats');
280280
userEvent.click(cats);

0 commit comments

Comments
 (0)