Skip to content

Commit

Permalink
Make sure value change even happens latest by blur
Browse files Browse the repository at this point in the history
  • Loading branch information
mstahv committed Feb 1, 2024
1 parent 44c8a8c commit 8790e80
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
7 changes: 7 additions & 0 deletions src/main/java/org/vaadin/tinymce/TinyMce.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -87,6 +88,7 @@ public TinyMce(boolean shadowRoot) {
} else {
getElement().appendChild(ta);
}

domListenerRegistration = getElement().addEventListener("tchange",
(DomEventListener) event -> {
boolean value = event.getEventData()
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions src/test/java/org/vaadin/tinymce/DemoView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 8790e80

Please sign in to comment.