TabItem
API reference › Bootstrap 6 › item › TabItem
Represents a Tabs item: a tab with its pane, a plain link, or a toggle that opens a Menu of tabs.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$active readonly constructor | bool| | 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 |
$content readonly constructor | string|Stringable| | HTML content of the pane, or null for an empty pane. Default: null. | TabItem |
$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, and a disabled toggle is never marked active. Default: false. | TabItem |
$encode readonly constructor | bool| | Whether to HTML-encode $label, or null to use Tabs::$encodeLabels. Default: null. | TabItem |
$headerOptions readonly constructor | array<array-key, | HTML attributes of the .nav-item element. Default: []. | TabItem |
$items readonly constructor | array<array-key, MenuItem|TabItem> | Items of the menu toggled by the tab: tabs are rendered as menu buttons with their panes, tabs with a $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 |
$label readonly constructor | string|Stringable | Label of the tab button, link, or menu toggle. | TabItem |
$linkOptions readonly constructor | array<array-key, | HTML attributes of the tab button; its id defaults to {id}-tab{n}. Default: []. | TabItem |
$options readonly constructor | array<array-key, | HTML attributes of the pane; its id defaults to {id}-pane{n}. Default: []. | TabItem |
$url readonly constructor | array<array-key, | URL of a plain link tab, processed by Url::to(), or null for a tab with a pane. Default: null. | TabItem |
$visible readonly constructor | bool | Whether to render the tab and its pane. Default: true. | TabItem |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
fromArray() static | Creates an item from the array configuration documented in Tabs::$items. | TabItem |
link() static | Creates a plain link tab. | TabItem |
menu() static | Creates a toggle that opens a Menu of tabs. | TabItem |
to() static | Creates a tab with its pane. | TabItem |
withActive() | Returns a copy with the given active state. | TabItem |
withContent() | Returns a copy with the given pane content. | TabItem |
withDisabled() | Returns a copy with the given disabled state. | TabItem |
withEncode() | Returns a copy with the given encoding flag. | TabItem |
withHeaderOptions() | Returns a copy with the given .nav-item attributes. | TabItem |
withItems() | Returns a copy with the given menu items. | TabItem |
withLabel() | Returns a copy with the given label. | TabItem |
withLinkOptions() | Returns a copy with the given tab button attributes. | TabItem |
withOptions() | Returns a copy with the given pane attributes. | TabItem |
withUrl() | Returns a copy with the given URL. | TabItem |
withVisible() | Returns a copy with the given visibility. | TabItem |
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 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(), the others recursively through this method.
Parameters
| Parameter | Type | Description |
|---|---|---|
$config | array<array-key, | Item configuration. |
Returns
self
Throws
yii\base\InvalidConfigException: if the item, or one of its nested items, has nostring|Stringablelabel.
link()
Section titled “link() ”public static function link(string|Stringable $label, array<array-key, mixed>|string $url): selfCreates a plain link tab.
Parameters
| Parameter | Type | Description |
|---|---|---|
$label | string|Stringable | Link label. |
$url | array<array-key, | URL processed by Url::to(). |
Returns
self
menu()
Section titled “menu() ”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): selfCreates a toggle that opens a Menu of tabs.
Parameters
| Parameter | Type | Description |
|---|---|---|
$label | string|Stringable | Toggle label. |
$items | array<array-key,MenuItem|TabItem> | 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(). |
Returns
self
public static function to(string|Stringable $label, string|Stringable|null $content = null): selfCreates a tab with its pane.
Parameters
| Parameter | Type | Description |
|---|---|---|
$label | string|Stringable | Tab label. |
$content | string|Stringable| | HTML content of the pane. |
Returns
self
withActive()
Section titled “withActive() ”public function withActive(bool|null $active): selfReturns a copy with the given active state.
Parameters
| Parameter | Type | Description |
|---|---|---|
$active | bool| |
Returns
self
withContent()
Section titled “withContent() ”public function withContent(string|Stringable|null $content): selfReturns a copy with the given pane content.
withDisabled()
Section titled “withDisabled() ”public function withDisabled(bool $disabled): selfReturns a copy with the given disabled state.
Parameters
| Parameter | Type | Description |
|---|---|---|
$disabled | bool |
Returns
self
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 .nav-item attributes.
Parameters
| Parameter | Type | Description |
|---|---|---|
$headerOptions | array<array-key, | HTML attributes of the .nav-item element. |
Returns
self
withItems()
Section titled “withItems() ”public function withItems(array<array-key, array<string, mixed>|yii2\extensions\bootstrap6\item\MenuItem|string|yii2\extensions\bootstrap6\item\TabItem> $items): selfReturns a copy with the given menu items.
Parameters
| Parameter | Type | Description |
|---|---|---|
$items | array<array-key,MenuItem|TabItem> | 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(). |
Returns
self
withLabel()
Section titled “withLabel() ”public function withLabel(string|Stringable $label): selfReturns a copy with the given label.
withLinkOptions()
Section titled “withLinkOptions() ”public function withLinkOptions(array<array-key, mixed> $linkOptions): selfReturns a copy with the given tab button attributes.
Parameters
| Parameter | Type | Description |
|---|---|---|
$linkOptions | array<array-key, | HTML attributes of the tab button. |
Returns
self
withOptions()
Section titled “withOptions() ”public function withOptions(array<array-key, mixed> $options): selfReturns a copy with the given pane attributes.
Parameters
| Parameter | Type | Description |
|---|---|---|
$options | array<array-key, | HTML attributes of the pane. |
Returns
self
withUrl()
Section titled “withUrl() ”public function withUrl(array<array-key, mixed>|string|null $url): selfReturns a copy with the given URL.
Parameters
| Parameter | Type | Description |
|---|---|---|
$url | array<array-key, | URL processed by Url::to(), or null for a tab with a pane. |
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