Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/OptionList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ const OptionList: React.ForwardRefRenderFunction<RefOptionListProps, {}> = (_, r
<div
{...pickAttrs(passedProps)}
{...(!virtual ? getItemAriaProps(item, itemIndex) : {})}
aria-selected={isAriaSelected(value)}
aria-selected={virtual ? undefined : isAriaSelected(value)}
className={optionClassName}
title={optionTitle}
onMouseMove={() => {
Expand Down
78 changes: 78 additions & 0 deletions tests/Accessibility.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,82 @@ describe('Select.Accessibility', () => {
});
expectOpen(container);
});

// https://github.com/ant-design/ant-design/issues/53713
describe('Select ARIA attributes', () => {
it('should have correct aria and role attributes in virtual true', () => {
render(
<Select
id="virtual-select"
open={true}
options={[
{
value: '123',
},
{
value: '1234',
},
{
value: '12345',
},
]}
/>,
);

const dropdown = document.querySelector('#virtual-select_list');
expect(dropdown).toHaveAttribute('role', 'listbox');

const hiddenOptions = dropdown.querySelectorAll('div[style*="height: 0"] div[role="option"]');
expect(hiddenOptions.length).toBeGreaterThan(0);
hiddenOptions.forEach((option) => {
expect(option).toHaveAttribute('role', 'option');
const ariaSelected = option.getAttribute('aria-selected');
if (ariaSelected !== null) {
expect(['true', 'false']).toContain(ariaSelected);
}
});

const rcVirtual = document.querySelector('.rc-virtual-list-holder-inner');
expect(rcVirtual).not.toHaveAttribute('role');
const rcOptionItem = rcVirtual.querySelectorAll('.rc-select-item-option');

rcOptionItem.forEach((option) => {
expect(option).not.toHaveAttribute('role');
expect(option).not.toHaveAttribute('aria-selected');
});
});

it('should have correct aria and role attributes in virtual false', () => {
render(
<Select
id="virtual-select"
open
virtual={false}
options={[
{
value: '123',
},
{
value: '1234',
},
{
value: '12345',
},
]}
/>,
);

const dropdown = document.querySelector('#virtual-select_list');
expect(dropdown).toHaveAttribute('role', 'listbox');

const options = dropdown.querySelectorAll('.rc-select-item-option');
options.forEach((option) => {
expect(option).toHaveAttribute('role', 'option');
const ariaSelected = option.getAttribute('aria-selected');
if (ariaSelected !== null) {
expect(['true', 'false']).toContain(ariaSelected);
}
});
});
});
});
2 changes: 0 additions & 2 deletions tests/__snapshots__/OptionList.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ exports[`OptionList renders correctly virtual 1`] = `
</div>
<div
aria-label="value-1"
aria-selected="true"
class="rc-select-item rc-select-item-option rc-select-item-option-grouped rc-select-item-option-active rc-select-item-option-selected"
title="1"
>
Expand Down Expand Up @@ -73,7 +72,6 @@ exports[`OptionList renders correctly virtual 1`] = `
group2
</div>
<div
aria-selected="false"
class="rc-select-item rc-select-item-option rc-select-item-option-grouped"
title="2"
>
Expand Down
9 changes: 0 additions & 9 deletions tests/__snapshots__/Select.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ exports[`Select.Basic does not filter when filterOption value is false 1`] = `
style="display: flex; flex-direction: column;"
>
<div
aria-selected="false"
class="rc-select-item rc-select-item-option rc-select-item-option-active"
title="1"
>
Expand All @@ -63,7 +62,6 @@ exports[`Select.Basic does not filter when filterOption value is false 1`] = `
</span>
</div>
<div
aria-selected="false"
class="rc-select-item rc-select-item-option"
title="2"
>
Expand Down Expand Up @@ -418,7 +416,6 @@ exports[`Select.Basic render should support fieldName 1`] = `
groupLabel
</div>
<div
aria-selected="false"
class="rc-select-item rc-select-item-option rc-select-item-option-grouped rc-select-item-option-active"
title="label"
>
Expand Down Expand Up @@ -465,7 +462,6 @@ exports[`Select.Basic render should support fieldName 2`] = `
groupLabel
</div>
<div
aria-selected="false"
class="rc-select-item rc-select-item-option rc-select-item-option-grouped rc-select-item-option-active"
title="label"
>
Expand Down Expand Up @@ -512,7 +508,6 @@ exports[`Select.Basic render should support fieldName 3`] = `
groupLabel
</div>
<div
aria-selected="false"
class="rc-select-item rc-select-item-option rc-select-item-option-grouped rc-select-item-option-active"
title="label"
>
Expand Down Expand Up @@ -580,7 +575,6 @@ exports[`Select.Basic should contain falsy children 1`] = `
style="display: flex; flex-direction: column;"
>
<div
aria-selected="true"
class="rc-select-item rc-select-item-option rc-select-item-option-active rc-select-item-option-selected"
title="1"
>
Expand All @@ -603,7 +597,6 @@ exports[`Select.Basic should contain falsy children 1`] = `
</span>
</div>
<div
aria-selected="false"
class="rc-select-item rc-select-item-option"
title="2"
>
Expand Down Expand Up @@ -679,7 +672,6 @@ exports[`Select.Basic should render custom dropdown correctly 1`] = `
style="display: flex; flex-direction: column;"
>
<div
aria-selected="false"
class="rc-select-item rc-select-item-option rc-select-item-option-active"
title="1"
>
Expand All @@ -700,7 +692,6 @@ exports[`Select.Basic should render custom dropdown correctly 1`] = `
</span>
</div>
<div
aria-selected="false"
class="rc-select-item rc-select-item-option"
title="2"
>
Expand Down
3 changes: 0 additions & 3 deletions tests/__snapshots__/Tags.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ exports[`Select.Tags OptGroup renders correctly 1`] = `
Manager
</div>
<div
aria-selected="true"
class="rc-select-item rc-select-item-option rc-select-item-option-grouped rc-select-item-option-active rc-select-item-option-selected"
title="Jack"
>
Expand Down Expand Up @@ -179,7 +178,6 @@ exports[`Select.Tags OptGroup renders correctly 1`] = `
Engineer
</div>
<div
aria-selected="false"
class="rc-select-item rc-select-item-option rc-select-item-option-grouped"
title="yiminghe"
>
Expand All @@ -200,7 +198,6 @@ exports[`Select.Tags OptGroup renders correctly 1`] = `
</span>
</div>
<div
aria-selected="true"
class="rc-select-item rc-select-item-option rc-select-item-option-selected"
title="foo"
>
Expand Down
Loading