Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Fix focus trap

Benjamin Bädorfae8835eaee3b
diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts
index c978f2bd0ec..dd1c4f27837 100644
--- a/frontend/src/app/app.module.ts
+++ b/frontend/src/app/app.module.ts
@@ -93,6 +93,7 @@ import { OpenProjectDirectFileUploadService } from './core/file-upload/op-direct
import { OpenProjectStateModule } from 'core-app/core/state/openproject-state.module';
import { OpenprojectContentLoaderModule } from 'core-app/shared/components/op-content-loader/openproject-content-loader.module';
import { OpenProjectHeaderInterceptor } from 'core-app/features/hal/http/openproject-header-interceptor';
+import { A11yModule } from '@angular/cdk/a11y';
export function initializeServices(injector:Injector) {
return () => {
@@ -114,6 +115,8 @@ export function initializeServices(injector:Injector) {
imports: [
// The BrowserModule must only be loaded here!
BrowserModule,
+ A11yModule,
+
// Commons
OPSharedModule,
// Design System
diff --git a/frontend/src/app/shared/components/attribute-help-texts/attribute-help-text.modal.ts b/frontend/src/app/shared/components/attribute-help-texts/attribute-help-text.modal.ts
index b0833126183..0245e99d05c 100644
--- a/frontend/src/app/shared/components/attribute-help-texts/attribute-help-text.modal.ts
+++ b/frontend/src/app/shared/components/attribute-help-texts/attribute-help-text.modal.ts
@@ -53,10 +53,12 @@ export class AttributeHelpTextModalComponent extends OpModalComponent implements
public helpText:HelpTextResource = this.locals.helpText!;
- constructor(@Inject(OpModalLocalsToken) public locals:OpModalLocalsMap,
+ constructor(
+ @Inject(OpModalLocalsToken) public locals:OpModalLocalsMap,
readonly I18n:I18nService,
readonly cdRef:ChangeDetectorRef,
- readonly elementRef:ElementRef) {
+ readonly elementRef:ElementRef,
+ ) {
super(locals, cdRef, elementRef);
}
diff --git a/frontend/src/app/shared/components/attribute-help-texts/help-text.modal.html b/frontend/src/app/shared/components/attribute-help-texts/help-text.modal.html
index a0251f605b0..cf960dc6651 100644
--- a/frontend/src/app/shared/components/attribute-help-texts/help-text.modal.html
+++ b/frontend/src/app/shared/components/attribute-help-texts/help-text.modal.html
@@ -28,20 +28,21 @@
<div class="spot-action-bar--right">
<button
type="button"
- class="button button_no-margin spot-action-bar--action spot-modal--cancel-button"
+ class="button spot-action-bar--action spot-modal--cancel-button"
(click)="closeMe()"
>
{{ text.close }}
</button>
- <a
- class="help-text--edit-button button button_no-margin spot-action-bar--action"
+ <button
+ class="help-text--edit-button button spot-action-bar--action"
*ngIf="helpText.editText"
[attr.href]="helpTextLink"
[attr.title]="text.edit"
+ type="button"
>
<op-icon icon-classes="button--icon icon-edit"></op-icon>
<span class="button--text" [textContent]="text.edit"></span>
- </a>
+ </button>
</div>
</div>
</div>
diff --git a/frontend/src/app/shared/components/modal/modal-overlay.component.html b/frontend/src/app/shared/components/modal/modal-overlay.component.html
index fe1a61d6270..70fd959d7c5 100644
--- a/frontend/src/app/shared/components/modal/modal-overlay.component.html
+++ b/frontend/src/app/shared/components/modal/modal-overlay.component.html
@@ -4,10 +4,10 @@
'spot-modal-overlay_active': (activeModalRef$ | async) !== null,
'spot-modal-overlay_not-full-screen': notFullscreen
}"
+ #overlay
tabindex="0"
cdkFocusInitial
cdkTrapFocus
- [cdkTrapFocusAutoCapture]="true"
(click)="close()"
>
<button
diff --git a/frontend/src/app/shared/components/modal/modal-overlay.component.ts b/frontend/src/app/shared/components/modal/modal-overlay.component.ts
index b38a20c08d3..7287a34a8fd 100644
--- a/frontend/src/app/shared/components/modal/modal-overlay.component.ts
+++ b/frontend/src/app/shared/components/modal/modal-overlay.component.ts
@@ -30,6 +30,7 @@ import {
ChangeDetectionStrategy,
Component,
ComponentRef,
+ ElementRef,
OnInit,
ViewChild,
} from '@angular/core';
@@ -53,6 +54,7 @@ export class OpModalOverlayComponent implements OnInit {
public notFullscreen = false;
@ViewChild(CdkPortalOutlet) portalOutlet:CdkPortalOutlet;
+ @ViewChild('overlay') overlay:ElementRef;
activeModalData$ = this.modalService.activeModalData$;
activeModalInstance$ = this.modalService.activeModalInstance$;
@@ -100,6 +102,7 @@ export class OpModalOverlayComponent implements OnInit {
this.activeModalInstance$.next(instance);
setTimeout(() => {
+ this.overlay.nativeElement.focus();
// Focus on the first element
instance && instance.onOpen();
diff --git a/frontend/src/app/shared/components/modal/modal.service.ts b/frontend/src/app/shared/components/modal/modal.service.ts
index 3a2cae17628..ae215f0e1d9 100644
--- a/frontend/src/app/shared/components/modal/modal.service.ts
+++ b/frontend/src/app/shared/components/modal/modal.service.ts
@@ -51,10 +51,6 @@ export class OpModalService {
constructor(
private readonly injector:Injector,
) {
- const hostElement = document.createElement('div');
- hostElement.classList.add('spot-modal-overlay');
- document.body.appendChild(hostElement);
-
// Listen to keystrokes on window to close context menus
window.addEventListener('keydown', (evt:KeyboardEvent) => {
if (evt.key !== 'Escape') {
diff --git a/frontend/src/app/spot/components/drop-modal/drop-modal.component.html b/frontend/src/app/spot/components/drop-modal/drop-modal.component.html
index b9d622d49a2..8bd238a9cae 100644
--- a/frontend/src/app/spot/components/drop-modal/drop-modal.component.html
+++ b/frontend/src/app/spot/components/drop-modal/drop-modal.component.html
@@ -1,9 +1,12 @@
<ng-content select="[slot=trigger]"></ng-content>
<div
+ *ngIf="open"
[ngClass]="['spot-drop-modal--body', 'spot-container', alignmentClass]"
+
(click)="onBodyClick($event)"
+
cdkTrapFocus
- *ngIf="open"
+ tabindex="0"
>
<ng-content select="[slot=body]"></ng-content>
diff --git a/frontend/src/app/spot/spot.module.ts b/frontend/src/app/spot/spot.module.ts
index b7ec798807e..8ab5413d3db 100644
--- a/frontend/src/app/spot/spot.module.ts
+++ b/frontend/src/app/spot/spot.module.ts
@@ -4,6 +4,7 @@ import {
ReactiveFormsModule,
} from '@angular/forms';
import { CommonModule } from '@angular/common';
+import { A11yModule } from '@angular/cdk/a11y';
import { I18nService } from 'core-app/core/i18n/i18n.service';
import { SpotCheckboxComponent } from './components/checkbox/checkbox.component';
@@ -23,6 +24,7 @@ import { SpotSelectorFieldComponent } from './components/selector-field/selector
FormsModule,
ReactiveFormsModule,
CommonModule,
+ A11yModule,
],
providers: [