Skip to content

Commit ea1a2d1

Browse files
committed
Fix issues with multiple TinyMCE instances in dialogs
1 parent f1557e8 commit ea1a2d1

File tree

3 files changed

+42
-9
lines changed

3 files changed

+42
-9
lines changed

src/main/resources/META-INF/resources/frontend/tinymceConnector.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,19 @@ window.Vaadin.Flow.tinymceConnector = {
105105
ed.focus();
106106
});
107107
// Move aux element as child from body to element to fix menus in modal Dialog
108-
const aux = document.getElementsByClassName('tox-tinymce-aux')[0];
109-
aux.parentElement.removeChild(aux);
110-
// Fix to allow menu grow outside Dialog
111-
aux.style.position = 'absolute';
112-
c.appendChild(aux);
113-
}
108+
Array.from(document.getElementsByClassName('tox-tinymce-aux')).forEach(aux => {
109+
if (!aux.dontmove) {
110+
aux.parentElement.removeChild(aux);
111+
// Fix to allow menu grow outside Dialog
112+
aux.style.position = 'absolute';
113+
c.editor = ed;
114+
c.appendChild(aux);
115+
}
116+
});
117+
} else {
118+
const aux = document.getElementsByClassName('tox-tinymce-aux')[0];
119+
aux.dontmove = true;
120+
}
114121
});
115122

116123
ed.on('change', function(e) {

src/main/resources/META-INF/resources/frontend/tinymceLumo.css

+4
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ button.tox-tbtn.tox-tbtn--select.tox-tbtn--bespoke {
104104
background-color: var(--lumo-primary-color-10pct);
105105
}
106106

107+
.tox .tox-menu.tox-collection.tox-collection--list {
108+
min-width: var(--tiny-mce-menu-width, 300px);
109+
}
110+
107111
.tox-menu-nav__js.tox-collection__item.tox-collection__item {
108112
color: var(--lumo-body-text-color);
109113
}

src/test/java/org/vaadin/tinymce/EditorInDialog.java

+25-3
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,55 @@
44
import com.vaadin.flow.component.dialog.Dialog;
55
import com.vaadin.flow.component.html.Div;
66
import com.vaadin.flow.component.html.Paragraph;
7+
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
78
import com.vaadin.flow.router.Route;
89

910
@Route
1011
public class EditorInDialog extends Div {
1112

1213
public EditorInDialog() {
1314
Dialog dialog = new Dialog();
14-
// dialog.setModal(false);
15+
Dialog dialog2 = new Dialog();
1516

1617
TinyMce editor = new TinyMce();
1718
editor.configure("plugins", "link");
1819

20+
TinyMce editor2 = new TinyMce();
21+
editor2.configure("plugins", "link");
22+
23+
TinyMce editor3 = new TinyMce();
24+
editor3.configure("plugins", "link");
25+
26+
TinyMce editor4 = new TinyMce();
27+
editor4.configure("plugins", "link");
28+
1929
editor.addValueChangeListener(e -> {
2030
reportValue(e.getValue());
2131
});
2232

23-
dialog.add(new Div(editor, new Button("show value", e -> {
33+
dialog.add(new Div(new HorizontalLayout(editor, editor2), new Button("show value", e -> {
2434
reportValue(editor.getValue());
2535
}), new Button("close", e -> {
2636
dialog.close();
2737
})));
38+
39+
dialog2.add(new Div(new HorizontalLayout(editor4), new Button("show value", e -> {
40+
reportValue(editor.getValue());
41+
}), new Button("close", e -> {
42+
dialog.close();
43+
})));
44+
2845
Button button = new Button("Open the editor dialog");
2946
button.addClickListener(event -> {
3047
dialog.open();
3148
});
3249

33-
add(button);
50+
Button button2 = new Button("Open the editor dialog");
51+
button2.addClickListener(event -> {
52+
dialog2.open();
53+
});
54+
55+
add(button, button2, editor3);
3456

3557
}
3658

0 commit comments

Comments
 (0)