You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@royale.apache.org by Harbs <ha...@gmail.com> on 2019/01/07 14:07:18 UTC

Preventing click event

I have a component where I want to prevent the element click event from firing from the component under certain conditions.

I’m struggling on how to best accomplish that.

Harbs

Re: Preventing click event

Posted by Alex Harui <ah...@adobe.com.INVALID>.

On 1/7/19, 10:31 AM, "Harbs" <ha...@gmail.com> wrote:

    Details:
    
      <sp:ActionButton id="actionButton" click="actionClick()"
            icon="#spectrum-css-icon-ChevronRightMedium"
            iconClass="spectrum-Icon spectrum-Icon--sizeXS"
            dataProvider="{comboProvider}" change="actionChange()"/>
    
    Requiring client code to check for defaultPrevented is bad. actionClick() should not run.
    
    I’m trying to prevent that. Event listeners added in addedToParent are run after event listener declared in MXML. That’s true even if do this:
    element.addEventListener('click',elementClickedForMenu,true);

There is no capture phase at the target.  To implement a capture phase listener, you must listen to the parent of the target.  If that still doesn't work, then there is a bug.
    
    Adding the event listener in the constructor makes it fire first, but I was having trouble canceling the subsequent ones.
    
    Capture phase seems to not help at all. It would probably help if I could attach the event listener to the parent, but I can’t do that inside the component.
    
    While responding to this email I realized that I had tried everything except stopImmediatePropogation.
    
    That was the answer.
    https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Funhurdle%2Fspectrum-royale%2Fblob%2F21ae0a6d901a8eb4f461ce42def34e870554ec34%2FSpectrum%2Fsrc%2Fcom%2Funhurdle%2Fspectrum%2FActionButton.as%23L103&amp;data=02%7C01%7Caharui%40adobe.com%7Caf6025fd64a444fed60e08d674ce609e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636824827066165754&amp;sdata=FYcQz2jXgV4wXb8iMO9etQ9xVKDGbsbGnh2xMJRl4h4%3D&amp;reserved=0 <https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Funhurdle%2Fspectrum-royale%2Fblob%2F21ae0a6d901a8eb4f461ce42def34e870554ec34%2FSpectrum%2Fsrc%2Fcom%2Funhurdle%2Fspectrum%2FActionButton.as%23L103&amp;data=02%7C01%7Caharui%40adobe.com%7Caf6025fd64a444fed60e08d674ce609e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636824827066165754&amp;sdata=FYcQz2jXgV4wXb8iMO9etQ9xVKDGbsbGnh2xMJRl4h4%3D&amp;reserved=0>
    
    Thanks!
    
    > On Jan 7, 2019, at 8:11 PM, Alex Harui <ah...@adobe.com.INVALID> wrote:
    > 
    > What's wrong with Olaf's answer?
    > 
    > preventDefault() should only work on cancelable events, and in theory if I remember the spec corrrectly, click is not cancelable.  The other listeners must also check isDefaultPrevented().
    > 
    > stopPropagation and stopImmediatePropagation are intended to keep other listeners from even getting called.  We want stopProp and stopImmedateProp to work in Royale so if it doesn't, it needs to be fixed.
    > 
    > I think the full answer to your scenario is to use capture phase and call stopProp.
    > 
    > My 2 cents,
    > -Alex
    > 
    > On 1/7/19, 7:22 AM, "Harbs" <harbs.lists@gmail.com <ma...@gmail.com>> wrote:
    > 
    >    The only way I see of preventing the event from firing is to abort fireListenerOverride in HTMLElementWrapper.
    > 
    >    I can set defaultPrevented by attaching an event listener to the element in the constructor of my class.
    > 
    >    The question is whether we should abort the event dispatching if the event is defaultPrevented.
    > 
    >    In short, we can solve this problem by adding to the beginning of HTMLElementWrapper.fireListenerOverride:
    > 
    >    if(eventObject.defaultPrevented)return false;
    > 
    >    The question is whether this is something we should be doing.
    > 
    >    I have no other ideas of how to solve this problem.
    > 
    >    Harbs
    > 
    >> On Jan 7, 2019, at 4:37 PM, Olaf Krueger <ma...@olafkrueger.net> wrote:
    >> 
    >> What's about setting up a default handler which always handles the click
    >> event.
    >> Depending on your conditions, maybe calling stopPropagation() or
    >> stopImmediatePropagation() will prevent further propagation?
    >> 
    >> Maybe this helps,
    >> Olaf
    >> 
    >> 
    >> 
    >> --
    >> Sent from: https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapache-royale-development.20373.n8.nabble.com%2F&amp;data=02%7C01%7Caharui%40adobe.com%7Caf6025fd64a444fed60e08d674ce609e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636824827066165754&amp;sdata=AXtaj%2FZnolmNjqWaFJ809giSfc1H7X7GeU9tWmaWdRY%3D&amp;reserved=0 <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapache-royale-development.20373.n8.nabble.com%2F&amp;data=02%7C01%7Caharui%40adobe.com%7Caf6025fd64a444fed60e08d674ce609e%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636824827066165754&amp;sdata=AXtaj%2FZnolmNjqWaFJ809giSfc1H7X7GeU9tWmaWdRY%3D&amp;reserved=0>
    


