Introduction
The toggle buttons input provides a group of buttons for selecting a single value, or multiple values, from a list of predefined options:Changing the color of option buttons
You can change the color of the option buttons using thecolors() method. Each key in the array should correspond to an option value:
HasColor interface to define colors instead.
Adding icons to option buttons
You can add icon to the option buttons using theicons() method. Each key in the array should correspond to an option value, and the value may be any valid icon:
HasIcon interface to define icons instead.
If you want to display only icons, you can use hiddenButtonLabels() to hide the option labels.
Adding tooltips to option buttons
You can add different tooltips to each option button using thetooltips() method.
Changing the button size
By default, toggle buttons use the medium size. You can change the size using thesize() method:
Size::ExtraSmall, Size::Small, Size::Medium, Size::Large, and Size::ExtraLarge. You can also pass their backed values ('xs', 'sm', 'md', 'lg', and 'xl'). Any other string is applied as a custom CSS class. Passing null restores the default medium size. The button size is also applied when using grouped().
Boolean options
If you want a simple boolean toggle button group, with “Yes” and “No” options, you can use theboolean() method:
colors() or icons().
To customize the “Yes” label, you can use the trueLabel argument on the boolean() method:
falseLabel argument on the boolean() method:
Positioning the options inline with each other
You may wish to display the buttonsinline() with each other:
Grouping option buttons
You may wish to group option buttons together so they are more compact, using thegrouped() method. This also makes them appear horizontally inline with each other:
Filling the container’s width
By default, the buttons only take up as much horizontal space as they need. You may use thefullWidth() method to allow buttons to stretch and fill the available width of their container. This can be used with the default (stacked) configuration, or alongside both inline() and grouped() methods:
Selecting multiple buttons
Themultiple() method on the ToggleButtons component allows you to select multiple values from the list of options:
array cast to the model property:
Splitting options into columns
You may split options into columns by using thecolumns() method:
columns() method of the grid. This allows you to responsively customize the number of columns at various breakpoints.
Setting the grid direction
By default, when you arrange buttons into columns, they will be listed in order vertically. If you’d like to list them horizontally, you may use thegridDirection(GridDirection::Row) method:
Disabling specific options
You can disable specific options using thedisableOptionWhen() method. It accepts a closure, in which you can check if the option with a specific $value should be disabled:
getEnabledOptions():
in() function, please see the Validation documentation.