Skip to content

Commit

Permalink
Patch TinyMCE to work with modal Dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
TatuLund committed Feb 2, 2024
1 parent a1185f5 commit 2496f44
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
35 changes: 11 additions & 24 deletions src/main/resources/META-INF/resources/frontend/tinymceConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,8 @@ window.Vaadin.Flow.tinymceConnector = {
readonlyTimeout = setTimeout(() => {
this.editor.mode.set(enabled ? 'design' : 'readonly');
}, 20);
},
isInDialog: function() {
let inDialog = false;
let parent = c.parentElement;
while(parent != null) {
if(parent.tagName.toLowerCase().indexOf("vaadin-dialog") == 0) {
inDialog = true;
break;
}
parent = parent.parentElement;
}
return inDialog;
}

};
}

Expand Down Expand Up @@ -94,22 +83,20 @@ window.Vaadin.Flow.tinymceConnector = {
c.dispatchEvent(event);
});

if(c.$connector.isInDialog()) {
// This is inside a shadowroot (Dialog in Vaadin)
// and needs some hacks to make this nagigateable with keyboard
if(!c.tabIndex) {
// make the wrapping element also focusable
c.setAttribute("tabindex", 0);
}
// on focus to wrapping element, pass forward to editor
c.addEventListener("focus", e=> {
ed.focus();
});
}
};

ta.innerHTML = initialContent;

// Move aux element as child to fix Dialog issues, TinyMCE is slow
// to init, thus timeout needed
setTimeout(() => {
const aux = document.getElementsByClassName('tox-tinymce-aux')[0];
aux.parentElement.removeChild(aux);
// Fix to allow menu grow outside Dialog
aux.style.position = 'absolute';
c.appendChild(aux);
}, 500);

tinymce.init(baseconfig);

}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/vaadin/tinymce/EditorInDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class EditorInDialog extends Div {

public EditorInDialog() {
Dialog dialog = new Dialog();
dialog.setModal(false);
// dialog.setModal(false);

TinyMce editor = new TinyMce();
editor.configure("plugins", "link");
Expand Down

0 comments on commit 2496f44

Please sign in to comment.