TogglerAttributesTrait
API reference › Bootstrap 6 › TogglerAttributesTrait
Provides fluent methods that modify the HTML attributes of the toggler rendered by the widget.
The using class implements togglerOptions(), which returns its toggler attribute array by reference; every
method modifies that array in place and returns the same instance. The attributes the toggler requires (for example
data-bs-toggle or aria-controls) are added while rendering.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
addTogglerAttribute() | Sets an HTML attribute value of the toggler. | TogglerAttributesTrait |
addTogglerClass() | Adds one or more CSS classes to the existing toggler classes; duplicated classes are collapsed. | TogglerAttributesTrait |
addTogglerCssStyle() | Adds CSS style properties to the style attribute of the toggler. | TogglerAttributesTrait |
togglerOptions() protected abstract | Returns the HTML attributes of the toggler by reference, enabling the toggler when it is disabled. | TogglerAttributesTrait |
Method details
Section titled “Method details”addTogglerAttribute()
Section titled “addTogglerAttribute() ”public function addTogglerAttribute(string $name, mixed $value): staticSets an HTML attribute value of the toggler.
Parameters
| Parameter | Type | Description |
|---|---|---|
$name | string | Attribute name. |
$value | mixed | Attribute value, or null to omit the attribute when rendering. |
Returns
static
addTogglerClass()
Section titled “addTogglerClass() ”public function addTogglerClass(BackedEnum|string|null ...$class): staticAdds one or more CSS classes to the existing toggler classes; duplicated classes are collapsed.
Parameters
| Parameter | Type | Description |
|---|---|---|
...$class | BackedEnum| | CSS class names to add; an enum case adds its value, and null is ignored. |
Returns
static
See also
addTogglerCssStyle()
Section titled “addTogglerCssStyle() ”public function addTogglerCssStyle(array<string, string>|string $style, bool $overwrite = true): staticAdds CSS style properties to the style attribute of the toggler.
Follows the merge rules of AttributesTrait::addCssStyle().
Parameters
| Parameter | Type | Description |
|---|---|---|
$style | array<string, | CSS style, either an array such as ['color' => 'red', or a string such as color: red; font-weight: bold;. |
$overwrite | bool | Whether to replace the value of properties already set; when false, their existing value is kept. |
Returns
static
See also
togglerOptions()
Section titled “togglerOptions() ”abstract protected function togglerOptions(): mixed[]Returns the HTML attributes of the toggler by reference, enabling the toggler when it is disabled.
Returns
mixed[]