Skip to content

Commit 5b17607

Browse files
authored
omitting aria-selected if grid or option doesnt support selection (#2172)
1 parent 5d5fc02 commit 5b17607

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

packages/@react-aria/grid/src/useGridRow.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function useGridRow<T, C extends GridCollection<T>, S extends GridState<T
5959

6060
let rowProps: HTMLAttributes<HTMLElement> = {
6161
role: 'row',
62-
'aria-selected': isSelected,
62+
'aria-selected': state.selectionManager.selectionMode !== 'none' ? isSelected : undefined,
6363
...pressProps
6464
};
6565

packages/@react-aria/listbox/src/useOption.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export function useOption<T>(props: AriaOptionProps, state: ListState<T>, ref: R
109109
let optionProps = {
110110
role: 'option',
111111
'aria-disabled': isDisabled,
112-
'aria-selected': isSelected
112+
'aria-selected': state.selectionManager.selectionMode !== 'none' ? isSelected : undefined
113113
};
114114

115115
// Safari with VoiceOver on macOS misreads options with aria-labelledby or aria-label as simply "text".

packages/@react-spectrum/listbox/test/ListBox.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ describe('ListBox', function () {
9696
let i = 1;
9797
for (let item of items) {
9898
expect(item).toHaveAttribute('tabindex');
99-
expect(item).toHaveAttribute('aria-selected');
99+
expect(item).not.toHaveAttribute('aria-selected');
100100
expect(item).toHaveAttribute('aria-disabled');
101101
expect(item).toHaveAttribute('aria-posinset', '' + i++);
102102
expect(item).toHaveAttribute('aria-setsize');
@@ -246,7 +246,7 @@ describe('ListBox', function () {
246246
});
247247

248248
it('supports disabled items', function () {
249-
let tree = renderComponent({onSelectionChange, disabledKeys: ['Baz'], autoFocus: 'first'});
249+
let tree = renderComponent({onSelectionChange, selectionMode: 'single', disabledKeys: ['Baz'], autoFocus: 'first'});
250250
let listbox = tree.getByRole('listbox');
251251
let options = within(listbox).getAllByRole('option');
252252

packages/@react-spectrum/table/test/Table.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ describe('TableView', function () {
195195
expect(rowheader).toHaveTextContent('Foo 2');
196196
expect(rowheader).toHaveAttribute('aria-colindex', '1');
197197

198-
expect(rows[1]).toHaveAttribute('aria-selected', 'false');
198+
expect(rows[1]).not.toHaveAttribute('aria-selected');
199199
expect(rows[1]).toHaveAttribute('aria-labelledby', rowheader.id);
200200

201201

@@ -355,7 +355,7 @@ describe('TableView', function () {
355355
expect(rowheader).toHaveTextContent('Foo 2');
356356
expect(rowheader).toHaveAttribute('aria-colindex', '1');
357357

358-
expect(rows[1]).toHaveAttribute('aria-selected', 'false');
358+
expect(rows[1]).not.toHaveAttribute('aria-selected');
359359
expect(rows[1]).toHaveAttribute('aria-labelledby', rowheader.id);
360360

361361
let cells = within(rowgroups[1]).getAllByRole('gridcell');

0 commit comments

Comments
 (0)