Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Edit File Modal Keyboard Trap

Abierto
#6,085 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 3 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Tranquilo
Stack tecnológico
angular, bootstrap, typescript

Línea de trabajo

Start by locating the Angular upload-item and upload-person edit-file modal components described in the issue, and check related issue #5502 for context. Reproduce the focus behavior in Safari with UVA-only or Embargo selected, then inspect the modal’s existing focus and dismissal handling. Done means keyboard focus enters and stays within the open modal, returns to its trigger on close, the dialog has an accessible name, and Escape still closes it.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

accessibility affects: 10.x affects: 9.x bug component: submission

@lgeggleston
Issue reported by University of Virginia (UVA) Library’s Assessment, Communications, and User Experience (ACE) team as part of internal DSpace 9 accessibility audit.

Issue 1 of 2: Edit File Modal Keyboard Trap

Describe the bug

Specifically in Safari, when the modal opens, keyboard focus is not properly managed. Users can tab out of the modal into background content and cannot tab back in, creating a functional keyboard trap. It appears to happen when UVA only or Embargo are selected. This violates the required modal dialog behavior defined in WCAG: Users must be able to move focus into and out of components using only the keyboard. The modal currently allows focus to escape but not return. When the modal appears, focus must move into it and remain within it until dismissed, preserving logical interaction order. The modal container lacks an accessible name via aria-labelledby, which can cause AT/browser combinations to incorrectly handle dialog focus. This issue blocks users from interacting with or closing the modal using keyboard-only navigation, making the modal inoperable for many users. Also affects: 2.1.2 No Keyboard Trap (Level A), 2.4.3 Focus Order (Level A), 4.1.2 Name, Role, Value (Level A)

Image
Page

Upload Item (Form)

WCAG Guideline

WCAG 2.1.1, 2.1.2, 2.4.3, and 4.1.2

To Reproduce

Relevant code

Start of code: \<ngb-modal-window role="dialog" tabindex="-1" aria-modal="true" class="d-block modal fade show"\>\<div role="document" class="modal-dialog modal-xl"\>\<div class="modal-content"\>

Expected behavior

Move focus into the modal when it opens: Focus has to move to the first meaningful control immediately when the modal appears. This is usually the close button, but can also be the first field. Trap focus inside the modal while it is open: Tab and Shift+Tab have to move only within the modal elements. The background content shouldn't receive focus. Ensure the modal has an accessible name Add an id to the title and reference it via aria-labelledby on the modal container Return focus to the button that opened the modal when it closes Retain the current functionality of closing modal by pressing Esc

Suggested fix / example code

Adding accessible name: \<ngb-modal-window role="dialog" aria-modal="true" aria-labelledby="edit-file-title" tabindex="-1"\> \<div class="modal-dialog modal-xl"\> \<div class="modal-content"\> \<div class="modal-header"\> \<h4 id="edit-file-title" class="modal-title"\>Edit file\</h4\> \<button type="button" class="btn-close" aria-label="Close"\>\</button\> \</div\> \<!-- modal body --\> \</div\>\</div\>\</ngb-modal-window\> Please note: the Javascript below are examples, but I didn't dive into the JS. The general functionality of what should be happening should hopefully be clear enough that you can make edits as needed. Move focus into modal when opened: // Called when opening the modal ngAfterViewInit() { const closeBtn = this.elementRef.nativeElement.querySelector('.btn-close'); (closeBtn || this.elementRef.nativeElement).focus();} Trap focus into modal: @HostListener('keydown', ['$event']) handleTabTrap(event: KeyboardEvent) { const focusableSelectors = [ 'button:not([disabled])', '[href]', 'input:not([disabled])', 'select:not([disabled])', 'textarea:not([disabled])', '[tabindex]:not([tabindex="-1"])' ]; const modal = this.elementRef.nativeElement; const focusable = Array.from(modal.querySelectorAll(focusableSelectors)); const first = focusable[0]; const last = focusable[focusable.length - 1]; if (event.key === 'Tab') { // Shift + Tab if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last.focus();} // Tab forward else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus();}}} Restore focus on close: // Before opening the modal storeTrigger(triggerElement: HTMLElement) { this.triggerEl = triggerElement;} // On modal close ngOnDestroy() { this.triggerEl?.focus();}

