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

Use guard clause to break early

Kabiru Mwenja283a6bb97351
diff --git a/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.component.ts b/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.component.ts
index 0637b17e177..f59cacecc2d 100644
--- a/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.component.ts
+++ b/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.component.ts
@@ -297,28 +297,29 @@ export class CkeditorAugmentedTextareaComponent extends UntilDestroyedMixin impl
}
private setLabel() {
- const ckContent = this.element.querySelector<HTMLElement>('.ck-content')!;
const label = document.querySelector<HTMLLabelElement>(`label[for=${this.textAreaId}]`);
+ if (!label) {
+ console.error(`Please provide a label for the textarea with id ${this.textAreaId}`);
+ return;
+ }
- if (label) {
- let labelId;
- if (label.hasAttribute('id')) {
- labelId = label.getAttribute('id')!;
- } else {
- labelId = uniqueId('label-');
- label.setAttribute('id', labelId);
- }
-
- ckContent.removeAttribute('aria-label');
- ckContent.setAttribute('aria-labelledby', labelId);
+ const ckContent = this.element.querySelector<HTMLElement>('.ck-content')!;
- if (!this.labelClickSubscription) {
- this.labelClickSubscription = fromEvent(label, 'click')
- .pipe(this.untilDestroyed())
- .subscribe(() => ckContent.focus());
- }
+ let labelId;
+ if (label.hasAttribute('id')) {
+ labelId = label.getAttribute('id')!;
} else {
- console.error(`Please provide a label for the textarea with id ${this.textAreaId}`);
+ labelId = uniqueId('label-');
+ label.setAttribute('id', labelId);
+ }
+
+ ckContent.removeAttribute('aria-label');
+ ckContent.setAttribute('aria-labelledby', labelId);
+
+ if (!this.labelClickSubscription) {
+ this.labelClickSubscription = fromEvent(label, 'click')
+ .pipe(this.untilDestroyed())
+ .subscribe(() => ckContent.focus());
}
}
}