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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Missing Form Label in work package comments rich text editor raises browser console error
Kabiru Mwenjaf58a7a6714b2
diff --git a/app/forms/work_packages/activities_tab/journals/notes_form.rb b/app/forms/work_packages/activities_tab/journals/notes_form.rbindex c1a459e954e..06a1e709ed1 100644--- a/app/forms/work_packages/activities_tab/journals/notes_form.rb+++ b/app/forms/work_packages/activities_tab/journals/notes_form.rb@@ -37,7 +37,8 @@ module WorkPackages::ActivitiesTab::Journalsrich_text_options: {showAttachments: false,resource:,- editor_type: "constrained"+ editor_type: "constrained",+ aria_label: I18n.t("activities.work_packages.activity_tab.label_type_to_comment")})enddiff --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.tsindex c0e6bfd7429..1e6921c0c05 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@@ -68,6 +68,8 @@ import { uniqueId } from 'lodash';export class CkeditorAugmentedTextareaComponent extends UntilDestroyedMixin implements OnInit {@Input() public textAreaId:string;+ @Input() public textAreaAriaLabel:string;+@Input() public previewContext:string;@Input() public macros:ICKEditorMacroType;@@ -215,7 +217,17 @@ export class CkeditorAugmentedTextareaComponent extends UntilDestroyedMixin implthis.setupAttachmentRemovalSignal(editor);}+ // Set initial labelthis.setLabel();++ // Use focusTracker to maintain aria-label as CKEditor re-renders ARIA-label every time on focus/blur+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access+ editor.ui.focusTracker.on('change:isFocused', (_evt:unknown, _name:string, isFocused:boolean) => {+ if (isFocused) {+ this.setLabel();+ }+ });+return editor;}@@ -288,23 +300,28 @@ export class CkeditorAugmentedTextareaComponent extends UntilDestroyedMixin impl}private setLabel() {- const label = document.querySelector<HTMLLabelElement>(`label[for=${this.textAreaId}]`)!;-const ckContent = this.element.querySelector<HTMLElement>('.ck-content')!;+ const label = document.querySelector<HTMLLabelElement>(`label[for=${this.textAreaId}]`);- let labelId;- if (label.hasAttribute('id')) {- labelId = label.getAttribute('id')!;- } else {- labelId = uniqueId('label-');- label.setAttribute('id', labelId);- }+ 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);+ ckContent.removeAttribute('aria-label');+ ckContent.setAttribute('aria-labelledby', labelId);- fromEvent(label, 'click')- .pipe(this.untilDestroyed())- .subscribe(() => ckContent.focus());+ fromEvent(label, 'click')+ .pipe(this.untilDestroyed())+ .subscribe(() => ckContent.focus());+ } else if (this.textAreaAriaLabel) {+ ckContent.setAttribute('aria-label', this.textAreaAriaLabel);+ } else {+ throw new Error(`Please provide a label for the textarea with id ${this.textAreaId} or set the textAreaAriaLabel property.`);+ }}}diff --git a/lib/primer/open_project/forms/rich_text_area.html.erb b/lib/primer/open_project/forms/rich_text_area.html.erbindex 0379d716982..461db3f7fbd 100644--- a/lib/primer/open_project/forms/rich_text_area.html.erb+++ b/lib/primer/open_project/forms/rich_text_area.html.erb@@ -5,7 +5,7 @@**@input.input_arguments) %><% end %><%= angular_component_tag "opce-ckeditor-augmented-textarea",- inputs: @rich_text_options.reverse_merge(+ inputs: rich_text_options.reverse_merge({textAreaId: @text_area_id,macros: false,diff --git a/lib/primer/open_project/forms/rich_text_area.rb b/lib/primer/open_project/forms/rich_text_area.rbindex c0276720a62..94064ed8f8a 100644--- a/lib/primer/open_project/forms/rich_text_area.rb+++ b/lib/primer/open_project/forms/rich_text_area.rb@@ -17,6 +17,14 @@ module Primer@rich_text_options = rich_text_options@text_area_id = rich_text_options.delete(:text_area_id) || builder.field_id(@input.name)end++ private++ def rich_text_options+ @rich_text_options.tap do |options|+ options[:textAreaAriaLabel] = options.delete(:aria_label) if options.key?(:aria_label)+ end+ endendendenddiff --git a/spec/features/activities/work_package/activity_tab_comment_editor_spec.rb b/spec/features/activities/work_package/activity_tab_comment_editor_spec.rbindex 3fab5263f17..3fb78b1611c 100644--- a/spec/features/activities/work_package/activity_tab_comment_editor_spec.rb+++ b/spec/features/activities/work_package/activity_tab_comment_editor_spec.rb@@ -118,6 +118,25 @@ RSpec.describe "Work package activity tab comment editor",endend+ describe "Accessibility" do+ current_user { admin }++ before do+ wp_page.visit!+ wp_page.wait_for_activity_tab+ end++ it "has an aria-label on the editor" do+ activity_tab.add_comment(text: "Sample text", save: false)++ activity_tab.expect_focus_on_editor++ within_test_selector("augmented-text-area-notes") do+ expect(page).to have_css(".ck-content[aria-label='Add a comment. Type @ to notify people.']")+ end+ end+ end+describe "Attachments" dolet(:image_fixture) { UploadedFile.load_from("spec/fixtures/files/image.png") }let(:editor) { Components::WysiwygEditor.new }