Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/material/datepicker/date-range-input.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ describe('MatDateRangeInput', () => {
fixture.detectChanges();
tick();

const popup = document.querySelector('.cdk-overlay-pane')!;
const popup = document.querySelector('.cdk-overlay-pane .mat-datepicker-content-container')!;
expect(popup).toBeTruthy();
expect(popup.getAttribute('aria-labelledby')).toBe(label.getAttribute('id'));
}));
Expand Down
16 changes: 4 additions & 12 deletions src/material/datepicker/datepicker-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ export class MatDatepickerContent<S, D = ExtractDateTypeFromSelection<S>>
{
private _subscriptions = new Subscription();
private _model: MatDateSelectionModel<S, D>;

/** Reference to the internal calendar component. */
@ViewChild(MatCalendar) _calendar: MatCalendar<D>;

Expand Down Expand Up @@ -154,6 +153,9 @@ export class MatDatepickerContent<S, D = ExtractDateTypeFromSelection<S>>
/** Portal with projected action buttons. */
_actionsPortal: TemplatePortal | null = null;

/** Id of the label for the `role="dialog"` element. */
_dialogLabelId: string | null;

constructor(
elementRef: ElementRef,
private _changeDetectorRef: ChangeDetectorRef,
Expand Down Expand Up @@ -622,14 +624,14 @@ export abstract class MatDatepickerBase<
instance.datepicker = this;
instance.color = this.color;
instance._actionsPortal = this._actionsPortal;
instance._dialogLabelId = this.datepickerInput.getOverlayLabelId();
}

/** Opens the overlay with the calendar. */
private _openOverlay(): void {
this._destroyOverlay();

const isDialog = this.touchUi;
const labelId = this.datepickerInput.getOverlayLabelId();
const portal = new ComponentPortal<MatDatepickerContent<S, D>>(
MatDatepickerContent,
this._viewContainerRef,
Expand All @@ -647,16 +649,6 @@ export abstract class MatDatepickerBase<
panelClass: `mat-datepicker-${isDialog ? 'dialog' : 'popup'}`,
}),
));
const overlayElement = overlayRef.overlayElement;
overlayElement.setAttribute('role', 'dialog');

if (labelId) {
overlayElement.setAttribute('aria-labelledby', labelId);
}

if (isDialog) {
overlayElement.setAttribute('aria-modal', 'true');
}

this._getCloseStream(overlayRef).subscribe(event => {
if (event) {
Expand Down
3 changes: 3 additions & 0 deletions src/material/datepicker/datepicker-content.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<div
cdkTrapFocus
role="dialog"
[attr.aria-modal]="true"
[attr.aria-labelledby]="_dialogLabelId ?? undefined"
class="mat-datepicker-content-container"
[class.mat-datepicker-content-container-with-custom-header]="datepicker.calendarHeaderComponent"
[class.mat-datepicker-content-container-with-actions]="_actionsPortal">
Expand Down
10 changes: 7 additions & 3 deletions src/material/datepicker/datepicker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ describe('MatDatepicker', () => {
fixture.detectChanges();
flush();

const popup = document.querySelector('.cdk-overlay-pane')!;
const popup = document.querySelector('.mat-datepicker-content-container')!;
expect(popup).toBeTruthy();
expect(popup.getAttribute('role')).toBe('dialog');
}));
Expand All @@ -254,7 +254,9 @@ describe('MatDatepicker', () => {
fixture.detectChanges();
flush();

const popup = document.querySelector('.cdk-overlay-pane')!;
const popup = document.querySelector(
'.cdk-overlay-pane .mat-datepicker-content-container',
)!;
expect(popup).toBeTruthy();
expect(popup.getAttribute('aria-labelledby')).toBe('test-label');
}),
Expand Down Expand Up @@ -1405,7 +1407,9 @@ describe('MatDatepicker', () => {
fixture.detectChanges();
flush();

const popup = document.querySelector('.cdk-overlay-pane')!;
const popup = document.querySelector(
'.cdk-overlay-pane .mat-datepicker-content-container',
)!;
expect(popup).toBeTruthy();
expect(popup.getAttribute('aria-labelledby')).toBe(label.getAttribute('id'));
}));
Expand Down
1 change: 1 addition & 0 deletions tools/public_api_guard/material/datepicker.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ export class MatDatepickerContent<S, D = ExtractDateTypeFromSelection<S>> extend
comparisonEnd: D | null;
comparisonStart: D | null;
datepicker: MatDatepickerBase<any, S, D>;
_dialogLabelId: string | null;
// (undocumented)
_getSelected(): D | DateRange<D> | null;
// (undocumented)
Expand Down