ButtonGroup
A specialized container that holds buttons, displaying them in a horizontal group with borders adjusted to make them stick together. Appearance in the built-in themes:
//<code-header>
fiddle.title = 'Button group';
//</code-header>
const container = new Container({
appendTo : targetElement,
columns : 2
});
for (const rendition of ['text', 'outlined', 'tonal', 'filled', 'elevated', 'padded', 'padded-filled']) {
container.add([
{
type : 'label',
text : StringHelper.capitalize(rendition),
column : 1
},
{
type : 'buttongroup',
toggleGroup : true,
column : 2,
rendition,
items : [
{
text : 'Day',
pressed : true
},
{ text : 'Week' },
{ text : 'Month' }
]
}
]);
}Trying to add other widgets than buttons will throw an exception.
new ButtonGroup({
items : [
{ icon : 'fa-kiwi-bird' },
{ icon : 'fa-kiwi-otter' },
{ icon : 'fa-kiwi-rabbit' },
...
]
});
Configs
95
Configs
95Common
CSS
Custom CSS class to add to element.
new ButtonGroup({
cls : 'custom-css-class,
items : [
{ icon : 'fa fa-unicorn', cls : 'button-cls-class' },
...
]
});
Other
Default color to apply to all contained buttons, see Button#color. Individual buttons can override the default.
An array of Buttons or typed Button config objects.
Predefined style to use for the buttons. Possible values are:
'elevated'- Raised buttons with box-shadow'filled'- Filled with the primary color'tonal'- Filled with a faded shade of the primary color'outlined'- Outlined with borders and pale or transparent fill'text'- Transparent text-only button'padded'- Adds a background to the ButtonGroup and padding around the buttons + neutral background for toggled buttons'padded-filled'- Same as 'padded', but uses a primary color shade for the background of toggled buttons
The supplied value will be part of the button group's and each button's class list, as b-button-{rendition}.
If not value is supplied, it will search upwards for one, falling back to using the first button's rendition.
A two-element array containing the minimum and maximum number of toggleable buttons. If a single number is
specified, it is converted to an array using that given value as the maximum and 1 is used as the minimum.
If true is specified, it is equivalent to [0, Infinity], allowing any buttons to be toggled independently
or all buttons to be untoggled.
A value of null (the default) is similar to toggleable : 1 unless toggleGroup is set,
or individual buttons are configured with their own toggleable or
toggleGroup values. If this config is used, toggleable and toggleGroup
should not be assigned to individual buttons.
Set to true to turn the ButtonGroup into a toggle group, assigning a generated value to each contained
buttons toggleGroup config. Individual buttons can
override the default.
If you use gaps between your buttons, set this to true (controls whether to use border-radius for the
button elements)
DOM
Float & align
Layout
misc
Misc
Scrolling
Properties
83
Properties
83Class hierarchy
Other
Predefined style to use for the buttons. Possible values are:
'elevated'- Raised buttons with box-shadow'filled'- Filled with the primary color'tonal'- Filled with a faded shade of the primary color'outlined'- Outlined with borders and pale or transparent fill'text'- Transparent text-only button'padded'- Adds a background to the ButtonGroup and padding around the buttons + neutral background for toggled buttons'padded-filled'- Same as 'padded', but uses a primary color shade for the background of toggled buttons
The supplied value will be part of the button group's and each button's class list, as b-button-{rendition}.
If not value is supplied, it will search upwards for one, falling back to using the first button's rendition.
A two-element array containing the minimum and maximum number of toggleable buttons. If a single number is
specified, it is converted to an array using that given value as the maximum and 1 is used as the minimum.
If true is specified, it is equivalent to [0, Infinity], allowing any buttons to be toggled independently
or all buttons to be untoggled.
A value of null (the default) is similar to toggleable : 1 unless toggleGroup is set,
or individual buttons are configured with their own toggleable or
toggleGroup values. If this config is used, toggleable and toggleGroup
should not be assigned to individual buttons.
CSS
DOM
Layout
Misc
Widget hierarchy
Functions
67
Functions
67Configuration
Events
Misc
Other
Widget hierarchy
Events
19
Events
19Fires when the default action is performed on a button in the group (the button is clicked)
// Adding a listener using the "on" method
buttonGroup.on('action', ({ source, event }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Button | Clicked button |
event | Event | DOM event |
Fires when a button in the group is clicked
// Adding a listener using the "on" method
buttonGroup.on('click', ({ source, event }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Button | Clicked button |
event | Event | DOM event |
Fires when a button in the group is toggled (the pressed state is changed). If you need to process the pressed button only, consider using click event or action event.
// Adding a listener using the "on" method
buttonGroup.on('toggle', ({ source, pressed, event }) => {
});| Parameter | Type | Description |
|---|---|---|
source | Button | Toggled button |
pressed | Boolean | New pressed state |
event | Event | DOM event |
Event handlers
19
Event handlers
19Called when the default action is performed on a button in the group (the button is clicked)
new ButtonGroup({
onAction({ source, event }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Button | Clicked button |
event | Event | DOM event |
Called when a button in the group is clicked
new ButtonGroup({
onClick({ source, event }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Button | Clicked button |
event | Event | DOM event |
Called when a button in the group is toggled (the pressed state is changed). If you need to process the pressed button only, consider using click event or action event.
new ButtonGroup({
onToggle({ source, pressed, event }) {
}
});| Parameter | Type | Description |
|---|---|---|
source | Button | Toggled button |
pressed | Boolean | New pressed state |
event | Event | DOM event |
Typedefs
6
Typedefs
6CSS variables
47
CSS variables
47| Name | Description |
|---|---|
--b-button-group-border-width | ButtonGroup border width, overridden by `--b-button-outlined-border-width` when using outlined rendition |
--b-button-group-border-radius | ButtonGroup border-radius, should normally match Button border-radius (cannot hide overflow, since badges need to stay visible) |
--b-button-group-box-shadow | ButtonGroup box-shadow, overridden by `--b-button-elevated-box-shadow` when using elevated rendition |
--b-button-group-border-color | ButtonGroup border color, overridden by `--b-button-outlined-border-color` when using outlined rendition |
--b-button-group-padded-padding | Padding when using "padded" rendition |
--b-button-group-padded-background | Background when using "padded" rendition |
--b-button-group-padded-active-background | Background for active (held down) button when using "padded" rendition |
--b-button-group-padded-pressed-background | Background for pressed button when using "padded" rendition |
--b-button-group-padded-pressed-hover-background | Background for hovered pressed button when using "padded" rendition (when not in a toggle group) |
--b-button-group-padded-pressed-box-shadow | Box-shadow for pressed button when using "padded" rendition |
--b-button-group-padded-pressed-border | Border for pressed button when using "padded" rendition |
--b-button-group-padded-button-opacity | Opacity of the buttons in the group when using "padded" rendition |
--b-button-group-padded-border | Border for the button group when using "padded" rendition |
--b-button-group-padded-filled-pressed-color | Text color for pressed button when using "padded-filled" rendition |
--b-button-group-padded-filled-pressed-background | Background for pressed button when using "padded-filled" rendition |
--b-button-group-padded-filled-pressed-hover-background | Background for hovered pressed button when using "padded-filled" rendition (when not in a toggle group) |