ToggleButtonBar does not behave as advertised

The ToggleButtonBar component, included in the Flex 2.0 framework extends ButtonBar and adds the toggleOnClick property. When set to true, this property is supposed to allow the user to deselect the currently selected button, which then sets the selectedIndex property to -1. This is what the documentation claims anyway. What actually happens is a little different. Setting toggleOnClick=true does indeed allow the user to deselect whichever button is selected, but it doesn't change the selectedIndex. This results in a very odd experience in which you can not reselect the button you just deselected, because the ButtonBar already thinks it's selected.

I stepped through the source of the ToggleButtonBar (and its ancestors) just enough to realize that evaluating selectedIndex == -1 is heavily used to determine if the control is initializing. Because of this, setting selectedIndex=-1 any time after initialization is handled unintuitively, and yields undesirable results. Immediately after deselecting a button, the selectedIndex is indeed -1, however, it's later forced back to the index of the button that was just clicked. Even if you figured out a way to make the selectedIndex=-1 stick, forget trying to instantiate the component with none of the buttons selected; When initializing, a value of -1 is interpreted to mean that selectedIndex was never explicitly defined, and it's then forced to 0 to select the first button.

I think I am going to ditch the ToggleButtonBar for now and use a couple of buttons with toggleEnabled and then write a simple manager to make sure that only one button is selected. I'm might see if the RadioButtonGroup class provides this functionality, but I'm worried that it will enforce that at least one button is selected, and what I really need is something that allows none of the buttons are selected.

This entry was posted in Flex. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

One Comment

  1. Posted July 3, 2007 at 10:29 am | Permalink

    Hi, Andy,

    Wanted to tell you that I just checked in a fix for this problem. The next public build of Flex 3 should have the fix. Please check it to make sure it does what you think it should.

One Trackback

  1. By SimianLogic » Blog Archive » ToggleButtonBar fix on November 7, 2007 at 5:40 pm

    [...] can’t click on it again until you select something else and then come back to it. I found a blog post of someone else complaining about this, and–even more valuabe–there was a comment from [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">