mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
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:
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user