How do you you unfocus a button?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

How do you you unfocus a button?

Justin Mclean
Hi,

Is there any focus/unfocus API for buttons?

Currently I have a small issue where I need to unfocus a button after the button text changes.

Here some code to illustrate the issue:

<?xml version="1.0" encoding="utf-8"?>
<js:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                xmlns:js="library://ns.apache.org/royale/basic">

    <fx:Script><![CDATA[
        public function changeText():void {
            button.text = "Clicked";
            // TODO unfocus the button
        }
        ]]></fx:Script>

    <js:valuesImpl>
        <js:SimpleCSSValuesImpl/>
    </js:valuesImpl>
   
    <js:initialView>
        <js:View percentWidth="100" percentHeight="100">
            <js:HContainer>
                <js:TextButton id="button" text="Click Me!" click="changeText()"  />
                <js:TextButton text="Ordinary Button" />
            </js:HContainer>
        </js:View>
    </js:initialView>

</js:Application>

About the only way of doing it that I can think of is:

public function changeText():void {
    button.text = "Clicked";
    COMPILE::JS {
        button.element.blur();
    }
    COMPILE::SWF {
        stage.focus = null;
    }
}


But in general it useful to be able to set and unset the focus in a set buttons.

Is there a better way to do this? And if not should there be an API in the framework to do this?

Thanks,
Justin

Reply | Threaded
Open this post in threaded view
|

Re: How do you you unfocus a button?

Gabe Harbs
We’ve run into the same thing.

There are two ways to accomplish the general goal in HTML. One is blur(). The second is to disable the focus rect.

Which one is better depends on accessibility concerns.

We never got around to encapsulating the functionality, so you need to do it manually. We used the button.element.blur() approach for buttons we did not want to have a focus rect.

Harbs

> On Nov 27, 2017, at 2:09 AM, Justin Mclean <[hidden email]> wrote:
>
> Hi,
>
> Is there any focus/unfocus API for buttons?
>
> Currently I have a small issue where I need to unfocus a button after the button text changes.
>
> Here some code to illustrate the issue:
>
> <?xml version="1.0" encoding="utf-8"?>
> <js:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
>                xmlns:js="library://ns.apache.org/royale/basic">
>
>    <fx:Script><![CDATA[
>        public function changeText():void {
>            button.text = "Clicked";
>            // TODO unfocus the button
>        }
>        ]]></fx:Script>
>
>    <js:valuesImpl>
>        <js:SimpleCSSValuesImpl/>
>    </js:valuesImpl>
>
>    <js:initialView>
>        <js:View percentWidth="100" percentHeight="100">
>            <js:HContainer>
>                <js:TextButton id="button" text="Click Me!" click="changeText()"  />
>                <js:TextButton text="Ordinary Button" />
>            </js:HContainer>
>        </js:View>
>    </js:initialView>
>
> </js:Application>
>
> About the only way of doing it that I can think of is:
>
> public function changeText():void {
>    button.text = "Clicked";
>    COMPILE::JS {
>        button.element.blur();
>    }
>    COMPILE::SWF {
>        stage.focus = null;
>    }
> }
>
>
> But in general it useful to be able to set and unset the focus in a set buttons.
>
> Is there a better way to do this? And if not should there be an API in the framework to do this?
>
> Thanks,
> Justin
>

Reply | Threaded
Open this post in threaded view
|

Re: How do you you unfocus a button?

Justin Mclean
Hi,

> We’ve run into the same thing.

Given two of us have run into this issue doesn’t it sound like a good inclusion for the framework?

Thanks,
Justin