Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onSelectionChange event #5785

Closed
devongovett opened this issue Jan 5, 2016 · 15 comments
Closed

onSelectionChange event #5785

devongovett opened this issue Jan 5, 2016 · 15 comments
Assignees
Labels

Comments

@devongovett
Copy link
Contributor

The onSelect event does not fire while the user is dragging the mouse, only after they release. It would be nice to have an event that fired immediately whenever the selection changed, including while dragging the mouse. This is useful, for example, when syncing selections between multiple collaborators, ala google docs.

The native selectionchange event is supported cross browser, way back in IE, Chrome, and Safari, and recently in Firefox 43. Is this something React could polyfill and expose to components?

@YurkaninRyan
Copy link

Do any of the more seasoned contributors have any opinions on what this should look like? Should it just become a feature of onSelect or does it merit it's own event hook?

It seems like the current React onSelect is a bit of a mixture of the two already.

@gaearon
Copy link
Collaborator

gaearon commented Oct 3, 2017

Seems reasonable to me to mirror the browser API.

@flarnie
Copy link
Contributor

flarnie commented Oct 11, 2017

I'd like to look into this because it could affect Draft.js. Will post more when I get time.

@raphasilvac
Copy link

raphasilvac commented Nov 16, 2017

Hello @flarnie,
I think it would be nice for Draft.js

I think there is a problem on Draft.js,
the selectionState is only updated after "mouseup",
if you keep mouse pressed and paste or write some word you will see that the word or some part of it goes to a wrong place ("previous selectionState").

This is reproducible on Draft.js home/demo page and on facebook status field. (macOS: chrome, FF and Safari)

I think it is not a good solution, but for a test I added the following code on Draft.js componentDidMount:
document.addEventListener("selectionchange", this._onSelect);

In my tests it works, but maybe you can know some unexpected effect about it.

Sorry about my english!

Thank you.

@ianstormtaylor
Copy link

ianstormtaylor commented Dec 2, 2017

@flarnie any word on this? We'd love this for Slate.js as well!

FWIW, I'd propose that it just be implemented as:

onSelectionChange={...}
onSelectionStart={...}

Different than the existing onSelect, to not have to worry about backwards compatibility, since onSelect fires much less frequently. (And is kind of like a pseudo-onSelectionEnd.) That way people can opt into using onSelectionChange/Start but do it in a way that takes throttling into account.

I don't know much about React events, but if they're just pass-throughs with no complex compatibility logic, they might be fairly easy to implement?

@noahlemen
Copy link
Member

noahlemen commented Mar 28, 2018

came across this PR and noticed it hadn't been linked here yet -- for documentation's sake, it looks like a attempt at this was made in #10746. in a comment, @gaearon mentioned that it may be best to expose the event, but not add a polyfill.

@stale
Copy link

stale bot commented Jan 10, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution.

@stale stale bot added the Resolution: Stale Automatically closed due to inactivity label Jan 10, 2020
@ianstormtaylor
Copy link

Not stale!

This is still a pain point that's lacking in React's API. I'm not sure what the solution is since it seems like no new events are being added to React despite them being standardized?

@stale stale bot removed the Resolution: Stale Automatically closed due to inactivity label Jan 10, 2020
@TrySound
Copy link
Contributor

This will probably be a solution
#17651

@stale
Copy link

stale bot commented Apr 9, 2020

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

@stale stale bot added the Resolution: Stale Automatically closed due to inactivity label Apr 9, 2020
@stale
Copy link

stale bot commented Apr 17, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!

@stale stale bot closed this as completed Apr 17, 2020
@ianstormtaylor
Copy link

ianstormtaylor commented Apr 1, 2021

Still not stale...

@Christian-Toney
Copy link

bump

@Fortidude
Copy link

any ideas someone? : )

@b5414
Copy link

b5414 commented Dec 1, 2022

🙂

<div onSelect={...}></div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests