Created
June 19, 2019 12:59
-
-
Save Peppe/c180cf946c65be3b6b3ab4fa7b11b1f3 to your computer and use it in GitHub Desktop.
RichTextEditor with an extra button
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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