diff --git a/src/main/java/org/vaadin/tinymce/TinyMce.java b/src/main/java/org/vaadin/tinymce/TinyMce.java index c9a2c64..b0aabb4 100644 --- a/src/main/java/org/vaadin/tinymce/TinyMce.java +++ b/src/main/java/org/vaadin/tinymce/TinyMce.java @@ -26,6 +26,7 @@ import com.vaadin.flow.component.dependency.JavaScript; import com.vaadin.flow.component.dependency.StyleSheet; import com.vaadin.flow.component.html.Div; +import com.vaadin.flow.dom.DebouncePhase; import com.vaadin.flow.dom.DomEventListener; import com.vaadin.flow.dom.DomListenerRegistration; import com.vaadin.flow.dom.Element; @@ -87,6 +88,7 @@ public TinyMce(boolean shadowRoot) { } else { getElement().appendChild(ta); } + domListenerRegistration = getElement().addEventListener("tchange", (DomEventListener) event -> { boolean value = event.getEventData() @@ -135,6 +137,11 @@ protected void onAttach(AttachEvent attachEvent) { id = UUID.randomUUID().toString(); ta.setAttribute("id", id); } + if(!getEventBus().hasListener(BlurEvent.class)) { + // adding fake blur listener so throttled value + // change events happen by latest at blur + addBlurListener(e -> {}); + } if (!attachEvent.isInitialAttach()) { // Value after initial attach should be set via TinyMCE JavaScript // API, otherwise value is not updated upon reattach diff --git a/src/test/java/org/vaadin/tinymce/DemoView.java b/src/test/java/org/vaadin/tinymce/DemoView.java index 6f53828..fa098a6 100755 --- a/src/test/java/org/vaadin/tinymce/DemoView.java +++ b/src/test/java/org/vaadin/tinymce/DemoView.java @@ -57,18 +57,18 @@ public DemoView() { Notification.show("Blur event!"); }); - Button blur = new Button("blur (NOT SUPPORTED)", e-> { - tinyMce.blur(); - }); - blur.addClickShortcut(Key.KEY_B, KeyModifier.CONTROL); - add(blur); - Button disable = new Button("Disabble", e-> { tinyMce.setEnabled(!tinyMce.isEnabled()); e.getSource().setText(tinyMce.isEnabled() ? "Disable" : "Enable"); }); add(disable); - + + Button blur = new Button("blur (NOT SUPPORTED really, but of course works from button)", e-> { + tinyMce.blur(); + }); + blur.addClickShortcut(Key.KEY_B, KeyModifier.CONTROL); + add(blur); + tinyMce.addValueChangeListener(e -> { Notification.show("ValueChange event!"); System.out.println(e.getValue());