Skip to content

Commit 3541651

Browse files
authored
Remove aria-checked from useCheckbox and useSwitch (#3687)
1 parent 3f7bb50 commit 3541651

File tree

5 files changed

+14
-25
lines changed

5 files changed

+14
-25
lines changed

packages/@react-aria/checkbox/src/useCheckbox.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ export function useCheckbox(props: AriaCheckboxProps, state: ToggleState, inputR
4444
return {
4545
inputProps: {
4646
...inputProps,
47-
checked: isSelected,
48-
'aria-checked': isIndeterminate ? 'mixed' : isSelected
47+
checked: isSelected
4948
}
5049
};
5150
}

packages/@react-aria/switch/src/useSwitch.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ export function useSwitch(props: AriaSwitchProps, state: ToggleState, ref: RefOb
3535
inputProps: {
3636
...inputProps,
3737
role: 'switch',
38-
checked: isSelected,
39-
'aria-checked': isSelected
38+
checked: isSelected
4039
}
4140
};
4241
}

packages/@react-spectrum/card/test/CardView.test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,8 +1036,8 @@ describe('CardView', function () {
10361036
let cards = tree.getAllByRole('gridcell');
10371037
expect(cards[0].parentNode).toHaveAttribute('aria-selected', 'true');
10381038
expect(cards[1].parentNode).toHaveAttribute('aria-selected', 'true');
1039-
expect(within(cards[0]).getByRole('checkbox')).toHaveAttribute('aria-checked', 'true');
1040-
expect(within(cards[1]).getByRole('checkbox')).toHaveAttribute('aria-checked', 'true');
1039+
expect(within(cards[0]).getByRole('checkbox').checked).toBeTruthy();
1040+
expect(within(cards[1]).getByRole('checkbox').checked).toBeTruthy();
10411041
});
10421042

