Skip to content

Instantly share code, notes, and snippets.

@Peppe
Created June 19, 2019 12:59
Show Gist options
  • Save Peppe/c180cf946c65be3b6b3ab4fa7b11b1f3 to your computer and use it in GitHub Desktop.
Save Peppe/c180cf946c65be3b6b3ab4fa7b11b1f3 to your computer and use it in GitHub Desktop.
RichTextEditor with an extra button
package com.example.app.spring;
import com.vaadin.flow.component.ClientCallable;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.richtexteditor.RichTextEditor;
public class ModifiedRichTextEditor extends RichTextEditor {
public ModifiedRichTextEditor() {
String script =
"var span = document.createElement(\"span\");" +
"span.setAttribute(\"part\", \"toolbar-group\");" +
"var button = document.createElement(\"button\");" +
"button.textContent = \"hello\";" +
"button.setAttribute(\"part\", \"toolbar-button\");" +
"button.addEventListener('click', () => this.$server.clicked());" +
"span.appendChild(button);" +
"this.shadowRoot.querySelector('[part~=\"toolbar\"]').appendChild(span)";
getElement().executeJs(script);
}
@ClientCallable
private void clicked() {
Notification.show("button clicked!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment