-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
refactor(Canvas): BREAKING: remove button from mouse events, delegate to event.button property #9449
Conversation
Build Stats
|
b04acea
to
7b4927f
Compare
cleaner and safer Update eventData.test.ts.snap
7b4927f
to
2c2cea2
Compare
// e.button for a left click is `0` and so different than `1` is more | ||
// not a right click. PR 3888 introduced this code and was about left clicks. | ||
function notALeftClick(e: MouseEvent) { | ||
return e.button && e.button !== 1; |
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.
because e.button === 0
for a left click it would return false
:
notALeftClick(LEFT_CLICK_EV)
=> false
=> is a left click
so it was correct for left and right (e.button === 2
) but not for middle click (e.button === 1
) which would return false. Because it is rarly used we didn't catch it I think
It will account for events with no button
property as before, returning false
, meaning left click or "handle the event"
src/constants.ts
Outdated
export const LEFT_CLICK = 0; | ||
export const MIDDLE_CLICK = 1; | ||
export const RIGHT_CLICK = 2; |
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.
we can remove these values or not, they are used in a single place now
now they are the same values as MouseEvent#button
this[FIRE_CLICK_EVENT_MAP[(e as MouseEvent).button as 1 | 2]] && | ||
this._handleEvent(e, 'down'); | ||
|
||
this._resetTransformEventData(); |
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.
added _resetTransformEventData
button
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.
done
export const LEFT_CLICK = 1; | ||
export const MIDDLE_CLICK = 2; | ||
export const RIGHT_CLICK = 3; |
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.
this is the perfect case for a const enum once in a while but we don't need to do it now.
Motivation
#9434 made me look at the unused
button
propertyDescription
first merge #9434
Remove the
button
property ofTPointerEventInfo
because of the following:e
directlye.button
and cause confusionChanges
button
from eventnotALeftClick
in text clickGist
In Action