# TabItem

> Represents a Tabs item: a tab with its pane, a plain link, or a toggle that opens a Menu of tabs.

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

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

Represents a `Tabs` item: a tab with its pane, a plain link, or a toggle that opens a `Menu` of tabs.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-active"></span>`$active` readonly constructor | `bool\|null` | Whether the tab and its pane, the link, or the menu toggle are active, or `null` to let `Tabs` activate the first eligible tab when none is active; an active menu toggle needs no active item. Default: `null`. | `TabItem` |
| <span id="property-content"></span>`$content` readonly constructor | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php)`\|null` | HTML content of the pane, or `null` for an empty pane. Default: `null`. | `TabItem` |
| <span id="property-disabled"></span>`$disabled` readonly constructor | `bool` | Whether the tab button, the link, or the menu toggle is disabled; a disabled link loses its `href` and takes precedence over [`$active`](/docs/extensions/bootstrap6/reference/item/tabitem/index.md#property-active), and a disabled toggle is never marked active. Default: `false`. | `TabItem` |
| <span id="property-encode"></span>`$encode` readonly constructor | `bool\|null` | Whether to HTML-encode [`$label`](/docs/extensions/bootstrap6/reference/item/tabitem/index.md#property-label), or `null` to use `Tabs::$encodeLabels`. Default: `null`. | `TabItem` |
| <span id="property-headerOptions"></span>`$headerOptions` readonly constructor | `array<array-key, mixed>` | HTML attributes of the `.nav-item` element. Default: `[]`. | `TabItem` |
| <span id="property-items"></span>`$items` readonly constructor | `array<array-key,` [`MenuItem`](/docs/extensions/bootstrap6/reference/item/menuitem/index.md)`\|string\|`[`TabItem`](/docs/extensions/bootstrap6/reference/item/tabitem/index.md)`>` | Items of the menu toggled by the tab: tabs are rendered as menu buttons with their panes, tabs with a [`$url`](/docs/extensions/bootstrap6/reference/item/tabitem/index.md#property-url) as menu links, tabs with their own items as nested `.submenu` panels; menu items and strings are passed to the `Menu` as is. Default: `[]`. | `TabItem` |
| <span id="property-label"></span>`$label` readonly constructor | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php) | Label of the tab button, link, or menu toggle. | `TabItem` |
| <span id="property-linkOptions"></span>`$linkOptions` readonly constructor | `array<array-key, mixed>` | HTML attributes of the tab button; its `id` defaults to `{id}-tab{n}`. Default: `[]`. | `TabItem` |
| <span id="property-options"></span>`$options` readonly constructor | `array<array-key, mixed>` | HTML attributes of the pane; its `id` defaults to `{id}-pane{n}`. Default: `[]`. | `TabItem` |
| <span id="property-url"></span>`$url` readonly constructor | `array<array-key, mixed>\|string\|null` | URL of a plain link tab, processed by [`Url::to()`](/docs/api/yii/helpers/baseurl/index.md#method-to), or `null` for a tab with a pane. Default: `null`. | `TabItem` |
| <span id="property-visible"></span>`$visible` readonly constructor | `bool` | Whether to render the tab and its pane. Default: `true`. | `TabItem` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`fromArray()`](#method-fromArray) static | Creates an item from the array configuration documented in `Tabs::$items`. | `TabItem` |
| [`link()`](#method-link) static | Creates a plain link tab. | `TabItem` |
| [`menu()`](#method-menu) static | Creates a toggle that opens a `Menu` of tabs. | `TabItem` |
| [`to()`](#method-to) static | Creates a tab with its pane. | `TabItem` |
| [`withActive()`](#method-withActive) | Returns a copy with the given active state. | `TabItem` |
| [`withContent()`](#method-withContent) | Returns a copy with the given pane content. | `TabItem` |
| [`withDisabled()`](#method-withDisabled) | Returns a copy with the given disabled state. | `TabItem` |
| [`withEncode()`](#method-withEncode) | Returns a copy with the given encoding flag. | `TabItem` |
| [`withHeaderOptions()`](#method-withHeaderOptions) | Returns a copy with the given `.nav-item` attributes. | `TabItem` |
| [`withItems()`](#method-withItems) | Returns a copy with the given menu items. | `TabItem` |
| [`withLabel()`](#method-withLabel) | Returns a copy with the given label. | `TabItem` |
| [`withLinkOptions()`](#method-withLinkOptions) | Returns a copy with the given tab button attributes. | `TabItem` |
| [`withOptions()`](#method-withOptions) | Returns a copy with the given pane attributes. | `TabItem` |
| [`withUrl()`](#method-withUrl) | Returns a copy with the given URL. | `TabItem` |
| [`withVisible()`](#method-withVisible) | Returns a copy with the given visibility. | `TabItem` |

## 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 `Tabs::$items`.

An `active` key, even `null`, makes the state explicit. Nested `items` arrays with a `url` key, even `null`, or
without a `label` are converted through [`MenuItem::fromArray()`](/docs/extensions/bootstrap6/reference/item/menuitem/index.md#method-fromArray), the others recursively through this method.

**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, or one of its nested items, has no `string|Stringable` `label`.

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

```php
public static function link(string|Stringable $label, array<array-key, mixed>|string $url): self
```

Creates a plain link tab.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$label` | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php) | Link label. |
| `$url` | `array<array-key, mixed>\|string` | URL processed by [`Url::to()`](/docs/api/yii/helpers/baseurl/index.md#method-to). |

**Returns**

`self`

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

```php
public static function menu(string|Stringable $label, array<array-key, array<string, mixed>|yii2\extensions\bootstrap6\item\MenuItem|string|yii2\extensions\bootstrap6\item\TabItem> $items): self
```

Creates a toggle that opens a `Menu` of tabs.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$label` | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php) | Toggle label. |
| `$items` | `array<array-key, array<string, mixed>\|`[`MenuItem`](/docs/extensions/bootstrap6/reference/item/menuitem/index.md)`\|string\|`[`TabItem`](/docs/extensions/bootstrap6/reference/item/tabitem/index.md)`>` | Tabs rendered as menu buttons (menu links when they have a URL, nested `.submenu` panels when they have items), menu items, or strings; arrays are converted as in [`fromArray()`](/docs/extensions/bootstrap6/reference/item/tabitem/index.md#method-fromArray). |

**Returns**

`self`

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

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

Creates a tab with its pane.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$label` | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php) | Tab label. |
| `$content` | `string\|`[`Stringable`](https://www.php.net/manual/en/class.stringable.php)`\|null` | HTML content of the pane. |

**Returns**

`self`

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

```php
public function withActive(bool|null $active): self
```

Returns a copy with the given active state.

**Parameters**

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

**Returns**

`self`

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

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

Returns a copy with the given pane content.

**Parameters**

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

**Returns**

`self`

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

```php
public function withDisabled(bool $disabled): self
```

Returns a copy with the given disabled state.

**Parameters**

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

**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 `.nav-item` attributes.

**Parameters**

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

**Returns**

`self`

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

```php
public function withItems(array<array-key, array<string, mixed>|yii2\extensions\bootstrap6\item\MenuItem|string|yii2\extensions\bootstrap6\item\TabItem> $items): self
```

Returns a copy with the given menu items.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$items` | `array<array-key, array<string, mixed>\|`[`MenuItem`](/docs/extensions/bootstrap6/reference/item/menuitem/index.md)`\|string\|`[`TabItem`](/docs/extensions/bootstrap6/reference/item/tabitem/index.md)`>` | Tabs rendered as menu buttons (menu links when they have a URL, nested `.submenu` panels when they have items), menu items, or strings; arrays are converted as in [`fromArray()`](/docs/extensions/bootstrap6/reference/item/tabitem/index.md#method-fromArray). |

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

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

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

Returns a copy with the given tab button attributes.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$linkOptions` | `array<array-key, mixed>` | HTML attributes of the tab button. |

**Returns**

`self`

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

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

Returns a copy with the given pane attributes.

**Parameters**

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

**Returns**

`self`

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

```php
public function withUrl(array<array-key, mixed>|string|null $url): self
```

Returns a copy with the given URL.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$url` | `array<array-key, mixed>\|string\|null` | URL processed by [`Url::to()`](/docs/api/yii/helpers/baseurl/index.md#method-to), or `null` for a tab with a pane. |

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