Skip to content

Commit 973ba95

Browse files
committed
Update how aria-describedby is generated
1 parent 7ee6e06 commit 973ba95

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

packages/react-select/src/Select.tsx

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,25 @@ export default class Select<
12351235
this.setState({ ariaSelection: { value, ...actionMeta } });
12361236
};
12371237

1238+
getAriaDescribedByValue = () => {
1239+
const { ariaSelection } = this.state;
1240+
const ariaDescribedByIds = [];
1241+
1242+
if (this.hasValue() && ariaSelection?.action === 'initial-input-focus') {
1243+
ariaDescribedByIds.push(this.getElementId('live-region'));
1244+
}
1245+
1246+
if (!this.hasValue()) {
1247+
ariaDescribedByIds.push(this.getElementId('placeholder'));
1248+
}
1249+
1250+
if (this.props['aria-describedby'] != null) {
1251+
ariaDescribedByIds.push(this.props['aria-describedby']);
1252+
}
1253+
1254+
return ariaDescribedByIds.join(' ');
1255+
};
1256+
12381257
hasValue() {
12391258
const { selectValue } = this.state;
12401259
return selectValue.length > 0;
@@ -1710,7 +1729,7 @@ export default class Select<
17101729
required,
17111730
} = this.props;
17121731
const { Input } = this.getComponents();
1713-
const { inputIsHidden, ariaSelection } = this.state;
1732+
const { inputIsHidden } = this.state;
17141733
const { commonProps } = this;
17151734

17161735
const id = inputId || this.getElementId('input');
@@ -1736,22 +1755,9 @@ export default class Select<
17361755
...(!isSearchable && {
17371756
'aria-readonly': true,
17381757
}),
1739-
...(this.hasValue()
1740-
? ariaSelection?.action === 'initial-input-focus' && {
1741-
'aria-describedby': this.getElementId('live-region'),
1742-
}
1743-
: {
1744-
'aria-describedby': this.getElementId('placeholder'),
1745-
}),
1758+
'aria-describedby': this.getAriaDescribedByValue(),
17461759
};
17471760

1748-
// aria-describedby allows for multiple IDs to be specified, separated by a space
1749-
if (this.props['aria-describedby'] != null) {
1750-
ariaAttributes[
1751-
'aria-describedby'
1752-
] += ` ${this.props['aria-describedby']}`;
1753-
}
1754-
17551761
if (!isSearchable) {
17561762
// use a dummy input to maintain focus/blur functionality
17571763
return (

0 commit comments

Comments
 (0)