fix(focus-trap): apply aria-hidden to focus trap tab anchors (#14644)

These anchors at the book ends of a FocusTrap'ed element have focus listeners that redirect focus
back to the element. However, some screen readers may access these focus traps without moving
programmatic focus, leaving the SR user wondering why an empty control lives on the page.  Android
TalkBack currently treats this as a stop with no announcement (because it has no content). Adding
the aria-hidden should prevent these from being accessed in SR contexts while preserving the core
functionality of redirecting focus when it's moved linearly (e.g., with tab).
This commit is contained in:
Steven Xu
2019-01-15 14:27:10 -08:00
committed by vivian-hu
parent 220e6b2a3e
commit f66302d443
2 changed files with 2 additions and 0 deletions
@@ -101,6 +101,7 @@ describe('FocusTrap', () => {
) as HTMLElement[];
expect(anchors.every(current => current.getAttribute('tabindex') === '0')).toBe(true);
expect(anchors.every(current => current.getAttribute('aria-hidden') === 'true')).toBe(true);
fixture.componentInstance._isFocusTrapEnabled = false;
fixture.detectChanges();
+1
View File
@@ -304,6 +304,7 @@ export class FocusTrap {
this._toggleAnchorTabIndex(this._enabled, anchor);
anchor.classList.add('cdk-visually-hidden');
anchor.classList.add('cdk-focus-trap-anchor');
anchor.setAttribute('aria-hidden', 'true');
return anchor;
}