Issue 2 of 2: Edit File Modal Keyboard Trap

Describe the bug

Specifically in Safari, when the modal opens, keyboard focus is not properly managed. Users can tab out of the modal into background content and cannot tab back in, creating a functional keyboard trap. It appears to happen when UVA only or Embargo are selected. This violates the required modal dialog behavior defined in WCAG: Users must be able to move focus into and out of components using only the keyboard. The modal currently allows focus to escape but not return. When the modal appears, focus must move into it and remain within it until dismissed, preserving logical interaction order. The modal container lacks an accessible name via aria-labelledby, which can cause AT/browser combinations to incorrectly handle dialog focus. This issue blocks users from interacting with or closing the modal using keyboard-only navigation, making the modal inoperable for many users.

Page

Upload Person (Form)

WCAG Guideline

WCAG 2.1.1, 2.1.2, 2.4.3, 4.1.2

To Reproduce

Relevant code

Start of code snippet: \<ngb-modal-window role="dialog" tabindex="-1" aria-modal="true" class="d-block modal fade show"\>\<div role="document" class="modal-dialog modal-xl"\>\<div class="modal-content"\>\<ds-submission-section-upload-file-edit \_nghost-dspace-angular-c3076456883=""\>\<div \_ngcontent-dspace-angular-c3076456883=""\>\<div \_ngcontent-dspace-angular-c3076456883="" class="modal-header"\>\<h4 \_ngcontent-dspace-angular-c3076456883="" class="modal-title"\>Edit file\</h4\>\<button \_ngcontent-dspace-angular-c3076456883="" type="button" aria-label="Close" class="

Expected behavior

Move focus into the modal when it opens: Focus has to move to the first meaningful control immediately when the modal appears. This is usually the close button, but can also be the first field. Trap focus inside the modal while it is open: Tab and Shift+Tab have to move only within the modal elements. The background content shouldn't receive focus. Ensure the modal has an accessible name Add an id to the title and reference it via aria-labelledby on the modal container Return focus to the button that opened the modal when it closes Retain the current functionality of closing modal by pressing Esc

Suggested fix / example code

Adding accessible name: \<ngb-modal-window role="dialog" aria-modal="true" aria-labelledby="edit-file-title" tabindex="-1"\>\<div class="modal-dialog modal-xl"\>\<div class="modal-content"\>\<div class="modal-header"\>\<h4 id="edit-file-title" class="modal-title"\>Edit file\</h4\>\<button type="button" class="btn-close" aria-label="Close"\>\</button\>\</div\>\</div\> \</div\>\</ngb-modal-window\> Please note: the Javascript below are examples, but I didn't dive into the JS. The general functionality of what should be happening should hopefully be clear enough that you can make edits as needed. Move focus into modal when opened: // Called when opening the modal ngAfterViewInit() { const closeBtn = this.elementRef.nativeElement.querySelector('.btn-close'); (closeBtn || this.elementRef.nativeElement).focus();} Trap focus into modal: @HostListener('keydown', ['$event']) handleTabTrap(event: KeyboardEvent) { const focusableSelectors = [ 'button:not([disabled])', '[href]', 'input:not([disabled])', 'select:not([disabled])', 'textarea:not([disabled])', '[tabindex]:not([tabindex="-1"])' ]; const modal = this.elementRef.nativeElement; const focusable = Array.from(modal.querySelectorAll(focusableSelectors)); const first = focusable[0]; const last = focusable[focusable.length - 1]; if (event.key === 'Tab') { // Shift + Tab if (event.shiftKey && document.activeElement === first) { event.preventDefault(); last.focus(); } // Tab forward else if (!event.shiftKey && document.activeElement === last) { event.preventDefault(); first.focus(); } }} Restore focus on close: // Before opening the modal storeTrigger(triggerElement: HTMLElement) { this.triggerEl = triggerElement;} // On modal close ngOnDestroy() { this.triggerEl?.focus();}

Related work

https://github.com/DSpace/dspace-angular/issues/5502

Lenguaje dominante
TypeScript
Estrellas
180
Forks
577
Merge medio
2 d 12 h
PR fusionados (30 d)
111

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de DSpace/dspace-angular

Todos los issues de DSpace/dspace-angular

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.