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

Button - Added additional pointercancel eventlistener #1487

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JulianStremel
Copy link
Contributor

Description

I just wanted to make pointerevents more reliably end for hmi applications.
So i added the pointercancel event to the button component that activates if the "pointerup" function is enabled.
This will fire when closing the window while a button is pressed or other navigation changes happen that would otherwise not fire the "pointerup" event.

Related Issue(s)

No related issue

Checklist

  • No further modifications and updates needed

Copy link
Contributor

@Steve-Mcl Steve-Mcl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi. This looks like a good addition however according to MDN the pointercancel event can fire for many more reasons and I suspect we would be indiscriminately firing the "up" event.

examples of situations that will trigger a pointercancel event:

  • A hardware event occurs that cancels the pointer activities. This may include, for example, the user switching applications using an application switcher interface or the "home" button on a mobile device.
  • The device's screen orientation is changed while the pointer is active.
  • The browser decides that the user started pointer input accidentally. This can happen if, for example, the hardware supports palm rejection to prevent a hand resting on the display while using a stylus from accidentally triggering events.
  • The touch-action CSS property prevents the input from continuing.
  • When the user interacts with too many simultaneous pointers, the browser can fire this event for all existing pointers (even if the user is still touching the screen).

If we are to include this, i suggest we have a "memory"

Something like:

const activeDownPointers = new Set();

On pointer down

activeDownPointers.add(event.pointerId);

On pointer cancel

    if (activeDownPointers.has(event.pointerId)) {
       activeDownPointers.delete(event.pointerId);
       // call pointer up code
   }

Untested

@JulianStremel
Copy link
Contributor Author

If we are to include this, i suggest we have a "memory"

Sounds reasonable !
I will have a second look at it shortly.

@JulianStremel
Copy link
Contributor Author

@Steve-Mcl after some initial testing i couldnt figure cases out in which a "random" pointercancel would be emitet.
I think due to pointercancel beeing a pointerevent it always cancels the active pointer on the pointerdowned element because it obviously needs a pointer to cancel on ... or is my understanding fundamentally wrong ?

@Steve-Mcl
Copy link
Contributor

TBH, I dont know (not played with this event before - just regurgitating what I seen on MDN)

When I get time to pull and test, I will know more.

If however in the meantime you decide to play around some more and find it is not necessary, then thats fine too.

@joepavitt
Copy link
Collaborator

I will have a second look at it shortly.

Have you had the chance to add in the memory proposed by Steve? I think it would be a good catch just in case there are occasions we've not considered where this could mis-fire

@joepavitt joepavitt changed the title added additional pointercancel eventlistener Button - Added additional pointercancel eventlistener Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants