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

fix: support aria-placeholder #5657

Open
wants to merge 2 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
5 changes: 5 additions & 0 deletions .changeset/tall-needles-fly.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-select': minor
---

Add support for aria-placeholder
3 changes: 3 additions & 0 deletions packages/react-select/src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ export interface Props<
'aria-invalid'?: AriaAttributes['aria-invalid'];
/** Aria label (for assistive tech) */
'aria-label'?: AriaAttributes['aria-label'];
/** Aria placeholder (for assistive tech) */
'aria-placeholder'?: AriaAttributes['aria-placeholder'];
/** HTML ID of an element that should be used as the label (for assistive tech) */
'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 */
Expand Down Expand Up @@ -1619,6 +1621,7 @@ export default class Select<
'aria-expanded': menuIsOpen,
'aria-haspopup': true,
'aria-errormessage': this.props['aria-errormessage'],
'aria-placeholder': this.props['aria-placeholder'],
'aria-invalid': this.props['aria-invalid'],
'aria-label': this.props['aria-label'],
'aria-labelledby': this.props['aria-labelledby'],
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 @@ -2052,6 +2052,28 @@ cases(
}
);

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

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