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

[Op#58556] shrink an re-expand editor with content on blur/on focus as requested (#17068)

jjabari-op0dec5fab329a
diff --git a/app/components/work_packages/activities_tab/journals/new_component.sass b/app/components/work_packages/activities_tab/journals/new_component.sass
index 2deebf6c581..89f88e90c2e 100644
--- a/app/components/work_packages/activities_tab/journals/new_component.sass
+++ b/app/components/work_packages/activities_tab/journals/new_component.sass
@@ -10,6 +10,9 @@
width: calc(100% - 40px)
// specific ck editor adjustments
.ck-content
- max-height: 30vh
+ &.ck-focused
+ max-height: 30vh
+ &.ck-blurred
+ max-height: 10vh
.ck-editor__preview
max-height: 30vh
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 2a1baff4c47..be98750c1cd 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
@@ -81,6 +81,9 @@ export class CkeditorAugmentedTextareaComponent extends UntilDestroyedMixin impl
// Output blur events
@Output() editorBlur = new EventEmitter<void>();
+ // Output focus events
+ @Output() editorFocus = new EventEmitter<void>();
+
// Which template to include
public element:HTMLElement;
diff --git a/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.html b/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.html
index fa8ffc51dc5..4aa304fe891 100644
--- a/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.html
+++ b/frontend/src/app/shared/components/editor/components/ckeditor-augmented-textarea/ckeditor-augmented-textarea.html
@@ -7,6 +7,7 @@
(saveRequested)="saveForm()"
(editorKeyup)="editorKeyup.emit()"
(editorBlur)="editorBlur.emit()"
+ (editorFocus)="editorFocus.emit()"
></op-ckeditor>
</div>
diff --git a/frontend/src/app/shared/components/editor/components/ckeditor/op-ckeditor.component.ts b/frontend/src/app/shared/components/editor/components/ckeditor/op-ckeditor.component.ts
index e1716d82a2a..51843b2f83b 100644
--- a/frontend/src/app/shared/components/editor/components/ckeditor/op-ckeditor.component.ts
+++ b/frontend/src/app/shared/components/editor/components/ckeditor/op-ckeditor.component.ts
@@ -77,6 +77,9 @@ export class OpCkeditorComponent extends UntilDestroyedMixin implements OnInit,
// Output blur events
@Output() editorBlur = new EventEmitter<string>();
+ // Output focus events
+ @Output() editorFocus = new EventEmitter<string>();
+
// View container of the replacement used to initialize CKEditor5
@ViewChild('opCkeditorReplacementContainer', { static: true }) opCkeditorReplacementContainer:ElementRef;
@@ -300,6 +303,8 @@ export class OpCkeditorComponent extends UntilDestroyedMixin implements OnInit,
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (!editor.ui.focusTracker.isFocused) {
this.editorBlur.emit();
+ } else {
+ this.editorFocus.emit();
}
}, 0);
},
diff --git a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts
index 568d311ce93..51da1617736 100644
--- a/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/work-packages/activities-tab/index.controller.ts
@@ -48,7 +48,8 @@ export default class IndexController extends Controller {
private onSubmitBound:EventListener;
private adjustMarginBound:EventListener;
- private hideEditorBound:EventListener;
+ private onBlurEditorBound:EventListener;
+ private onFocusEditorBound:EventListener;
private saveInProgress:boolean;
private updateInProgress:boolean;
@@ -325,13 +326,15 @@ export default class IndexController extends Controller {
private addEventListenersToCkEditorInstance() {
this.onSubmitBound = () => { void this.onSubmit(); };
this.adjustMarginBound = () => { void this.adjustJournalContainerMargin(); };
- this.hideEditorBound = () => { void this.hideEditorIfEmpty(); };
+ this.onBlurEditorBound = () => { void this.onBlurEditor(); };
+ this.onFocusEditorBound = () => { void this.onFocusEditor(); };
const editorElement = this.getCkEditorElement();
if (editorElement) {
editorElement.addEventListener('saveRequested', this.onSubmitBound);
editorElement.addEventListener('editorKeyup', this.adjustMarginBound);
- editorElement.addEventListener('editorBlur', this.hideEditorBound);
+ editorElement.addEventListener('editorBlur', this.onBlurEditorBound);
+ editorElement.addEventListener('editorFocus', this.onFocusEditorBound);
}
}
@@ -340,7 +343,8 @@ export default class IndexController extends Controller {
if (editorElement) {
editorElement.removeEventListener('saveRequested', this.onSubmitBound);
editorElement.removeEventListener('editorKeyup', this.adjustMarginBound);
- editorElement.removeEventListener('editorBlur', this.hideEditorBound);
+ editorElement.removeEventListener('editorBlur', this.onBlurEditorBound);
+ editorElement.removeEventListener('editorFocus', this.onFocusEditorBound);
}
}
@@ -463,21 +467,39 @@ export default class IndexController extends Controller {
const ckEditorInstance = this.getCkEditorInstance();
if (ckEditorInstance && ckEditorInstance.getData({ trim: false }).length === 0) {
- this.clearEditor(); // remove potentially empty lines
- this.removeEventListenersFromCkEditorInstance();
- this.buttonRowTarget.classList.remove('d-none');
- this.formRowTarget.classList.add('d-none');
-
- if (this.journalsContainerTarget) {
- this.journalsContainerTarget.style.marginBottom = '';
- this.journalsContainerTarget.classList.add('work-packages-activities-tab-index-component--journals-container_with-initial-input-compensation');
- this.journalsContainerTarget.classList.remove('work-packages-activities-tab-index-component--journals-container_with-input-compensation');
- }
+ this.hideEditor();
+ }
+ }
+
+ hideEditor() {
+ this.clearEditor(); // remove potentially empty lines
+ this.removeEventListenersFromCkEditorInstance();
+ this.buttonRowTarget.classList.remove('d-none');
+ this.formRowTarget.classList.add('d-none');
+
+ if (this.journalsContainerTarget) {
+ this.journalsContainerTarget.style.marginBottom = '';
+ this.journalsContainerTarget.classList.add('work-packages-activities-tab-index-component--journals-container_with-initial-input-compensation');
+ this.journalsContainerTarget.classList.remove('work-packages-activities-tab-index-component--journals-container_with-input-compensation');
+ }
+
+ if (this.isMobile()) { this.scrollInputContainerIntoView(300); }
+ }
+
+ onBlurEditor() {
+ const ckEditorInstance = this.getCkEditorInstance();
- if (this.isMobile()) { this.scrollInputContainerIntoView(300); }
+ if (ckEditorInstance && ckEditorInstance.getData({ trim: false }).length === 0) {
+ this.hideEditor();
+ } else {
+ this.adjustJournalContainerMargin();
}
}
+ onFocusEditor() {
+ this.adjustJournalContainerMargin();
+ }
+
async onSubmit(event:Event | null = null) {
if (this.saveInProgress === true) return;