Re: Preventing click event

Posted by Harbs <ha...@gmail.com>.
Details:

  <sp:ActionButton id="actionButton" click="actionClick()"
        icon="#spectrum-css-icon-ChevronRightMedium"
        iconClass="spectrum-Icon spectrum-Icon--sizeXS"
        dataProvider="{comboProvider}" change="actionChange()"/>

Requiring client code to check for defaultPrevented is bad. actionClick() should not run.

I’m trying to prevent that. Event listeners added in addedToParent are run after event listener declared in MXML. That’s true even if do this:
element.addEventListener('click',elementClickedForMenu,true);

Adding the event listener in the constructor makes it fire first, but I was having trouble canceling the subsequent ones.

Capture phase seems to not help at all. It would probably help if I could attach the event listener to the parent, but I can’t do that inside the component.

While responding to this email I realized that I had tried everything except stopImmediatePropogation.

That was the answer.
https://github.com/unhurdle/spectrum-royale/blob/21ae0a6d901a8eb4f461ce42def34e870554ec34/Spectrum/src/com/unhurdle/spectrum/ActionButton.as#L103 <https://github.com/unhurdle/spectrum-royale/blob/21ae0a6d901a8eb4f461ce42def34e870554ec34/Spectrum/src/com/unhurdle/spectrum/ActionButton.as#L103>

Thanks!

> On Jan 7, 2019, at 8:11 PM, Alex Harui <ah...@adobe.com.INVALID> wrote:
> 
> What's wrong with Olaf's answer?
> 
> preventDefault() should only work on cancelable events, and in theory if I remember the spec corrrectly, click is not cancelable.  The other listeners must also check isDefaultPrevented().
> 
> stopPropagation and stopImmediatePropagation are intended to keep other listeners from even getting called.  We want stopProp and stopImmedateProp to work in Royale so if it doesn't, it needs to be fixed.
> 
> I think the full answer to your scenario is to use capture phase and call stopProp.
> 
> My 2 cents,
> -Alex
> 
> On 1/7/19, 7:22 AM, "Harbs" <harbs.lists@gmail.com <ma...@gmail.com>> wrote:
> 
>    The only way I see of preventing the event from firing is to abort fireListenerOverride in HTMLElementWrapper.
> 
>    I can set defaultPrevented by attaching an event listener to the element in the constructor of my class.
> 
>    The question is whether we should abort the event dispatching if the event is defaultPrevented.
> 
>    In short, we can solve this problem by adding to the beginning of HTMLElementWrapper.fireListenerOverride:
> 
>    if(eventObject.defaultPrevented)return false;
> 
>    The question is whether this is something we should be doing.
> 
>    I have no other ideas of how to solve this problem.
> 
>    Harbs
> 
>> On Jan 7, 2019, at 4:37 PM, Olaf Krueger <ma...@olafkrueger.net> wrote:
>> 
>> What's about setting up a default handler which always handles the click
>> event.
>> Depending on your conditions, maybe calling stopPropagation() or
>> stopImmediatePropagation() will prevent further propagation?
>> 
>> Maybe this helps,
>> Olaf
>> 
>> 
>> 
>> --
>> Sent from: https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapache-royale-development.20373.n8.nabble.com%2F&amp;data=02%7C01%7Caharui%40adobe.com%7C6701c5cf1ec84c93592008d674b3ff28%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636824713784402779&amp;sdata=LgEP5%2BK2c6iu2JaOcwqwB88NfdRxJrhDf52iICsOJcQ%3D&amp;reserved=0 <https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapache-royale-development.20373.n8.nabble.com%2F&amp;data=02%7C01%7Caharui%40adobe.com%7C6701c5cf1ec84c93592008d674b3ff28%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636824713784402779&amp;sdata=LgEP5%2BK2c6iu2JaOcwqwB88NfdRxJrhDf52iICsOJcQ%3D&amp;reserved=0>

Re: Preventing click event

Posted by Alex Harui <ah...@adobe.com.INVALID>.
What's wrong with Olaf's answer?

preventDefault() should only work on cancelable events, and in theory if I remember the spec corrrectly, click is not cancelable.  The other listeners must also check isDefaultPrevented().

stopPropagation and stopImmediatePropagation are intended to keep other listeners from even getting called.  We want stopProp and stopImmedateProp to work in Royale so if it doesn't, it needs to be fixed.

I think the full answer to your scenario is to use capture phase and call stopProp.

My 2 cents,
-Alex

