Skip to content

Commit 9485aff

Browse files
crisbetojelbourn
authored andcommitted
fix(bottom-sheet): bottom-sheet content not being read out by screen readers (#14534)
Currently we focus the first focusable element inside a bottom sheet as per the accessibility recommendations, however moving focus to the first item causes some screen readers not to read out the rest of the bottom sheet content. These changes switch to focusing the bottom sheet container by default which allows screen readers to read out everything. If users press tab, they'll land on the first tabbable element anyways. The old behavior can still be opted into via the autoFocus option. Relates to #10591.
1 parent f2a06ab commit 9485aff

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/lib/bottom-sheet/bottom-sheet-config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,11 @@ export class MatBottomSheetConfig<D = any> {
4747
*/
4848
closeOnNavigation?: boolean = true;
4949

50+
// Note that this is disabled by default, because while the a11y recommendations are to focus
51+
// the first focusable element, doing so prevents screen readers from reading out the
52+
// rest of the bottom sheet content.
5053
/** Whether the bottom sheet should focus the first focusable element on open. */
51-
autoFocus?: boolean = true;
54+
autoFocus?: boolean = false;
5255

5356
/**
5457
* Whether the bottom sheet should restore focus to the

src/lib/bottom-sheet/bottom-sheet.spec.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,18 +514,32 @@ describe('MatBottomSheet', () => {
514514
beforeEach(() => document.body.appendChild(overlayContainerElement));
515515
afterEach(() => document.body.removeChild(overlayContainerElement));
516516

517-
it('should focus the first tabbable element of the bottom sheet on open', fakeAsync(() => {
517+
it('should focus the bottom sheet container by default', fakeAsync(() => {
518518
bottomSheet.open(PizzaMsg, {
519-
viewContainerRef: testViewContainerRef
519+
viewContainerRef: testViewContainerRef,
520520
});
521521

522522
viewContainerFixture.detectChanges();
523523
flushMicrotasks();
524524

525-
expect(document.activeElement!.tagName)
526-
.toBe('INPUT', 'Expected first tabbable element (input) in the sheet to be focused.');
525+
expect(document.activeElement!.tagName).toBe('MAT-BOTTOM-SHEET-CONTAINER',
526+
'Expected bottom sheet container to be focused.');
527527
}));
528528

529+
it('should focus the first tabbable element of the bottom sheet on open when' +
530+
'autoFocus is enabled', fakeAsync(() => {
531+
bottomSheet.open(PizzaMsg, {
532+
viewContainerRef: testViewContainerRef,
533+
autoFocus: true
534+
});
535+
536+
viewContainerFixture.detectChanges();
537+
flushMicrotasks();
538+
539+
expect(document.activeElement!.tagName).toBe('INPUT',
540+
'Expected first tabbable element (input) in the sheet to be focused.');
541+
}));
542+
529543
it('should allow disabling focus of the first tabbable element', fakeAsync(() => {
530544
bottomSheet.open(PizzaMsg, {
531545
viewContainerRef: testViewContainerRef,

0 commit comments

Comments
 (0)