Skip to content

Commit 175d4e4

Browse files
crisbetoannieyw
authored andcommitted
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. (cherry picked from commit f7bd224)
1 parent 87ee0b8 commit 175d4e4

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
@@ -544,7 +544,10 @@ export abstract class MatDatepickerBase<C extends MatDatepickerControl<D>, S,
544544
maxWidth: '80vw',
545545
maxHeight: '',
546546
position: {},
547-
autoFocus: true,
547+
548+
// Disable the dialog's automatic focus capturing, because it'll go to the close button
549+
// automatically. The calendar will move focus on its own once it renders.
550+
autoFocus: false,
548551

549552
// `MatDialog` has focus restoration built in, however we want to disable it since the
550553
// 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)