On 1/7/19, 7:22 AM, "Harbs" <ha...@gmail.com> wrote:

    The only way I see of preventing the event from firing is to abort fireListenerOverride in HTMLElementWrapper.
    
    I can set defaultPrevented by attaching an event listener to the element in the constructor of my class.
    
    The question is whether we should abort the event dispatching if the event is defaultPrevented.
    
    In short, we can solve this problem by adding to the beginning of HTMLElementWrapper.fireListenerOverride:
    
    if(eventObject.defaultPrevented)return false;
    
    The question is whether this is something we should be doing.
    
    I have no other ideas of how to solve this problem.
    
    Harbs
    
    > On Jan 7, 2019, at 4:37 PM, Olaf Krueger <ma...@olafkrueger.net> wrote:
    > 
    > What's about setting up a default handler which always handles the click
    > event.
    > Depending on your conditions, maybe calling stopPropagation() or
    > stopImmediatePropagation() will prevent further propagation?
    > 
    > Maybe this helps,
    > Olaf
    > 
    > 
    > 
    > --
    > Sent from: https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fapache-royale-development.20373.n8.nabble.com%2F&amp;data=02%7C01%7Caharui%40adobe.com%7C6701c5cf1ec84c93592008d674b3ff28%7Cfa7b1b5a7b34438794aed2c178decee1%7C0%7C0%7C636824713784402779&amp;sdata=LgEP5%2BK2c6iu2JaOcwqwB88NfdRxJrhDf52iICsOJcQ%3D&amp;reserved=0
    
    


Re: Preventing click event

Posted by Harbs <ha...@gmail.com>.
The only way I see of preventing the event from firing is to abort fireListenerOverride in HTMLElementWrapper.

I can set defaultPrevented by attaching an event listener to the element in the constructor of my class.

The question is whether we should abort the event dispatching if the event is defaultPrevented.

In short, we can solve this problem by adding to the beginning of HTMLElementWrapper.fireListenerOverride:

if(eventObject.defaultPrevented)return false;

The question is whether this is something we should be doing.

I have no other ideas of how to solve this problem.

Harbs

> On Jan 7, 2019, at 4:37 PM, Olaf Krueger <ma...@olafkrueger.net> wrote:
> 
> What's about setting up a default handler which always handles the click
> event.
> Depending on your conditions, maybe calling stopPropagation() or
> stopImmediatePropagation() will prevent further propagation?
> 
> Maybe this helps,
> Olaf
> 
> 
> 
> --
> Sent from: http://apache-royale-development.20373.n8.nabble.com/


Re: Preventing click event

Posted by Olaf Krueger <ma...@olafkrueger.net>.
What's about setting up a default handler which always handles the click
event.
Depending on your conditions, maybe calling stopPropagation() or
stopImmediatePropagation() will prevent further propagation?

Maybe this helps,
Olaf



--
Sent from: http://apache-royale-development.20373.n8.nabble.com/

Re: Preventing click event

Posted by Harbs <ha...@gmail.com>.
I mean that click events from the underlying HTML element automatically fire from the Royale UIBase.

I have a button which pops up a menu when held for a second. If you release the mouse over the button after the menu pops up, the browser fires a click event. I only want a click event if there’s no menu visible.

I tried preventDefault, and it didn’t seem to help.
I even tried adding the event listener to the capture phase but that didn’t work either.

Thanks,
Harbs

> On Jan 7, 2019, at 4:17 PM, Piotr Zarzycki <pi...@gmail.com> wrote:
> 
> Hi Harbs,
> 
> I did something like that lately, but it is not what I wanted to figure out
> how to achieve in Royale.
> 
> element.addEventListener('click', function(event:Event):Boolean {
>                event.preventDefault();
>                return false;
>            });
> 
> By prevent you mean do not propagate actually ?
> 
> Thanks, Piotr
> 
> pon., 7 sty 2019 o 15:07 Harbs <ha...@gmail.com> napisał(a):
> 
>> I have a component where I want to prevent the element click event from
>> firing from the component under certain conditions.
>> 
>> I’m struggling on how to best accomplish that.
>> 
>> Harbs
> 
> 
> 
> -- 
> 
> Piotr Zarzycki
> 
> Patreon: *https://www.patreon.com/piotrzarzycki
> <https://www.patreon.com/piotrzarzycki>*


Re: Preventing click event

Posted by Piotr Zarzycki <pi...@gmail.com>.
Hi Harbs,

I did something like that lately, but it is not what I wanted to figure out
how to achieve in Royale.

element.addEventListener('click', function(event:Event):Boolean {
                event.preventDefault();
                return false;
            });

By prevent you mean do not propagate actually ?

Thanks, Piotr

pon., 7 sty 2019 o 15:07 Harbs <ha...@gmail.com> napisał(a):

> I have a component where I want to prevent the element click event from
> firing from the component under certain conditions.
>
> I’m struggling on how to best accomplish that.
>
> Harbs



-- 

Piotr Zarzycki

Patreon: *https://www.patreon.com/piotrzarzycki
<https://www.patreon.com/piotrzarzycki>*