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:

Button group
//<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

Common

listenersEvents

CSS

cls: String

Custom CSS class to add to element.

new ButtonGroup({
  cls : 'custom-css-class,
  items : [
      { icon : 'fa fa-unicorn', cls : 'button-cls-class' },
      ...
  ]
});
borderContainer
htmlClsWidget
itemClsContainer
styleWidget
uiWidget

Other

color: String

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.

rendition: elevated | filled | tonal | outlined | text | padded | padded-filled | StringAlso a property

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.

toggleGroup: Boolean

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.

useGap: Boolean= false

If you use gaps between your buttons, set this to true (controls whether to use border-radius for the button elements)

columnWidget
defaultFocusContainer
labelPositionContainer
rtlRTL
spanWidget

Accessibility

ariaLabelWidget
keyMapKeyMap

Content

defaultsContainer
lazyItemsContainer
namedItemsContainer
textContentContainer

DOM

adoptWidget
appendToWidget
contentWidget
datasetWidget
htmlWidget
idWidget
tagWidget
titleWidget

Float & align

alignWidget
anchorWidget
centeredWidget
draggableWidget
floatingWidget
xWidget
yWidget

Layout

alignSelfWidget
dockWidget
flexWidget
heightWidget
hiddenWidget
hideWhenEmptyContainer
layoutContainer
layoutStyleContainer
marginWidget
maxHeightWidget
maxWidthWidget
minHeightWidget
minWidthWidget
textAlignWidget
weightWidget
widthWidget

misc

tabBarItemsContainer

Misc

dataFieldWidget
disabledWidget
localeClassLocalizable
localizableLocalizable
maskedWidget
ownerWidget
readOnlyWidget
refWidget
rippleWidget
tabWidget
tooltipWidget

Record

recordContainer

Scrolling

Properties

83

Class hierarchy

isButtonGroup: Boolean= truereadonly
Identifies an object as an instance of ButtonGroup class, or subclass thereof.
isButtonGroup: Boolean= truereadonlystatic
Identifies an object as an instance of ButtonGroup class, or subclass thereof.
isContainerContainer
isDelayableDelayable
isEventsEvents
isKeyMapKeyMap
isLocalizableLocalizable
isWidgetWidget

Other

rendition: elevated | filled | tonal | outlined | text | padded | padded-filled | StringAlso a config

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.

$namestaticWidget
columnWidget
firstItemContainer
hasChangesContainer
isValidContainer
itemsContainer
labelPositionContainer
lastItemContainer
rtlRTL
spanWidget
typestaticWidget
valuesContainer

Accessibility

keyMapKeyMap

CSS

clsWidget

DOM

appendToWidget
contentWidget
datasetWidget
elementWidget
htmlWidget
idWidget
styleWidget

Float & align

xWidget
yWidget

Layout

alignSelfWidget
flexWidget
heightWidget
layoutContainer
layoutStyleContainer
marginWidget
maxHeightWidget
maxWidthWidget
minHeightWidget
minWidthWidget
widthWidget

Lifecycle

configBase

Misc

cellInfoWidget
disabledWidget
localeHelperLocalizable
localeManagerLocalizable
readOnlyWidget
refWidget
tabWidget
tooltipWidget

Record

recordContainer

Visibility

hiddenWidget
isVisibleWidget

Widget hierarchy

ownerWidget
parentWidget
widgetMapContainer

Functions

67

Configuration

applyDefaultsstaticBase

Events

Float & align

alignToWidget
setXYWidget
showByWidget
toFrontWidget

Lifecycle

createstaticWidget
destroystaticBase
initClassstaticWidget

Misc

attachTooltipstaticWidget
fromElementstaticWidget
fromSelectorstaticWidget
getByIdstaticWidget
isOfTypeNamestaticBase
mixinstaticBase
optionalLstaticLocalizable

Other

addContainer
composeWidget
createOnFrameDelayable
disableWidget
enableWidget
focusWidget
getAtContainer
getWidgetByIdContainer
insertContainer
LstaticLocalizable
maskWidget
onEvents
recomposeWidget
relayAllEvents
removeContainer
removeAllContainer
resetValuesContainer
setValuesContainer
triggerEvents
unEvents
unmaskWidget

Visibility

hideWidget
showWidget

Widget hierarchy

closestWidget
containsWidget
ownsWidget
queryWidget
queryAllWidget
upWidget

Events

19

Fires 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 }) => {

});
ParameterTypeDescription
sourceButton

Clicked button

eventEvent

DOM event

Fires when a button in the group is clicked

// Adding a listener using the "on" method
buttonGroup.on('click', ({ source, event }) => {

});
ParameterTypeDescription
sourceButton

Clicked button

eventEvent

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 }) => {

});
ParameterTypeDescription
sourceButton

Toggled button

pressedBoolean

New pressed state

eventEvent

DOM event

catchAllEvents
destroyEvents
focusInWidget
focusOutWidget
hideWidget
paintWidget
readOnlyWidget
recomposeWidget
resizeWidget
showWidget

Event handlers

19

Called when the default action is performed on a button in the group (the button is clicked)

new ButtonGroup({
    onAction({ source, event }) {

    }
});
ParameterTypeDescription
sourceButton

Clicked button

eventEvent

DOM event

Called when a button in the group is clicked

new ButtonGroup({
    onClick({ source, event }) {

    }
});
ParameterTypeDescription
sourceButton

Clicked button

eventEvent

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 }) {

    }
});
ParameterTypeDescription
sourceButton

Toggled button

pressedBoolean

New pressed state

eventEvent

DOM event

onDestroyEvents
onFocusInWidget
onHideWidget
onPaintWidget
onResizeWidget
onShowWidget

Typedefs

6

CSS variables

47
NameDescription
--b-button-group-border-widthButtonGroup border width, overridden by `--b-button-outlined-border-width` when using outlined rendition
--b-button-group-border-radiusButtonGroup border-radius, should normally match Button border-radius (cannot hide overflow, since badges need to stay visible)
--b-button-group-box-shadowButtonGroup box-shadow, overridden by `--b-button-elevated-box-shadow` when using elevated rendition
--b-button-group-border-colorButtonGroup border color, overridden by `--b-button-outlined-border-color` when using outlined rendition
--b-button-group-padded-paddingPadding when using "padded" rendition
--b-button-group-padded-backgroundBackground when using "padded" rendition
--b-button-group-padded-active-backgroundBackground for active (held down) button when using "padded" rendition
--b-button-group-padded-pressed-backgroundBackground for pressed button when using "padded" rendition
--b-button-group-padded-pressed-hover-backgroundBackground for hovered pressed button when using "padded" rendition (when not in a toggle group)
--b-button-group-padded-pressed-box-shadowBox-shadow for pressed button when using "padded" rendition
--b-button-group-padded-pressed-borderBorder for pressed button when using "padded" rendition
--b-button-group-padded-button-opacityOpacity of the buttons in the group when using "padded" rendition
--b-button-group-padded-borderBorder for the button group when using "padded" rendition
--b-button-group-padded-filled-pressed-colorText color for pressed button when using "padded-filled" rendition
--b-button-group-padded-filled-pressed-backgroundBackground for pressed button when using "padded-filled" rendition
--b-button-group-padded-filled-pressed-hover-backgroundBackground for hovered pressed button when using "padded-filled" rendition (when not in a toggle group)

Inherited