10431043
it('CardView should support disabledKeys', function () {
@@ -1051,7 +1051,7 @@ describe('CardView', function () {
10511051
expect(document.activeElement).not.toBe(cards[0]);
10521052
expect(cards[0].parentNode).not.toHaveAttribute('aria-selected', 'true');
10531053
expect(within(cards[0]).getByRole('checkbox')).toHaveAttribute('disabled');
1054-
expect(within(cards[0]).getByRole('checkbox')).not.toHaveAttribute('aria-checked', 'true');
1054+
expect(within(cards[0]).getByRole('checkbox').checked).toBeFalsy();
10551055
expect(onSelectionChange).not.toHaveBeenCalled();
10561056
});
10571057

@@ -1072,17 +1072,17 @@ describe('CardView', function () {
10721072

10731073
expect(cards[0].parentNode).toHaveAttribute('aria-selected', 'true');
10741074
expect(cards[2].parentNode).toHaveAttribute('aria-selected', 'true');
1075-
expect(within(cards[0]).getByRole('checkbox')).toHaveAttribute('aria-checked', 'true');
1076-
expect(within(cards[2]).getByRole('checkbox')).toHaveAttribute('aria-checked', 'true');
1075+
expect(within(cards[0]).getByRole('checkbox').checked).toBeTruthy();
1076+
expect(within(cards[2]).getByRole('checkbox').checked).toBeTruthy();
10771077

10781078
triggerPress(cards[0]);
10791079
expect(new Set(onSelectionChange.mock.calls[2][0])).toEqual(new Set(['Title 3']));
10801080
expect(onSelectionChange).toHaveBeenCalledTimes(3);
10811081

10821082
expect(cards[0].parentNode).toHaveAttribute('aria-selected', 'false');
10831083
expect(cards[2].parentNode).toHaveAttribute('aria-selected', 'true');
1084-
expect(within(cards[0]).getByRole('checkbox')).toHaveAttribute('aria-checked', 'false');
1085-
expect(within(cards[2]).getByRole('checkbox')).toHaveAttribute('aria-checked', 'true');
1084+
expect(within(cards[0]).getByRole('checkbox').checked).toBeFalsy();
1085+
expect(within(cards[2]).getByRole('checkbox').checked).toBeTruthy();
10861086
});
10871087

10881088
it('CardView should support single selection', function () {
@@ -1096,23 +1096,23 @@ describe('CardView', function () {
10961096
expect(new Set(onSelectionChange.mock.calls[0][0])).toEqual(new Set(['Title 1']));
10971097
expect(onSelectionChange).toHaveBeenCalledTimes(1);
10981098
expect(cards[0].parentNode).toHaveAttribute('aria-selected', 'true');
1099-
expect(within(cards[0]).getByRole('checkbox')).toHaveAttribute('aria-checked', 'true');
1099+
expect(within(cards[0]).getByRole('checkbox').checked).toBeTruthy();
11001100

11011101
triggerPress(cards[2]);
11021102
expect(new Set(onSelectionChange.mock.calls[1][0])).toEqual(new Set(['Title 3']));
11031103
expect(onSelectionChange).toHaveBeenCalledTimes(2);
11041104
expect(cards[0].parentNode).toHaveAttribute('aria-selected', 'false');
11051105
expect(cards[2].parentNode).toHaveAttribute('aria-selected', 'true');
1106-
expect(within(cards[0]).getByRole('checkbox')).toHaveAttribute('aria-checked', 'false');
1107-
expect(within(cards[2]).getByRole('checkbox')).toHaveAttribute('aria-checked', 'true');
1106+
expect(within(cards[0]).getByRole('checkbox').checked).toBeFalsy();
1107+
expect(within(cards[2]).getByRole('checkbox').checked).toBeTruthy();
11081108

11091109
triggerPress(cards[2]);
11101110
expect(new Set(onSelectionChange.mock.calls[2][0])).toEqual(new Set([]));
11111111
expect(onSelectionChange).toHaveBeenCalledTimes(3);
11121112
expect(cards[0].parentNode).toHaveAttribute('aria-selected', 'false');
11131113
expect(cards[2].parentNode).toHaveAttribute('aria-selected', 'false');
1114-
expect(within(cards[0]).getByRole('checkbox')).toHaveAttribute('aria-checked', 'false');
1115-
expect(within(cards[2]).getByRole('checkbox')).toHaveAttribute('aria-checked', 'false');
1114+
expect(within(cards[0]).getByRole('checkbox').checked).toBeFalsy();
1115+
expect(within(cards[2]).getByRole('checkbox').checked).toBeFalsy();
11161116
});
11171117

11181118
it('CardView should support no selection', function () {

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,14 @@ describe('Checkbox', function () {
3232
let checkbox = getByLabelText('Click Me');
3333
expect(checkbox.value).toBe('on');
3434
expect(checkbox.checked).toBeFalsy();
35-
expect(checkbox).toHaveAttribute('aria-checked', 'false');
3635
expect(onChangeSpy).not.toHaveBeenCalled();
3736

3837
userEvent.click(checkbox);
39-
expect(checkbox).toHaveAttribute('aria-checked', 'true');
4038
expect(checkbox.checked).toBeTruthy();
4139
expect(onChangeSpy).toHaveBeenCalled();
4240
expect(onChangeSpy.mock.calls[0][0]).toBe(true);
4341

4442
userEvent.click(checkbox);
45-
expect(checkbox).toHaveAttribute('aria-checked', 'false');
4643
expect(onChangeSpy).toHaveBeenCalled();
4744
expect(onChangeSpy.mock.calls[1][0]).toBe(false);
4845

@@ -148,19 +145,16 @@ describe('Checkbox', function () {
148145

149146
let checkbox = getByLabelText('Click Me');
150147
expect(checkbox.value).toBe('on');
151-
expect(checkbox).toHaveAttribute('aria-checked', 'mixed');
152148
expect(checkbox.indeterminate).toBeTruthy();
153149
expect(checkbox.checked).toBeFalsy();
154150

155151
userEvent.click(checkbox);
156-
expect(checkbox).toHaveAttribute('aria-checked', 'mixed');
157152
expect(checkbox.indeterminate).toBeTruthy();
158153
expect(checkbox.checked).toBeTruthy();
159154
expect(onChangeSpy).toHaveBeenCalled();
160155
expect(onChangeSpy.mock.calls[0][0]).toBe(true);
161156

162157
userEvent.click(checkbox);
163-
expect(checkbox).toHaveAttribute('aria-checked', 'mixed');
164158
expect(checkbox.indeterminate).toBeTruthy();
165159
expect(checkbox.checked).toBeFalsy();
166160
expect(onChangeSpy.mock.calls[1][0]).toBe(false);

packages/@react-spectrum/switch/test/Switch.test.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,13 @@ describe('Switch', function () {
3232
let checkbox = getByLabelText('Click Me');
3333
expect(checkbox.value).toBe('on');
3434
expect(checkbox.checked).toBeFalsy();
35-
expect(checkbox).toHaveAttribute('aria-checked', 'false');
3635
expect(onChangeSpy).not.toHaveBeenCalled();
3736

3837
userEvent.click(checkbox);
39-
expect(checkbox).toHaveAttribute('aria-checked', 'true');
4038
expect(checkbox.checked).toBeTruthy();
4139
expect(onChangeSpy.mock.calls[0][0]).toBe(true);
4240

4341
userEvent.click(checkbox);
44-
expect(checkbox).toHaveAttribute('aria-checked', 'false');
4542
expect(onChangeSpy.mock.calls[1][0]).toBe(false);
4643

4744
// would test space key, but then it's just testing the browser, no need

0 commit comments

Comments
 (0)