Skip to content
PHP Ecosystem
Explore

AccordionItem

API reference › Bootstrap 6 › item › AccordionItem

final readonly classyii2\extensions\bootstrap6\item\AccordionItem
Uses traitsItemTrait
Sourcesrc/item/AccordionItem.php

Represents an Accordion item: a <details> element with its <summary> label and .accordion-body content.

PropertyTypeDescriptionDefined by
$bodyOptions readonly constructorarray<array-key, mixed>HTML attributes of the .accordion-body element. Default: [].AccordionItem
$content readonly constructorstring|StringableContent of the .accordion-body element (not encoded).AccordionItem
$encode readonly constructorbool|nullWhether to HTML-encode $label, or null to use Accordion::$encodeLabels. Default: null.AccordionItem
$headerOptions readonly constructorarray<array-key, mixed>HTML attributes of the <summary> element. Default: [].AccordionItem
$label readonly constructorstring|StringableContent of the <summary> element.AccordionItem
$open readonly constructorboolWhether the item is initially expanded. Default: false.AccordionItem
$options readonly constructorarray<array-key, mixed>HTML attributes of the <details> element. Default: [].AccordionItem
$visible readonly constructorboolWhether to render the item. Default: true.AccordionItem
MethodDescriptionDefined by
fromArray() staticCreates an item from the array configuration documented in Accordion::$items.AccordionItem
to() staticCreates an item.AccordionItem
withBodyOptions()Returns a copy with the given .accordion-body attributes.AccordionItem
withContent()Returns a copy with the given content.AccordionItem
withEncode()Returns a copy with the given encoding flag.AccordionItem
withHeaderOptions()Returns a copy with the given <summary> attributes.AccordionItem
withLabel()Returns a copy with the given label.AccordionItem
withOpen()Returns a copy with the given expanded state.AccordionItem
withOptions()Returns a copy with the given <details> attributes.AccordionItem
withVisible()Returns a copy with the given visibility.AccordionItem
public static function fromArray(array<array-key, mixed> $config): self

Creates an item from the array configuration documented in Accordion::$items.

Only true opens the item and only false hides it; an encode other than null is compared with false; attribute keys that are not arrays are ignored.

Parameters

ParameterTypeDescription
$configarray<array-key, mixed>Item configuration.

Returns

self

Throws

public static function to(string|Stringable $label, string|Stringable $content): self

Creates an item.

Parameters

ParameterTypeDescription
$labelstring|StringableContent of the <summary> element.
$contentstring|StringableContent of the .accordion-body element (not encoded).

Returns

self

public function withBodyOptions(array<array-key, mixed> $bodyOptions): self

Returns a copy with the given .accordion-body attributes.

Parameters

ParameterTypeDescription
$bodyOptionsarray<array-key, mixed>HTML attributes of the .accordion-body element.

Returns

self

public function withContent(string|Stringable $content): self

Returns a copy with the given content.

Parameters

ParameterTypeDescription
$contentstring|Stringable

Returns

self

public function withEncode(bool|null $encode): self

Returns a copy with the given encoding flag.

Parameters

ParameterTypeDescription
$encodebool|null

Returns

self

public function withHeaderOptions(array<array-key, mixed> $headerOptions): self

Returns a copy with the given <summary> attributes.

Parameters

ParameterTypeDescription
$headerOptionsarray<array-key, mixed>HTML attributes of the <summary> element.

Returns

self

public function withLabel(string|Stringable $label): self

Returns a copy with the given label.

Parameters

ParameterTypeDescription
$labelstring|Stringable

Returns

self

public function withOpen(bool $open): self

Returns a copy with the given expanded state.

Parameters

ParameterTypeDescription
$openbool

Returns

self

public function withOptions(array<array-key, mixed> $options): self

Returns a copy with the given <details> attributes.

Parameters

ParameterTypeDescription
$optionsarray<array-key, mixed>HTML attributes of the <details> element.

Returns

self

public function withVisible(bool $visible): self

Returns a copy with the given visibility.

Parameters

ParameterTypeDescription
$visiblebool

Returns

self