AccordionItem
API reference › Bootstrap 6 › item › AccordionItem
Represents an Accordion item: a <details> element with its <summary> label and .accordion-body content.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$bodyOptions readonly constructor | array<array-key, | HTML attributes of the .accordion-body element. Default: []. | AccordionItem |
$content readonly constructor | string|Stringable | Content of the .accordion-body element (not encoded). | AccordionItem |
$encode readonly constructor | bool| | Whether to HTML-encode $label, or null to use Accordion::$encodeLabels. Default: null. | AccordionItem |
$headerOptions readonly constructor | array<array-key, | HTML attributes of the <summary> element. Default: []. | AccordionItem |
$label readonly constructor | string|Stringable | Content of the <summary> element. | AccordionItem |
$open readonly constructor | bool | Whether the item is initially expanded. Default: false. | AccordionItem |
$options readonly constructor | array<array-key, | HTML attributes of the <details> element. Default: []. | AccordionItem |
$visible readonly constructor | bool | Whether to render the item. Default: true. | AccordionItem |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
fromArray() static | Creates an item from the array configuration documented in Accordion::$items. | AccordionItem |
to() static | Creates 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 |
Method details
Section titled “Method details”fromArray()
Section titled “fromArray() ”public static function fromArray(array<array-key, mixed> $config): selfCreates 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
| Parameter | Type | Description |
|---|---|---|
$config | array<array-key, | Item configuration. |
Returns
self
Throws
yii\base\InvalidConfigException: if the item has nostring|Stringablelabelorcontent.
public static function to(string|Stringable $label, string|Stringable $content): selfCreates an item.
Parameters
| Parameter | Type | Description |
|---|---|---|
$label | string|Stringable | Content of the <summary> element. |
$content | string|Stringable | Content of the .accordion-body element (not encoded). |
Returns
self
withBodyOptions()
Section titled “withBodyOptions() ”public function withBodyOptions(array<array-key, mixed> $bodyOptions): selfReturns a copy with the given .accordion-body attributes.
Parameters
| Parameter | Type | Description |
|---|---|---|
$bodyOptions | array<array-key, | HTML attributes of the .accordion-body element. |
Returns
self
withContent()
Section titled “withContent() ”public function withContent(string|Stringable $content): selfReturns a copy with the given content.
withEncode()
Section titled “withEncode() ”public function withEncode(bool|null $encode): selfReturns a copy with the given encoding flag.
Parameters
| Parameter | Type | Description |
|---|---|---|
$encode | bool| |
Returns
self
withHeaderOptions()
Section titled “withHeaderOptions() ”public function withHeaderOptions(array<array-key, mixed> $headerOptions): selfReturns a copy with the given <summary> attributes.
Parameters
| Parameter | Type | Description |
|---|---|---|
$headerOptions | array<array-key, | HTML attributes of the <summary> element. |
Returns
self
withLabel()
Section titled “withLabel() ”public function withLabel(string|Stringable $label): selfReturns a copy with the given label.
withOpen()
Section titled “withOpen() ”public function withOpen(bool $open): selfReturns a copy with the given expanded state.
Parameters
| Parameter | Type | Description |
|---|---|---|
$open | bool |
Returns
self
withOptions()
Section titled “withOptions() ”public function withOptions(array<array-key, mixed> $options): selfReturns a copy with the given <details> attributes.
Parameters
| Parameter | Type | Description |
|---|---|---|
$options | array<array-key, | HTML attributes of the <details> element. |
Returns
self
withVisible()
Section titled “withVisible() ”public function withVisible(bool $visible): selfReturns a copy with the given visibility.
Parameters
| Parameter | Type | Description |
|---|---|---|
$visible | bool |
Returns
self