Skip to main content

Button Group Field

type: "button-group"

A row of toggle buttons, of which one is selected. Like a radio field, it shows all options at once, but it takes much less room and the buttons can show icons. It suits a few short options, like an alignment or a direction.

Additional Properties​

PropertyTypeRestrictionsDescription
optionsValueButtonOptionsRequiredThe buttons users can select from.
defaultValuestring-The value of the button selected by default.

Unlike the options of a select field, a button doesn't need a label. A button with only an icon shows just the icon, which works well for alignments and similar choices. A button with neither a label nor an icon shows its value.

While users haven't picked a button, the button of the defaultValue is shown as selected. Users can clear their choice with the clear button next to the group, which brings back the defaultValue.

Icons​

The icon of a button references an icon of Strato or of any react-icons set, prefixed with the icon set: LineChartIcon or strato/LineChartIcon for Strato, md/MdHome, fa6/FaHouse or lu/LuAlignLeft for react-icons. See Icons for all prefixes.

Example​

mobro-widget-config.json
{
"config": [
{
"name": "text_align",
"label": "Alignment",
"type": "button-group",
"defaultValue": "left",
"options": [
{"value": "left", "icon": "lu/LuAlignLeft"},
{"value": "center", "icon": "lu/LuAlignCenter"},
{"value": "right", "icon": "lu/LuAlignRight"}
]
},
{
"name": "size",
"label": "Size",
"type": "button-group",
"defaultValue": "m",
"options": [
{"label": "S", "value": "s"},
{"label": "M", "value": "m"},
{"label": "L", "value": "l"}
]
}
]
}

Usage​

The value of a button group field is the value of the selected button. To read it in a widget, use useButtonGroupField.