Skip to content
PHP Ecosystem
Explore

TogglerAttributesTrait

API reference › Bootstrap 6 › TogglerAttributesTrait

traityii2\extensions\bootstrap6\TogglerAttributesTrait
Sourcesrc/TogglerAttributesTrait.php
Used by 4 types

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.

MethodDescriptionDefined 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 abstractReturns the HTML attributes of the toggler by reference, enabling the toggler when it is disabled.TogglerAttributesTrait
public function addTogglerAttribute(string $name, mixed $value): static

Sets an HTML attribute value of the toggler.

Parameters

ParameterTypeDescription
$namestringAttribute name.
$valuemixedAttribute value, or null to omit the attribute when rendering.

Returns

static

public function addTogglerClass(BackedEnum|string|null ...$class): static

Adds one or more CSS classes to the existing toggler classes; duplicated classes are collapsed.

Parameters

ParameterTypeDescription
...$classBackedEnum|string|nullCSS class names to add; an enum case adds its value, and null is ignored.

Returns

static

See also

public function addTogglerCssStyle(array<string, string>|string $style, bool $overwrite = true): static

Adds CSS style properties to the style attribute of the toggler.

Follows the merge rules of AttributesTrait::addCssStyle().

Parameters

ParameterTypeDescription
$stylearray<string, string>|stringCSS style, either an array such as ['color' => 'red', 'font-weight' => 'bold'] or a string such as color: red; font-weight: bold;.
$overwriteboolWhether to replace the value of properties already set; when false, their existing value is kept.

Returns

static

See also

abstract protected function togglerOptions(): mixed[]

Returns the HTML attributes of the toggler by reference, enabling the toggler when it is disabled.

Returns

mixed[]