yew
yew copied to clipboard
Behaviour of `onselectionchange` attribute on an element
Problem
I mean to do something when text is selected. I built an example app for this issue, where when text is selected, the selection is displayed under the text.
Steps To Reproduce
I first attempted to use a callback on onselectionchange
to trigger a new render, see example. This does not work. Note that using a onmousemove
attribute, I get the expected high level behaviour when selecting with the mouse, see example.
Registering an event listener on the document works, see example.
Expected behavior
onselectionchange
attribute to be enough to register a callback on the selectionchange event.
I note that selectionchange
is a document event (mdn) while for example mousemove
is an element event (mdn). If onselectionchange
is not meant to be put on a div
I would maybe expect that compilation fails?
Environment:
- Yew version: 0.17.4
- Rust version: 1.51.0
- Build tool, if relevant: wasm-pack
- OS: Windows 10
- Browser and version, if relevant: Firefox 87
Hi @nbrr, I've been looking at this issue, btw thank you for the example repo made it easy to do :) I'm not experiencing any problems or differences between the two version now. mdn does note in general that this is experimental so maybe this was a browser bug that has been fixed between your issue and now? If you could confirm the same and close the issue if you agree and if I've missed something just let me know :)
If onselectionchange is not meant to be put on a div I would maybe expect that compilation fails?
No, we don't guarantee checks for all w3c specs. It would be too big of an overhead for an open source library. Expected behavior for yew user is to check mdn or other documentation, like you did here.
I also have to note, yes i can still reproduce this on [email protected], but the event only will work when mounted on document element. That is expected JavaScript behavior.