Flex Tab Key Navigation for custom Spark PopUp
This took me a while to figure out.
In a project I created a custom PopUp, nothing fancy, just a couple of text inputs. When I tried to enable Tab key navigation I set the required properties but Flex would simply ignore tab key navigation to the input fields in the pop up.
The Documentation about the IFocusManager states that a pop up will get its own FocusManager and its own tab loop.
After some tracing I found that my pop up and its child weren’t included in the FocusManager as focus objects. In fact, there was no FocusManager for my pop up at all.
The reason for this is that when the PopUpMangerImpl is about to create and configure the pop up, it checks if the pop up is a IFocusManagerContainer so that focus can be added.
Unfortunately my popup was a Group which does not implement the IFocusManagerContainer interface. Naturally no FocusManager would be created.
If you want to use a Spark Group as your pop up, the solution is to create a new class that extends from Group and implements the IFocusManagerContainer. Then use this class as the container for the pop up.
. . . public class AHPopUpGroup extends Group implements IFocusManagerContainer { public function AHPopUpGroup() { super(); } /** * @private * Storage for the defaultButton property. */ private var _defaultButton:IFlexDisplayObject; [Inspectable(category="General")] /** * The Button control designated as the default button for the container. * When controls in the container have focus, pressing the * Enter key is the same as clicking this Button control. * * @default null */ public function get defaultButton():IFlexDisplayObject { return _defaultButton; } /** * @private */ public function set defaultButton(value:IFlexDisplayObject):void { _defaultButton = value; ContainerGlobals.focusedContainer = null; } } . . .
And the mxml for the pop up becomes something like this
.
.
.
<!---
Uses a Group that implements the IFocusManagerContainer
-->
.
.
.
TextInput, Buttons etc now get focus on tab key navigation
.
.
.
.
.
.Similar Posts
Customize the Spark TextInput Component in Flex 4 (Gumbo). Adding focus and Transitions.
Custom PopUp Rating Component in Spark Flex 4 (Gumbo)
Use SpriteVisualElement to implement a simple component in Flex 4
Random notes on DataGroup and Spark Containers in Flex 4 (Gumbo)
Spark Icon Button with Gradient effects and Filter animation, colorized by styles. Flex 4 (Gumbo)

October 7th, 2010 at 11:45 am
Thanks for the tip!
I already know it will save me some headache….
December 1st, 2010 at 2:23 am
All you have to do is make your popup a SkinnableContainer instead of Group, since SkinnableContainer implements IFocusManagerContainer.
December 2nd, 2010 at 2:11 pm
Thanks for the tip, Adam. That’s right but I’d rather do not have the additional overhead of the SkinnableContainer when I don’t need it.
March 5th, 2011 at 5:21 pm
I had been trying to figure this out for a whole darn day now, reposting this in my blog!
Also, what about states implementation ?
May 24th, 2011 at 4:48 pm
Thanks mate. Really saved me some time.