Skip to content

Commit

Permalink
required prop accessibiltiy and functionality improvements (#5536)
Browse files Browse the repository at this point in the history
* Hide `RequiredInput` from screen readers

* Make `required` work without `name` prop
Synonymous to default HTML form elements

* Add changeset
  • Loading branch information
Rall3n authored Mar 22, 2023
1 parent 11a7b34 commit 925cd4a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/gorgeous-bottles-bow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'react-select': patch
---

`required` prop accessibiltiy and functionality improvements
6 changes: 3 additions & 3 deletions packages/react-select/src/Select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2022,12 +2022,12 @@ export default class Select<
const { delimiter, isDisabled, isMulti, name, required } = this.props;
const { selectValue } = this.state;

if (!name || isDisabled) return;

if (required && !this.hasValue()) {
if (required && !this.hasValue() && !isDisabled) {
return <RequiredInput name={name} onFocus={this.onValueInputFocus} />;
}

if (!name || isDisabled) return;

if (isMulti) {
if (delimiter) {
const value = selectValue
Expand Down
3 changes: 2 additions & 1 deletion packages/react-select/src/internal/RequiredInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import { FocusEventHandler, FunctionComponent } from 'react';
import { jsx } from '@emotion/react';

const RequiredInput: FunctionComponent<{
readonly name: string;
readonly name?: string;
readonly onFocus: FocusEventHandler<HTMLInputElement>;
}> = ({ name, onFocus }) => (
<input
required
name={name}
tabIndex={-1}
aria-hidden="true"
onFocus={onFocus}
css={{
label: 'requiredInput',
Expand Down

0 comments on commit 925cd4a

Please sign in to comment.