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/37468 dynamic form a11y (#9328)

Benjamin Bädorfa4e136ac92e2
diff --git a/frontend/src/app/modules/common/dynamic-forms/components/dynamic-field-group-wrapper/dynamic-field-group-wrapper.component.html b/frontend/src/app/modules/common/dynamic-forms/components/dynamic-field-group-wrapper/dynamic-field-group-wrapper.component.html
index 73a7e034f04..541b70b6d07 100644
--- a/frontend/src/app/modules/common/dynamic-forms/components/dynamic-field-group-wrapper/dynamic-field-group-wrapper.component.html
+++ b/frontend/src/app/modules/common/dynamic-forms/components/dynamic-field-group-wrapper/dynamic-field-group-wrapper.component.html
@@ -1,31 +1,31 @@
-<fieldset class="form--fieldset -collapsible"
- [ngClass]="{'collapsed': to.collapsibleFieldGroupsCollapsed}"
- *ngIf="to?.collapsibleFieldGroups">
- <legend class="form--fieldset-legend"
- title="Show/hide"
- (click)="to.collapsibleFieldGroupsCollapsed = !to.collapsibleFieldGroupsCollapsed">
- <a href="#">
+<fieldset
+ class="op-fieldset op-fieldset_collapsible"
+ [ngClass]="{'op-fieldset_collapsed': to.collapsibleFieldGroupsCollapsed}"
+ *ngIf="to?.collapsibleFieldGroups"
+>
+ <legend class="op-fieldset--legend">
+ <button
+ title="Show/hide"
+ type="button"
+ class="op-fieldset--toggle"
+ (click)="to.collapsibleFieldGroupsCollapsed = !to.collapsibleFieldGroupsCollapsed"
+ >
{{ to.label }}
- </a>
+ </button>
</legend>
- <div
- [ngStyle]="{
- 'height': to.collapsibleFieldGroupsCollapsed ? 0 : 'auto',
- 'visibility': to.collapsibleFieldGroupsCollapsed ? 'hidden' : 'visible',
- 'overflow': to.collapsibleFieldGroupsCollapsed ? 'hidden' : 'visible'
- }"
- >
+ <div class="op-fieldset--fields">
<ng-container #fieldComponent></ng-container>
</div>
</fieldset>
-<ng-container *ngIf="!to?.collapsibleFieldGroups">
- <div>
- {{ to.label }}
- </div>
+<fieldset
+ class="op-fieldset"
+ *ngIf="!to?.collapsibleFieldGroups"
+>
+ <legend class="op-fieldset--legend">{{ to.label }}</legend>
- <div>
+ <div class="op-fieldset--fields">
<ng-container #fieldComponent></ng-container>
</div>
-</ng-container>
\ No newline at end of file
+</fieldset>
\ No newline at end of file
diff --git a/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/boolean-input/boolean-input.component.html b/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/boolean-input/boolean-input.component.html
index 2b167e412cc..f68ed30cc75 100644
--- a/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/boolean-input/boolean-input.component.html
+++ b/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/boolean-input/boolean-input.component.html
@@ -1,5 +1,7 @@
-<input type="checkbox"
- [attr.aria-required]="to.required"
- [attr.required]="to.required"
- [formControl]="formControl"
- [formlyAttributes]="field">
+<input
+ type="checkbox"
+ [attr.aria-required]="to.required"
+ [attr.required]="to.required"
+ [formControl]="formControl"
+ [formlyAttributes]="field"
+>
diff --git a/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/date-input/date-input.component.html b/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/date-input/date-input.component.html
index 05db6e32b75..7b95ebbc7d1 100644
--- a/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/date-input/date-input.component.html
+++ b/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/date-input/date-input.component.html
@@ -1,5 +1,6 @@
-<op-date-picker-adapter [required]="to.required"
- [disabled]="to.disabled"
- [formControl]="formControl"
- [formlyAttributes]="field">
-</op-date-picker-adapter>
\ No newline at end of file
+<op-date-picker-adapter
+ [required]="to.required"
+ [disabled]="to.disabled"
+ [formControl]="formControl"
+ [formlyAttributes]="field"
+></op-date-picker-adapter>
\ No newline at end of file
diff --git a/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/date-input/date-input.component.ts b/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/date-input/date-input.component.ts
index d338716b8b2..bcdb398900d 100644
--- a/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/date-input/date-input.component.ts
+++ b/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/date-input/date-input.component.ts
@@ -6,5 +6,4 @@ import { FieldType } from "@ngx-formly/core";
templateUrl: './date-input.component.html',
styleUrls: ['./date-input.component.scss'],
})
-export class DateInputComponent extends FieldType {
-}
+export class DateInputComponent extends FieldType {}
diff --git a/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/formattable-textarea-input/formattable-textarea-input.component.html b/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/formattable-textarea-input/formattable-textarea-input.component.html
index 293e7e41e53..1140c1834f4 100644
--- a/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/formattable-textarea-input/formattable-textarea-input.component.html
+++ b/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/formattable-textarea-input/formattable-textarea-input.component.html
@@ -1,4 +1,5 @@
-<op-formattable-control [templateOptions]="to"
- [formControl]="formControl"
- [formlyAttributes]="field">
-</op-formattable-control>
+<op-formattable-control
+ [templateOptions]="to"
+ [formControl]="formControl"
+ [formlyAttributes]="field"
+></op-formattable-control>
diff --git a/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/integer-input/integer-input.component.html b/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/integer-input/integer-input.component.html
index 809d85d6c10..2999bed6273 100644
--- a/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/integer-input/integer-input.component.html
+++ b/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/integer-input/integer-input.component.html
@@ -1,7 +1,8 @@
-<input [type]="to.type"
- [attr.aria-required]="to.required"
- [attr.required]="to.required"
- [attr.lang]="to.locale"
- [formControl]="formControl"
- [formlyAttributes]="field"
- class="op-input">
\ No newline at end of file
+<input
+ [type]="to.type"
+ [attr.required]="to.required"
+ [attr.lang]="to.locale"
+ [formControl]="formControl"
+ [formlyAttributes]="field"
+ class="op-input"
+>
\ No newline at end of file
diff --git a/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/select-input/select-input.component.html b/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/select-input/select-input.component.html
index c424022c152..a1dc144f501 100644
--- a/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/select-input/select-input.component.html
+++ b/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/select-input/select-input.component.html
@@ -1,17 +1,19 @@
-<ng-select [items]="to?.options | async"
- [formControl]="formControl"
- [formlyAttributes]="field"
- [attr.aria-required]="to.required"
- [attr.required]="to.required"
- [multiple]="to.multiple"
- [bindLabel]="to.bindLabel"
- [searchable]="to.searchable"
- [virtualScroll]="to.virtualScroll"
- [clearable]="to.clearable"
- [typeahead]="to.typeahead"
- [clearOnBackspace]="to.clearOnBackspace"
- [clearSearchOnAdd]="to.clearSearchOnAdd"
- [hideSelected]="to.hideSelected">
+<ng-select
+ [items]="to?.options | async"
+ [formControl]="formControl"
+ [formlyAttributes]="field"
+ [attr.aria-required]="to.required"
+ [attr.required]="to.required"
+ [multiple]="to.multiple"
+ [bindLabel]="to.bindLabel"
+ [searchable]="to.searchable"
+ [virtualScroll]="to.virtualScroll"
+ [clearable]="to.clearable"
+ [typeahead]="to.typeahead"
+ [clearOnBackspace]="to.clearOnBackspace"
+ [clearSearchOnAdd]="to.clearSearchOnAdd"
+ [hideSelected]="to.hideSelected"
+>
<ng-template ng-tag-tmp let-search="searchTerm">
<b [textContent]="to.text.add_new_action"></b>: {{search}}
</ng-template>
diff --git a/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/select-project-status-input/select-project-status-input.component.html b/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/select-project-status-input/select-project-status-input.component.html
index dc854349426..c33a932a718 100644
--- a/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/select-project-status-input/select-project-status-input.component.html
+++ b/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/select-project-status-input/select-project-status-input.component.html
@@ -1,13 +1,15 @@
-<ng-select [items]="to?.options | async"
- [formControl]="formControl"
- [formlyAttributes]="field"
- bindLabel="name"
- [searchable]="true"
- [virtualScroll]="true"
- [clearable]="false"
- [clearOnBackspace]="false"
- [clearSearchOnAdd]="false"
- [hideSelected]="true">
+<ng-select
+ [items]="to?.options | async"
+ [formControl]="formControl"
+ [formlyAttributes]="field"
+ bindLabel="name"
+ [searchable]="true"
+ [virtualScroll]="true"
+ [clearable]="false"
+ [clearOnBackspace]="false"
+ [clearSearchOnAdd]="false"
+ [hideSelected]="true"
+>
<ng-template ng-label-tmp let-item="item">
<span class="project-status--bulb -inline" [ngClass]="cssClass(item)"></span>
<span class="project-status--name" [ngClass]="cssClass(item)">{{item.name}}</span>
diff --git a/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/text-input/text-input.component.html b/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/text-input/text-input.component.html
index da0d99c050f..75f85a00380 100644
--- a/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/text-input/text-input.component.html
+++ b/frontend/src/app/modules/common/dynamic-forms/components/dynamic-inputs/text-input/text-input.component.html
@@ -1,6 +1,8 @@
-<input [type]="to.type"
- [attr.aria-required]="to.required"
- [attr.required]="to.required"
- [formControl]="formControl"
- [formlyAttributes]="field"
- class="op-input">
+<input
+ [type]="to.type"
+ [attr.aria-required]="to.required"
+ [attr.required]="to.required"
+ [formControl]="formControl"
+ [formlyAttributes]="field"
+ class="op-input"
+>
diff --git a/frontend/src/app/modules/common/forms/fieldset.sass b/frontend/src/app/modules/common/forms/fieldset.sass
new file mode 100644
index 00000000000..edeee9824ee
--- /dev/null
+++ b/frontend/src/app/modules/common/forms/fieldset.sass
@@ -0,0 +1,58 @@
+.op-fieldset
+ padding: 1rem 0 0
+ margin-bottom: 1rem
+ border: 0
+ min-width: 0
+ word-break: break-word
+
+ &_collapsible &
+ &--toggle::before
+ display: inline-block
+ content: ""
+ padding: .625rem .25rem 0
+
+ &_collapsed &
+ &--toggle::before
+ content: ""
+
+ &--fields
+ height: 0
+ visibility: hidden
+ overflow: hidden
+
+ &--legend
+ width: 100%
+ color: #4d4d4d
+ font-size: 1rem
+ font-weight: 700
+ line-height: 1.8
+ text-transform: uppercase
+ border-bottom: 1px solid #dfdfdf
+
+ &--toggle
+ text-align: left
+ width: 100%
+ border: 0
+ cursor: pointer
+ color: inherit
+ text-decoration: none
+ text-transform: inherit
+ background: transparent
+
+ &::before
+ font-family: openproject-icon-font
+ font-style: normal
+ font-weight: 400
+ font-variant: normal
+ text-transform: none
+ text-decoration: none
+ speak: none
+ line-height: 1
+ -webkit-font-smoothing: antialiased
+ -moz-osx-font-smoothing: grayscale
+ font-size: .75rem
+
+ &--fields
+ height: auto
+ visibility: visible
+ overflow: visible
diff --git a/frontend/src/app/modules/common/forms/form-field/form-field.component.html b/frontend/src/app/modules/common/forms/form-field/form-field.component.html
index f02dc85ccf2..7126dc90ea1 100644
--- a/frontend/src/app/modules/common/forms/form-field/form-field.component.html
+++ b/frontend/src/app/modules/common/forms/form-field/form-field.component.html
@@ -1,6 +1,10 @@
<ng-container *ngIf="!hidden">
<label class="op-form-field--label-wrap">
<div class="op-form-field--label">
+ <span
+ *ngIf="showErrorMessage"
+ class="Hidden for sighted"
+ >Invalid</span>
{{ label }}
<span *ngIf="required" class="op-form-field--label-indicator">*</span>
<attribute-help-text
@@ -22,18 +26,27 @@
<ng-content select="[slot=help-text]"></ng-content>
</div>
- <div class="op-form-field--errors"
- *ngIf="showErrorMessage">
+ <div
+ class="op-form-field--errors"
+ *ngIf="showErrorMessage"
+ [id]="errorsID"
+ >
<ng-content select="[slot=errors]"></ng-content>
</div>
</ng-container>
<ng-template #inputTemplate>
- <div class="op-form-field--description">
+ <div
+ class="op-form-field--description"
+ [id]="descriptionID"
+ >
<ng-content select="[slot=description]"></ng-content>
</div>
- <div class="op-form-field--input">
+ <div
+ class="op-form-field--input"
+ [attr.aria-describedby]="describedByID"
+ >
<ng-content select="[slot=input]"></ng-content>
</div>
</ng-template>
diff --git a/frontend/src/app/modules/common/forms/form-field/form-field.component.ts b/frontend/src/app/modules/common/forms/form-field/form-field.component.ts
index bc04c523d5a..bc1cb1e8dc3 100644
--- a/frontend/src/app/modules/common/forms/form-field/form-field.component.ts
+++ b/frontend/src/app/modules/common/forms/form-field/form-field.component.ts
@@ -32,26 +32,38 @@ export class OpFormFieldComponent {
@ContentChild(NgControl) ngControl:NgControl;
+ internalID = `op-form-field-${+new Date()}`;
+
+ get errorsID() {
+ return `${this.internalID}-errors`;
+ }
+
+ get descriptionID() {
+ return `${this.internalID}-description`;
+ }
+
+ get describedByID() {
+ return this.showErrorMessage ? this.errorsID : this.descriptionID;
+ }
+
get formControl():AbstractControl|undefined|null {
return this.ngControl?.control || this.control;
}
get showErrorMessage():boolean {
- let showErrorMessage = false;
-
if (!this.formControl) {
return false;
}
if (this.showValidationErrorOn === 'submit') {
- showErrorMessage = this.formControl.invalid && this._formGroupDirective?.submitted;
+ return this.formControl.invalid && this._formGroupDirective?.submitted;
} else if (this.showValidationErrorOn === 'blur') {
- showErrorMessage = this.formControl.invalid && this.formControl.touched;
+ return this.formControl.invalid && this.formControl.touched;
} else if (this.showValidationErrorOn === 'change') {
- showErrorMessage = this.formControl.invalid && this.formControl.dirty;
+ return this.formControl.invalid && this.formControl.dirty;
}
- return showErrorMessage;
+ return false;
}
constructor(
diff --git a/frontend/src/app/modules/common/forms/index.sass b/frontend/src/app/modules/common/forms/index.sass
index 3cbe43cf5ac..f67b666db2d 100644
--- a/frontend/src/app/modules/common/forms/index.sass
+++ b/frontend/src/app/modules/common/forms/index.sass
@@ -1,3 +1,4 @@
@import './form-field/form-field'
@import './form'
+@import './fieldset'
@import './highlighted-input'
diff --git a/frontend/src/app/modules/common/op-date-picker/op-date-picker.component.html b/frontend/src/app/modules/common/op-date-picker/op-date-picker.component.html
index 150c2cbd108..527d47d0ca2 100644
--- a/frontend/src/app/modules/common/op-date-picker/op-date-picker.component.html
+++ b/frontend/src/app/modules/common/op-date-picker/op-date-picker.component.html
@@ -1,13 +1,15 @@
-<input #dateInput
- [id]="id"
- [name]="name"
- [value]="initialDate"
- [ngClass]="classes + ' op-input'"
- [size]="size"
- [required]="required"
- [disabled]="disabled"
- (click)="openOnClick()"
- (keydown.escape)="close()"
- (blur)="closeOnOutsideClick($event)"
- (input)="onInputChange($event)"
- type="text">
+<input
+ #dateInput
+ [id]="id"
+ [name]="name"
+ [value]="initialDate"
+ [ngClass]="classes + ' op-input'"
+ [size]="size"
+ [required]="required"
+ [disabled]="disabled"
+ (click)="openOnClick()"
+ (keydown.escape)="close()"
+ (blur)="closeOnOutsideClick($event)"
+ (input)="onInputChange($event)"
+ type="text"
+>
diff --git a/frontend/src/app/modules/common/option-list/option-list.component.html b/frontend/src/app/modules/common/option-list/option-list.component.html
index d55552d456d..53058bafc81 100644
--- a/frontend/src/app/modules/common/option-list/option-list.component.html
+++ b/frontend/src/app/modules/common/option-list/option-list.component.html
@@ -3,11 +3,11 @@
[class]="getClassListForItem(option)"
>
<input
+ class="op-option-list--input"
type="radio"
[attr.name]="name"
[value]="option.value"
[(ngModel)]="selected"
- class="op-option-list--input"
[disabled]="option.disabled"
/>
<div>
diff --git a/spec/features/projects/attribute_help_texts_spec.rb b/spec/features/projects/attribute_help_texts_spec.rb
index 0a3a7d580c7..c1c5bc05e79 100644
--- a/spec/features/projects/attribute_help_texts_spec.rb
+++ b/spec/features/projects/attribute_help_texts_spec.rb
@@ -86,7 +86,7 @@ describe 'Project attribute help texts', type: :feature, js: true do
it 'shows the help text on the project create form' do
visit new_project_path
- page.find('.form--fieldset-legend', text: 'ADVANCED SETTINGS').click
+ page.find('.op-fieldset--legend', text: 'ADVANCED SETTINGS').click
expect(page).to have_selector('.op-form-field--label attribute-help-text', wait: 10)
diff --git a/spec/features/projects/project_status_administration_spec.rb b/spec/features/projects/project_status_administration_spec.rb
index cf0d7d51fb0..65f4c545fa0 100644
--- a/spec/features/projects/project_status_administration_spec.rb
+++ b/spec/features/projects/project_status_administration_spec.rb
@@ -60,7 +60,7 @@ describe 'Projects status administration', type: :feature, js: true do
visit new_project_path
# Create the project with status
- click_link 'Advanced settings'
+ click_button 'Advanced settings'
name_field.set_value 'New project'
status_field.select_option 'On track'
diff --git a/spec/features/projects/projects_custom_fields_spec.rb b/spec/features/projects/projects_custom_fields_spec.rb
index 1a17463fce7..04cf3355c7f 100644
--- a/spec/features/projects/projects_custom_fields_spec.rb
+++ b/spec/features/projects/projects_custom_fields_spec.rb
@@ -49,7 +49,7 @@ describe 'Projects custom fields', type: :feature, js: true do
name_field.set_value 'My project name'
- find('.form--fieldset-legend a', text: 'ADVANCED SETTINGS').click
+ find('.op-fieldset--toggle', text: 'ADVANCED SETTINGS').click
cf_field.expect_visible
@@ -79,7 +79,7 @@ describe 'Projects custom fields', type: :feature, js: true do
visit new_project_path
name_field.set_value 'My project name'
- find('.form--fieldset-legend a', text: 'ADVANCED SETTINGS').click
+ find('.op-fieldset--toggle', text: 'ADVANCED SETTINGS').click
default_int_field.expect_value default_int_custom_field.default_value.to_s
default_string_field.expect_value default_string_custom_field.default_value.to_s
@@ -144,7 +144,7 @@ describe 'Projects custom fields', type: :feature, js: true do
visit new_project_path
name_field.set_value 'My project name'
- find('.form--fieldset-legend a', text: 'ADVANCED SETTINGS').click
+ find('.op-fieldset--toggle', text: 'ADVANCED SETTINGS').click
float_field.set_value '10000.55'
@@ -169,7 +169,7 @@ describe 'Projects custom fields', type: :feature, js: true do
visit new_project_path
name_field.set_value 'My project name'
- find('.form--fieldset-legend a', text: 'ERWEITERTE EINSTELLUNGEN').click
+ find('.op-fieldset--toggle', text: 'ERWEITERTE EINSTELLUNGEN').click
float_field.set_value '10000,55'
@@ -235,7 +235,7 @@ describe 'Projects custom fields', type: :feature, js: true do
name_field.set_value 'My project name'
- find('.form--fieldset-legend a', text: 'ADVANCED SETTINGS').click
+ find('.op-fieldset--toggle', text: 'ADVANCED SETTINGS').click
cf_field.expect_visible
cf_field.expect_no_option invisible_user
diff --git a/spec/features/projects/projects_spec.rb b/spec/features/projects/projects_spec.rb
index 83e9e8c2113..03c727f1916 100644
--- a/spec/features/projects/projects_spec.rb
+++ b/spec/features/projects/projects_spec.rb
@@ -101,7 +101,7 @@ describe 'Projects', type: :feature, js: true do
name_field.set_value 'Foo bar'
- find('.form--fieldset-legend a', text: 'ADVANCED SETTINGS').click
+ find('.op-fieldset--toggle', text: 'ADVANCED SETTINGS').click
list_field.select_option 'A', 'B'
@@ -206,7 +206,7 @@ describe 'Projects', type: :feature, js: true do
it 'hides the active field and the identifier' do
visit new_project_path
- find('.form--fieldset-legend a', text: 'ADVANCED SETTINGS').click
+ find('.op-fieldset--toggle', text: 'ADVANCED SETTINGS').click
expect(page).to have_no_content 'Active'
expect(page).to have_no_content 'Identifier'
@@ -244,7 +244,7 @@ describe 'Projects', type: :feature, js: true do
click_on 'Advanced settings'
- within('.form--fieldset') do
+ within('.op-fieldset') do
expect(page).to have_text 'Optional Foo'
expect(page).to have_no_text 'Required Foo'
end
diff --git a/spec/features/projects/template_spec.rb b/spec/features/projects/template_spec.rb
index 45c68b0d920..944876988d7 100644
--- a/spec/features/projects/template_spec.rb
+++ b/spec/features/projects/template_spec.rb
@@ -95,7 +95,7 @@ describe 'Project templates', type: :feature, js: true do
template_field.expect_selected 'My template'
# Updates the identifier in advanced settings
- page.find('.form--fieldset-legend', text: 'ADVANCED SETTINGS').click
+ page.find('.op-fieldset--toggle', text: 'ADVANCED SETTINGS').click
status_field.expect_selected 'ON TRACK'
# It does not show the copy meta flags