# AccordionItem

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

[API reference](/docs/api/index.md) › [Bootstrap 6](/docs/extensions/bootstrap6/reference/index.md) › [item](/docs/extensions/bootstrap6/reference/item/index.md) › AccordionItem

| final readonly class | `yii2\extensions\bootstrap6\item\AccordionItem` |
| --- | --- |
| Uses traits | [`ItemTrait`](/docs/extensions/bootstrap6/reference/item/itemtrait/index.md) |
| Source | [`src/item/AccordionItem.php`](https://github.com/yii2-extensions/bootstrap6/blob/main/src/item/AccordionItem.php#L14) |

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

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-bodyOptions"></span>`$bodyOptions` readonly constructor | `array<array-key, mixed>` | HTML attributes of the `.accordion-body` element. Default: `[]`. | `AccordionItem` |
| <span id="property-content"></span>`$content` readonly constructor | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php) | Content of the `.accordion-body` element (not encoded). | `AccordionItem` |
| <span id="property-encode"></span>`$encode` readonly constructor | `bool\|null` | Whether to HTML-encode [`$label`](/docs/extensions/bootstrap6/reference/item/accordionitem/index.md#property-label), or `null` to use `Accordion::$encodeLabels`. Default: `null`. | `AccordionItem` |
| <span id="property-headerOptions"></span>`$headerOptions` readonly constructor | `array<array-key, mixed>` | HTML attributes of the `<summary>` element. Default: `[]`. | `AccordionItem` |
| <span id="property-label"></span>`$label` readonly constructor | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php) | Content of the `<summary>` element. | `AccordionItem` |
| <span id="property-open"></span>`$open` readonly constructor | `bool` | Whether the item is initially expanded. Default: `false`. | `AccordionItem` |
| <span id="property-options"></span>`$options` readonly constructor | `array<array-key, mixed>` | HTML attributes of the `<details>` element. Default: `[]`. | `AccordionItem` |
| <span id="property-visible"></span>`$visible` readonly constructor | `bool` | Whether to render the item. Default: `true`. | `AccordionItem` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`fromArray()`](#method-fromArray) static | Creates an item from the array configuration documented in `Accordion::$items`. | `AccordionItem` |
| [`to()`](#method-to) static | Creates an item. | `AccordionItem` |
| [`withBodyOptions()`](#method-withBodyOptions) | Returns a copy with the given `.accordion-body` attributes. | `AccordionItem` |
| [`withContent()`](#method-withContent) | Returns a copy with the given content. | `AccordionItem` |
| [`withEncode()`](#method-withEncode) | Returns a copy with the given encoding flag. | `AccordionItem` |
| [`withHeaderOptions()`](#method-withHeaderOptions) | Returns a copy with the given `<summary>` attributes. | `AccordionItem` |
| [`withLabel()`](#method-withLabel) | Returns a copy with the given label. | `AccordionItem` |
| [`withOpen()`](#method-withOpen) | Returns a copy with the given expanded state. | `AccordionItem` |
| [`withOptions()`](#method-withOptions) | Returns a copy with the given `<details>` attributes. | `AccordionItem` |
| [`withVisible()`](#method-withVisible) | Returns a copy with the given visibility. | `AccordionItem` |

## Method details

### fromArray() <span id="method-fromArray"></span>

```php
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**

| Parameter | Type | Description |
| --- | --- | --- |
| `$config` | `array<array-key, mixed>` | Item configuration. |

**Returns**

`self`

**Throws**

- [`yii\base\InvalidConfigException`](/docs/api/yii/base/invalidconfigexception/index.md): if the item has no `string|Stringable` `label` or `content`.

### to() <span id="method-to"></span>

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

Creates an item.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$label` | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php) | Content of the `<summary>` element. |
| `$content` | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php) | Content of the `.accordion-body` element (not encoded). |

**Returns**

`self`

### withBodyOptions() <span id="method-withBodyOptions"></span>

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

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

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$bodyOptions` | `array<array-key, mixed>` | HTML attributes of the `.accordion-body` element. |

**Returns**

`self`

### withContent() <span id="method-withContent"></span>

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

Returns a copy with the given content.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$content` | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php) |  |

**Returns**

`self`

### withEncode() <span id="method-withEncode"></span>

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

Returns a copy with the given encoding flag.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$encode` | `bool\|null` |  |

**Returns**

`self`

### withHeaderOptions() <span id="method-withHeaderOptions"></span>

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

Returns a copy with the given `<summary>` attributes.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$headerOptions` | `array<array-key, mixed>` | HTML attributes of the `<summary>` element. |

**Returns**

`self`

### withLabel() <span id="method-withLabel"></span>

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

Returns a copy with the given label.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$label` | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php) |  |

**Returns**

`self`

### withOpen() <span id="method-withOpen"></span>

```php
public function withOpen(bool $open): self
```

Returns a copy with the given expanded state.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$open` | `bool` |  |

**Returns**

`self`

### withOptions() <span id="method-withOptions"></span>

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

Returns a copy with the given `<details>` attributes.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$options` | `array<array-key, mixed>` | HTML attributes of the `<details>` element. |

**Returns**

`self`

### withVisible() <span id="method-withVisible"></span>

```php
public function withVisible(bool $visible): self
```

Returns a copy with the given visibility.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$visible` | `bool` |  |

**Returns**

`self`