Skip to content
Draft
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
5 changes: 5 additions & 0 deletions .changeset/calm-listboxes-notice.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-select': patch
---

Fix loading and empty menu notices to satisfy listbox ARIA required children.
18 changes: 16 additions & 2 deletions packages/react-select/src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2056,11 +2056,25 @@ export default class Select<
} else if (isLoading) {
const message = loadingMessage({ inputValue });
if (message === null) return null;
menuUI = <LoadingMessage {...commonProps}>{message}</LoadingMessage>;
menuUI = (
<LoadingMessage
{...commonProps}
innerProps={{ role: 'option', 'aria-disabled': true }}
>
{message}
</LoadingMessage>
);
} else {
const message = noOptionsMessage({ inputValue });
if (message === null) return null;
menuUI = <NoOptionsMessage {...commonProps}>{message}</NoOptionsMessage>;
menuUI = (
<NoOptionsMessage
{...commonProps}
innerProps={{ role: 'option', 'aria-disabled': true }}
>
{message}
</NoOptionsMessage>
);
}
const menuPlacementProps = {
minMenuHeight,
Expand Down
22 changes: 21 additions & 1 deletion packages/react-select/src/__tests__/Select.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { KeyboardEvent } from 'react';
import { render, fireEvent, EventType } from '@testing-library/react';
import { render, fireEvent, EventType, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import cases from 'jest-in-case';

Expand Down Expand Up @@ -418,6 +418,26 @@ cases(
}
);

test('no options message is rendered as a disabled option', () => {
const { getByRole } = render(
<Select {...BASIC_PROPS} menuIsOpen options={[]} />
);
const notice = within(getByRole('listbox')).getByRole('option');

expect(notice).toHaveTextContent('No options');
expect(notice).toHaveAttribute('aria-disabled', 'true');
});

test('loading message is rendered as a disabled option', () => {
const { getByRole } = render(
<Select {...BASIC_PROPS} menuIsOpen options={[]} isLoading />
);
const notice = within(getByRole('listbox')).getByRole('option');

expect(notice).toHaveTextContent('Loading...');
expect(notice).toHaveAttribute('aria-disabled', 'true');
});

cases(
'value prop',
({ props, expectedValue }) => {
Expand Down