Skip to content

Commit f7bd224

Browse files
authored
fix(material/datepicker): a couple of accessibility issues in touch UI mode (#21228)
Resolves the following accessibility issues when the datepicker is in touch UI mode: * Focus was going directly to the close button, because that's the first element that the dialog's focus trap was running into. I've disabled the automatic focus redirection since the calendar has its own. * The calendar close button for screen readers was off-screen, because the dialog container has `position: static` and `overflow: auto`. Apart from the two issues above, I've also made it so the screen reader button's theme color matches the one of the calendar. This is mostly so the button doesn't look out of place if the calendar has a different theme and the user tabs into it.
1 parent e42d502 commit f7bd224

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

src/material/datepicker/calendar-body.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,12 @@ $mat-calendar-range-end-body-cell-size:
185185
}
186186
}
187187

188+
// Allows for the screen reader close button to be seen in touch UI mode.
189+
.mat-datepicker-dialog .mat-dialog-container {
190+
position: relative;
191+
overflow: visible;
192+
}
193+
188194
@include cdk-high-contrast(active, off) {
189195
.mat-datepicker-popup:not(:empty),
190196
.mat-calendar-body-selected {

src/material/datepicker/datepicker-base.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,10 @@ export abstract class MatDatepickerBase<C extends MatDatepickerControl<D>, S,
570570
maxWidth: '80vw',
571571
maxHeight: '',
572572
position: {},
573-
autoFocus: true,
573+
574+
// Disable the dialog's automatic focus capturing, because it'll go to the close button
575+
// automatically. The calendar will move focus on its own once it renders.
576+
autoFocus: false,
574577

575578
// `MatDialog` has focus restoration built in, however we want to disable it since the
576579
// datepicker also has focus restoration for dropdown mode. We want to do this, in order

src/material/datepicker/datepicker-content.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<button
2323
type="button"
2424
mat-raised-button
25-
color="primary"
25+
[color]="color || 'primary'"
2626
class="mat-datepicker-close-button"
2727
[class.cdk-visually-hidden]="!_closeButtonFocused"
2828
(focus)="_closeButtonFocused = true"

0 commit comments

Comments
 (0)