Skip to content
PHP Ecosystem
Explore

TabItem

API reference › Bootstrap 6 › item › TabItem

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

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

PropertyTypeDescriptionDefined by
$active readonly constructorbool|nullWhether 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 constructorstring|Stringable|nullHTML content of the pane, or null for an empty pane. Default: null.TabItem
$disabled readonly constructorboolWhether 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 constructorbool|nullWhether to HTML-encode $label, or null to use Tabs::$encodeLabels. Default: null.TabItem
$headerOptions readonly constructorarray<array-key, mixed>HTML attributes of the .nav-item element. Default: [].TabItem
$items readonly constructorarray<array-key, MenuItem|string|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 constructorstring|StringableLabel of the tab button, link, or menu toggle.TabItem
$linkOptions readonly constructorarray<array-key, mixed>HTML attributes of the tab button; its id defaults to {id}-tab{n}. Default: [].TabItem
$options readonly constructorarray<array-key, mixed>HTML attributes of the pane; its id defaults to {id}-pane{n}. Default: [].TabItem
$url readonly constructorarray<array-key, mixed>|string|nullURL of a plain link tab, processed by Url::to(), or null for a tab with a pane. Default: null.TabItem
$visible readonly constructorboolWhether to render the tab and its pane. Default: true.TabItem
MethodDescriptionDefined by
fromArray() staticCreates an item from the array configuration documented in Tabs::$items.TabItem
link() staticCreates a plain link tab.TabItem
menu() staticCreates a toggle that opens a Menu of tabs.TabItem
to() staticCreates 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
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(), the others recursively through this method.

Parameters

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

Returns

self

Throws

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

Creates a plain link tab.

Parameters

ParameterTypeDescription
$labelstring|StringableLink label.
$urlarray<array-key, mixed>|stringURL processed by Url::to().

Returns

self

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

ParameterTypeDescription
$labelstring|StringableToggle label.
$itemsarray<array-key, array<string, mixed>|MenuItem|string|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): self

Creates a tab with its pane.

Parameters

ParameterTypeDescription
$labelstring|StringableTab label.
$contentstring|Stringable|nullHTML content of the pane.

Returns

self

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

Returns a copy with the given active state.

Parameters

ParameterTypeDescription
$activebool|null

Returns

self

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

Returns a copy with the given pane content.

Parameters

ParameterTypeDescription
$contentstring|Stringable|null

Returns

self

public function withDisabled(bool $disabled): self

Returns a copy with the given disabled state.

Parameters

ParameterTypeDescription
$disabledbool

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

Parameters

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

Returns

self

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

ParameterTypeDescription
$itemsarray<array-key, array<string, mixed>|MenuItem|string|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 function withLabel(string|Stringable $label): self

Returns a copy with the given label.

Parameters

ParameterTypeDescription
$labelstring|Stringable

Returns

self

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

Returns a copy with the given tab button attributes.

Parameters

ParameterTypeDescription
$linkOptionsarray<array-key, mixed>HTML attributes of the tab button.

Returns

self

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

Returns a copy with the given pane attributes.

Parameters

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

Returns

self

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

Returns a copy with the given URL.

Parameters

ParameterTypeDescription
$urlarray<array-key, mixed>|string|nullURL processed by Url::to(), or null for a tab with a pane.

Returns

self

public function withVisible(bool $visible): self

Returns a copy with the given visibility.

Parameters

ParameterTypeDescription
$visiblebool

Returns

self