angular / angular/components

bug(a11y): FocusTrap doesn't match browser/spec tab order in relation to Shadow DOM

Aperta
#32,265 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
area: cdk/a11y P3
Lingua principale
TypeScript
Stelle
25k
Fork
6.8k
Merge medio
1g 8h
PR unite (30g)
91

Descrizione

_EDIT: Removed the regression questions, it's not a regression_

### Description

A project I work with uses a component library based on https://lit.dev with `CUSTOM_ELEMENTS_SCHEMA`. They sometimes have regular, tabbable elements (``, ``) in their Shadow DOM and participate in the browser tab order as expected.

However, the CDK `FocusTrap` machinery and the `_getFirstTabbableElement` / `_getLastTabbableElement` don't quite consider enough of the [sequential focus navigation]. That means that focus trapping in a dialog only works it there's at least one *focusable area* not in a Shadow DOM.

For performance reason, I don't think it's necessary to build up the full [sequential focus navigation order]. It'd probably be sufficient to use the [`"DOM"` selection mechanism](https://html.spec.whatwg.org/multipage/interaction.html#selection-mechanism-dom) i.e. find the first/last [suitable sequentially focusable area] element in [shadow including tree order] (host - shadow dom - light dom).

[shadow including tree order]: https://dom.spec.whatwg.org/#concept-shadow-including-tree-order
[suitable sequentially focusable area]: https://html.spec.whatwg.org/multipage/interaction.html#suitable-sequentially-focusable-area
[sequential navigation search algorithm]: https://html.spec.whatwg.org/multipage/interaction.html#sequential-navigation-search-algorithm
[sequential focus navigation]: https://html.spec.whatwg.org/multipage/interaction.html#sequential-focus-navigation
[sequential focus navigation order]: https://html.spec.whatwg.org/multipage/interaction.html#sequential-focus-navigation-order

### Reproduction

StackBlitz link: https://stackblitz.com/edit/components-issue-starter-2e9thbl6?file=src%2Fmain.ts
Steps to reproduce:
1. Click in the preview window, preferably somewhere in the top part of the red area.
2. Tab to see the focus (outline) on the button in the red area
3. Tab to see the focus on the hidden trap element
4. Tab to see the focus (outline) on the button in the blue area
5. Keep Tabbing to see the focus actually get trapped

### Expected Behavior

The focus should remain trapped in the red area

### Actual Behavior

The focus moves past the red area, to an invisible item and then only gets trapped in the blue area.

### Environment

- Angular: 19, 20
- CDK/Material: 19, 20
- Browser(s): Edge, Firefox
- Operating System (e.g. Windows, macOS, Ubuntu): Windows 11 Enterprise

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia con il meccanismo di CDK FocusTrap e i relativi metodi _getFirstTabbableElement/_getLastTabbableElement, quindi riproduci il comportamento usando l’esempio StackBlitz collegato. Confronta l’attraversamento con shadow-including tree order e verifica che il focus rimanga all’interno dell’area intrappolata rossa invece di spostarsi attraverso l’elemento trap nascosto.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
angular, typescript
Ambito
accessibility, frontend
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.