fix(select): improvements for announcing placeholder and value on screenreaders (#22556)

- Hides select text from screen readers so it isn't announced twice (Android talkback needs this)
- Adds the placeholder text to be announced if there is no value
- Don't add a comma if there is no value/placeholder (NVDA speech viewer)
- Don't announce alert label twice
This commit is contained in:
Brandy Carney
2020-11-25 15:47:14 -05:00
committed by GitHub
parent c45c8d5564
commit ea52db66f0
3 changed files with 54 additions and 30 deletions

View File

@ -458,11 +458,12 @@ export class Select implements ComponentInterface {
const textPart = addPlaceholderClass ? 'placeholder' : 'text';
// If there is a label then we need to concatenate it with the
// current value and a comma so it separates nicely when the screen reader
// announces it, otherwise just announce the value
// current value (or placeholder) and a comma so it separates
// nicely when the screen reader announces it, otherwise just
// announce the value / placeholder
const displayLabel = labelText !== undefined
? `${displayValue}, ${labelText}`
: displayValue;
? (selectText !== '' ? `${selectText}, ${labelText}` : labelText)
: selectText;
return (
<Host
@ -477,7 +478,7 @@ export class Select implements ComponentInterface {
'select-disabled': disabled,
}}
>
<div class={selectTextClasses} part={textPart}>
<div aria-hidden="true" class={selectTextClasses} part={textPart}>
{selectText}
</div>
<div class="select-icon" role="presentation" part="icon">