Anyone have an example of getting selected text from Div or Span (or any component) in Vaadin 14?
Use case:
I have some text in a component, in this case in a panel in a SplitLayout. In large text, users want to highlight (e.g. text select via mouse) and then click a button someone on the page that takes the selected text (in a component) and uses that selected text for something.
I would try a executeJS callback, something like this https://stackoverflow.com/a/5379408/3608089 from a UI.getCurrent().getPage().executeJS("[JS snippet that returns a String here] ").then(String.class, string -> { /* event handling with the return value */} )
I did get something working using a @ClientCallable method with some JS executed on attach that listened to a select event and then returned document.getSelection().toString() to the server’s @ClientCallable method.