-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Add doubleClick support to slot selection #575
Conversation
@jquense Can you take a look at this PR, please |
hey there, thanks for the PR and your patience. I think the best option is to mimic browser doubleClick behavior, which is that the first click event happens, and if the another click happens within a configurable timespan (defualt 250ms) the second click is emitted as a doubleClick. So for every double click you get one click and one doubleClick event. |
Actually, this is how I made this thing working, except two points:
|
sorry not sure if ytou are saying it already works like i suggested? Does the curretn code mute the first click? It shouldn't |
Yes, it mutes the first click. I described the reason in 1. of my previous comment |
Ok that's what I thought. Yes I'm saying we should change that behavior and instead emit the first click. THat's how doubleClick works natively on the web and we should copy that behavior |
Ok, you are right. I just checked it by myself |
@jquense Done. Now solution looks more simplified. When a user clicks an empty cell:
|
@jquense please take a look at this |
src/Selection.js
Outdated
|
||
if (this._lastClickData && now - this._lastClickData.timestamp < clickInterval) { | ||
// Double click event | ||
this._lastClickData = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be cleared here? It seems like if you click 3 times really fast you'll get 1 click and 2 dblClick events instead of: click, dblClick, click
@jquense fixed |
@jquense please take a look at this |
src/Selection.js
Outdated
|
||
if ( | ||
this._lastClickData && | ||
!this._lastClickData.isDblClick && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why add this isDblClick
instead of setting _lastClickData
to null
after a double click
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see much difference between checking for a flag and checking for null value. _lastClickData = null
seems obscure for me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hear you, though the opposite strikes me as more obscure, at the moment we are tracking some metadata that isn't used which isn't clear. I think i'd be clearer to clear out the last click data if there is no last click data :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Clear _lastClickData on double click event
thanks a lot! |
Finally! 🎊 Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this feature still functional?
i want to use doubleClick on onSelectSlot? how can i do that
If you 'showCode' on the onDoubleClickEvent prop documentation you'll get an example of how you can handle this. |
Actually for this behavior you need the onSelectSlot prop. Check for |
It looks like there's no access to the |
This PR is a part of #563 issue
Purpose:
Selection object already has support for slot selection with
action: 'click'
property passed toonSelectSlot
. We have to add support for double click interaction, withaction: 'doubleClick'
property passed.Problem:
Now Selection object emits
click
event on every click, so if you click twice, it will emit 2click
events with a small delay.Solution:
To emit
doubleClick
event insideSelection
object, we have to check, wether first click is just a single click (then we emitclick
event), or it's the first click of double click (then we should mute it):click
event yet. Create a timeout for 200ms (usual max delay between 2 clicks of double click). Remeber timestamp of the first click.doubleClick
event and clear created timeout, else emitclick
event.click
event inside created timeoutDisadvantage:
onSelectSlot
handler forclick
events can be called only after 200ms after user click. I don't think we can make this delay less, because normal delay between 2 clicks ofdoubleClick
event can be up to 170ms.