Skip to content

Commit

Permalink
fix(material/select): VoiceOver reading out blank space (#21733)
Browse files Browse the repository at this point in the history
We have some inline elements inside `mat-select` which may collapse if their text bindings are
empty. To work around it we replace the content with a blank space. The problem is that
VoiceOver seems to read out this text.

These changes fix the issue by keeping the height of the elements using CSS instead.

Fixes #21725.
  • Loading branch information
crisbeto authored Feb 2, 2021
1 parent 8f558ee commit 9f913aa
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/material-experimental/mdc-select/select.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#fallbackOverlayOrigin="cdkOverlayOrigin"
#trigger>
<div class="mat-mdc-select-value" [ngSwitch]="empty" [attr.id]="_valueId">
<span class="mat-mdc-select-placeholder" *ngSwitchCase="true">{{placeholder || '\u00A0'}}</span>
<span class="mat-mdc-select-placeholder mat-mdc-select-min-line" *ngSwitchCase="true">{{placeholder}}</span>
<span class="mat-mdc-select-value-text" *ngSwitchCase="false" [ngSwitch]="!!customTrigger">
<span *ngSwitchDefault>{{triggerValue || '\u00A0'}}</span>
<span class="mat-mdc-select-min-line" *ngSwitchDefault>{{triggerValue}}</span>
<ng-content select="mat-select-trigger" *ngSwitchCase="true"></ng-content>
</span>
</div>
Expand Down
9 changes: 9 additions & 0 deletions src/material-experimental/mdc-select/select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,12 @@ $scale: 0.75 !default;
}
}
}

// Used to prevent inline elements from collapsing if their text bindings
// become empty. This is preferrable to inserting a blank space, because the
// space can be read out by screen readers (see #21725).
.mat-mdc-select-min-line:empty::before {
content: ' ';
white-space: pre;
width: 1px;
}
4 changes: 2 additions & 2 deletions src/material/select/select.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#origin="cdkOverlayOrigin"
#trigger>
<div class="mat-select-value" [ngSwitch]="empty" [attr.id]="_valueId">
<span class="mat-select-placeholder" *ngSwitchCase="true">{{placeholder || '\u00A0'}}</span>
<span class="mat-select-placeholder mat-select-min-line" *ngSwitchCase="true">{{placeholder}}</span>
<span class="mat-select-value-text" *ngSwitchCase="false" [ngSwitch]="!!customTrigger">
<span *ngSwitchDefault>{{triggerValue || '\u00A0'}}</span>
<span class="mat-select-min-line" *ngSwitchDefault>{{triggerValue}}</span>
<ng-content select="mat-select-trigger" *ngSwitchCase="true"></ng-content>
</span>
</div>
Expand Down
9 changes: 9 additions & 0 deletions src/material/select/select.scss
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,12 @@ $mat-select-placeholder-arrow-space: 2 * ($mat-select-arrow-size + $mat-select-a
display: block;
}
}

// Used to prevent inline elements from collapsing if their text bindings
// become empty. This is preferrable to inserting a blank space, because the
// space can be read out by screen readers (see #21725).
.mat-select-min-line:empty::before {
content: ' ';
white-space: pre;
width: 1px;
}

0 comments on commit 9f913aa

Please sign in to comment.