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

Blur active field before resetting or saving an edit field

Oliver Günther05d25478719e
diff --git a/frontend/src/app/shared/components/fields/edit/field-handler/hal-resource-edit-field-handler.ts b/frontend/src/app/shared/components/fields/edit/field-handler/hal-resource-edit-field-handler.ts
index d8a7372fdae..d92c7b278f8 100644
--- a/frontend/src/app/shared/components/fields/edit/field-handler/hal-resource-edit-field-handler.ts
+++ b/frontend/src/app/shared/components/fields/edit/field-handler/hal-resource-edit-field-handler.ts
@@ -122,6 +122,7 @@ export class HalResourceEditFieldHandler extends EditFieldHandler {
* Handle a user submitting the field (e.g, ng-change)
*/
public handleUserSubmit():Promise<any> {
+ this.blurActiveField();
this.onBeforeSubmit();
if (this.inFlight || this.form.editMode) {
@@ -179,12 +180,25 @@ export class HalResourceEditFieldHandler extends EditFieldHandler {
* Close the field, resetting it with its display value.
*/
public deactivate(focus = false) {
+ this.blurActiveField();
delete this.form.activeFields[this.fieldName];
this.onDestroy.next();
this.onDestroy.complete();
this.form.reset(this.fieldName, focus);
}
+ /**
+ * Safari scrolls around like crazy if you have a focused
+ * field that is about to be destroyed. So we blur it beforehand.
+ * @private
+ */
+ private blurActiveField() {
+ const active = document.activeElement as HTMLElement|null;
+ if (active?.blur) {
+ active.blur();
+ }
+ }
+
/**
* Returns whether the field has any errors set.
*/