Skip to content

Commit 8790e80

Browse files
committed
Make sure value change even happens latest by blur
1 parent 44c8a8c commit 8790e80

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/main/java/org/vaadin/tinymce/TinyMce.java

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.vaadin.flow.component.dependency.JavaScript;
2727
import com.vaadin.flow.component.dependency.StyleSheet;
2828
import com.vaadin.flow.component.html.Div;
29+
import com.vaadin.flow.dom.DebouncePhase;
2930
import com.vaadin.flow.dom.DomEventListener;
3031
import com.vaadin.flow.dom.DomListenerRegistration;
3132
import com.vaadin.flow.dom.Element;
@@ -87,6 +88,7 @@ public TinyMce(boolean shadowRoot) {
8788
} else {
8889
getElement().appendChild(ta);
8990
}
91+
9092
domListenerRegistration = getElement().addEventListener("tchange",
9193
(DomEventListener) event -> {
9294
boolean value = event.getEventData()
@@ -135,6 +137,11 @@ protected void onAttach(AttachEvent attachEvent) {
135137
id = UUID.randomUUID().toString();
136138
ta.setAttribute("id", id);
137139
}
140+
if(!getEventBus().hasListener(BlurEvent.class)) {
141+
// adding fake blur listener so throttled value
142+
// change events happen by latest at blur
143+
addBlurListener(e -> {});
144+
}
138145
if (!attachEvent.isInitialAttach()) {
139146
// Value after initial attach should be set via TinyMCE JavaScript
140147
// API, otherwise value is not updated upon reattach

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

+7-7
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@ public DemoView() {
5757
Notification.show("Blur event!");
5858
});
5959

60-
Button blur = new Button("blur (NOT SUPPORTED)", e-> {
61-
tinyMce.blur();
62-
});
63-
blur.addClickShortcut(Key.KEY_B, KeyModifier.CONTROL);
64-
add(blur);
65-
6660
Button disable = new Button("Disabble", e-> {
6761
tinyMce.setEnabled(!tinyMce.isEnabled());
6862
e.getSource().setText(tinyMce.isEnabled() ? "Disable" : "Enable");
6963
});
7064
add(disable);
71-
65+
66+
Button blur = new Button("blur (NOT SUPPORTED really, but of course works from button)", e-> {
67+
tinyMce.blur();
68+
});
69+
blur.addClickShortcut(Key.KEY_B, KeyModifier.CONTROL);
70+
add(blur);
71+
7272
tinyMce.addValueChangeListener(e -> {
7373
Notification.show("ValueChange event!");
7474
System.out.println(e.getValue());

0 commit comments

Comments
 (0)