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

emit a custom event when the dialog is closed

Klaus Zandersa8fcc97fe31f
diff --git a/frontend/src/turbo/turbo-event-listeners.ts b/frontend/src/turbo/turbo-event-listeners.ts
index b102187836c..4d4f13348c5 100644
--- a/frontend/src/turbo/turbo-event-listeners.ts
+++ b/frontend/src/turbo/turbo-event-listeners.ts
@@ -6,14 +6,20 @@ export function addTurboEventListeners() {
//
// It is necessary to close the primer dialog using the `close()` method, otherwise
// it will leave an overflow:hidden attribute on the body, which prevents scrolling on the page.
+ //
+ // Also, we will dispatch a custom `dialog:close` event when the dialog is closed.
document.addEventListener('turbo:submit-end', (event:CustomEvent) => {
- const { detail: { success }, target } = event as { detail:{ success:boolean }, target:EventTarget };
+ const { detail: { success }, target } = event as { detail:{ success:boolean }; target:EventTarget };
if (success && target instanceof HTMLFormElement) {
const dialog = target.closest('dialog') as HTMLDialogElement;
- if (dialog && dialog.dataset.keepOpenOnSubmit !== 'true') {
- dialog.close();
+ if (dialog) {
+ document.dispatchEvent(new CustomEvent('dialog:close', { detail: { dialog } }));
+
+ if (dialog.dataset.keepOpenOnSubmit !== 'true') {
+ dialog.close();
+ }
}
}
});