Skip to content

Commit 9f913aa

Browse files
authored
fix(material/select): VoiceOver reading out blank space (#21733)
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.
1 parent 8f558ee commit 9f913aa

File tree

4 files changed

+22
-4
lines changed

4 files changed

+22
-4
lines changed

src/material-experimental/mdc-select/select.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
#fallbackOverlayOrigin="cdkOverlayOrigin"
1515
#trigger>
1616
<div class="mat-mdc-select-value" [ngSwitch]="empty" [attr.id]="_valueId">
17-
<span class="mat-mdc-select-placeholder" *ngSwitchCase="true">{{placeholder || '\u00A0'}}</span>
17+
<span class="mat-mdc-select-placeholder mat-mdc-select-min-line" *ngSwitchCase="true">{{placeholder}}</span>
1818
<span class="mat-mdc-select-value-text" *ngSwitchCase="false" [ngSwitch]="!!customTrigger">
19-
<span *ngSwitchDefault>{{triggerValue || '\u00A0'}}</span>
19+
<span class="mat-mdc-select-min-line" *ngSwitchDefault>{{triggerValue}}</span>
2020
<ng-content select="mat-select-trigger" *ngSwitchCase="true"></ng-content>
2121
</span>
2222
</div>

src/material-experimental/mdc-select/select.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,12 @@ $scale: 0.75 !default;
144144
}
145145
}
146146
}
147+
148+
// Used to prevent inline elements from collapsing if their text bindings
149+
// become empty. This is preferrable to inserting a blank space, because the
150+
// space can be read out by screen readers (see #21725).
151+
.mat-mdc-select-min-line:empty::before {
152+
content: ' ';
153+
white-space: pre;
154+
width: 1px;
155+
}

src/material/select/select.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
#origin="cdkOverlayOrigin"
1515
#trigger>
1616
<div class="mat-select-value" [ngSwitch]="empty" [attr.id]="_valueId">
17-
<span class="mat-select-placeholder" *ngSwitchCase="true">{{placeholder || '\u00A0'}}</span>
17+
<span class="mat-select-placeholder mat-select-min-line" *ngSwitchCase="true">{{placeholder}}</span>
1818
<span class="mat-select-value-text" *ngSwitchCase="false" [ngSwitch]="!!customTrigger">
19-
<span *ngSwitchDefault>{{triggerValue || '\u00A0'}}</span>
19+
<span class="mat-select-min-line" *ngSwitchDefault>{{triggerValue}}</span>
2020
<ng-content select="mat-select-trigger" *ngSwitchCase="true"></ng-content>
2121
</span>
2222
</div>

src/material/select/select.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,12 @@ $mat-select-placeholder-arrow-space: 2 * ($mat-select-arrow-size + $mat-select-a
147147
display: block;
148148
}
149149
}
150+
151+
// Used to prevent inline elements from collapsing if their text bindings
152+
// become empty. This is preferrable to inserting a blank space, because the
153+
// space can be read out by screen readers (see #21725).
154+
.mat-select-min-line:empty::before {
155+
content: ' ';
156+
white-space: pre;
157+
width: 1px;
158+
}

0 commit comments

Comments
 (0)