Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for custom aria-describedby #5871

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion packages/react-select/src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export interface Props<
'aria-labelledby'?: AriaAttributes['aria-labelledby'];
/** Used to set the priority with which screen reader should treat updates to live regions. The possible settings are: off, polite (default) or assertive */
'aria-live'?: AriaAttributes['aria-live'];
/** HTML ID of an element that should be used as a description (for assistive tech) */
'aria-describedby'?: AriaAttributes['aria-describedby'];
/** Customise the messages used by the aria-live component */
ariaLiveMessages?: AriaLiveMessages<Option, IsMulti, Group>;
/** Focus the control when it is mounted */
Expand Down Expand Up @@ -1738,7 +1740,9 @@ export default class Select<
'aria-describedby': this.getElementId('live-region'),
}
: {
'aria-describedby': this.getElementId('placeholder'),
'aria-describedby':
this.props['aria-describedby'] ||
this.getElementId('placeholder'),
Comment on lines +1743 to +1745
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this should be:

Suggested change
'aria-describedby':
this.props['aria-describedby'] ||
this.getElementId('placeholder'),
'aria-describedby': [
this.props['aria-describedby'],
this.getElementId('placeholder'),
]
.filter(Boolean)
.join(' '),

}),
};

Expand Down
22 changes: 22 additions & 0 deletions packages/react-select/src/__tests__/Select.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2230,6 +2230,28 @@ test('accessibility > aria-activedescendant should not exist if hideSelectedOpti
).toBe('');
});

cases(
'accessibility > passes through aria-describedby prop',
({ props = { ...BASIC_PROPS, 'aria-describedby': 'testing' } }) => {
let { container } = render(<Select {...props} />);
expect(
container
.querySelector('input.react-select__input')!
.getAttribute('aria-describedby')
).toBe('testing');
},
{
'single select > should pass aria-describedby prop down to input': {},
'multi select > should pass aria-describedby prop down to input': {
props: {
...BASIC_PROPS,
'aria-describedby': 'testing',
isMulti: true,
},
},
}
);

cases(
'accessibility > passes through aria-labelledby prop',
({ props = { ...BASIC_PROPS, 'aria-labelledby': 'testing' } }) => {
Expand Down