I have multiple Y.Button instances that are logically associated and need to be managed as a group.
For example, you may need a radio group, so when one button becomes selected, the others are unselected. Or a checkbox group, which allows you to select multiple buttons and at some point you need to obtain the values of all selected buttons.
Note: A push group is really just a checkbox group, but with Y.Button instances whose types are push
as opposed to toggle
.
addButton
- Adds a button to the groupgetButtons
- Returns an array of Y.Button instances assigned to the groupgetSelectedButtons
- Returns an array of Y.Button instances that are currently selectedgetSelectedValues
- Returns an array of the values of select buttons (sugar)
type
('checkbox' [default], or 'radio')
selectionChange
- Fires after theselected
state on a grouped button changes.
button-base
(requires:base
,classnamemanager
,node
)
// Instantiation
group = new Y.ButtonGroup({type: 'radio'});
buttonA = new Y.Button({srcNode: "#foo"});
buttonB = new Y.Button({srcNode: "#bar"});
// Interaction
group.addButton(ButtonA);
group.addButton(ButtonB);
buttonA.select();
selected = group.getSelectedButtons(); // Returns buttonA
buttonB.select();
selected = group.getSelectedButtons(); // Returns buttonB
- Add support for a
buttons
attribute in the Y.ButtonGroup config object to add all buttons on instantiation. Update: see comment #4 - Add support for a
srcNodes
selector attribute in the Y.ButtonGroup config object to create Y.Button instances for each node and add to the group. Update: see comment #4 - Add support for a
click
event (exact name TBD) which fires when any button in the group is clicked. This would be most applicable topush
button groups.
Can you clarify the use cases for ButtonGroup?
Is it only for groups of radio/checkbox-style buttons, or can it also be used to group non-toggleable buttons in a toolbar, panel, or other UI element? Will it do anything other than maintain a list of buttons and tell you which buttons are selected? Will it provide any sugar for creating buttons and managing their relationships to one another, or is button creation and event management left entirely up to
Y.Button
and the implementor?If ButtonGroup will only target the narrow use case of toggleable radio/checkbox buttons, then I feel like maybe there should be a lower-level "group" abstraction under it, and it should be called ToggleGroup or something, to leave room for other kinds of groups in the future.
It'd be helpful if you could provide some real-world usage examples in addition to the sample code that exercises the API. That'd make it easier to decide whether ButtonGroup should be an ArrayList, a WidgetParent, a View, or something else.