Class kartik\tabs\TabsX

Inheritancekartik\tabs\TabsX » kartik\base\Widget » yii\base\Widget » yii\base\Component » yii\base\BaseObject
Implementskartik\base\BootstrapInterface, yii\base\Configurable, yii\base\ViewContextInterface
Uses Traitskartik\base\BootstrapTrait, kartik\base\TranslationTrait, kartik\base\WidgetTrait
Available since version1.0

TabsX is an extended Bootstrap Tabs navigation widget for Yii Framework 2 based on the bootstrap-tabs-x plugin by Krajee. This widget enhances the default bootstrap tabs plugin with various new styling enhancements.

echo TabsX::widget([
    'position' => TabsX::POS_ABOVE,
    'align' => TabsX::ALIGN_LEFT,
    'items' => [
        [
            'label' => 'One',
            'content' => 'Anim pariatur cliche...',
            'active' => true
        ],
        [
            'label' => 'Two',
            'content' => 'Anim pariatur cliche...',
            'headerOptions' => [],
            'options' => ['id' => 'myveryownID'],
        ],
        [
            'label' => 'Dropdown',
            'items' => [
                 [
                     'label' => 'DropdownA',
                     'content' => 'DropdownA, Anim pariatur cliche...',
                 ],
                 [
                     'label' => 'DropdownB',
                     'content' => 'DropdownB, Anim pariatur cliche...',
                 ],
            ],
        ],
    ],
]);

See also:

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$align string The alignment of the tab headers with respect to the tab content. kartik\tabs\TabsX
$autoIdPrefix string The prefix to the automatically generated widget IDs. yii\base\Widget
$baseSourcePath string|false Get parsed base source path based on $sourcePath setting. If $sourcePath is not set, it will return the current working directory of this widget class. kartik\base\WidgetTrait
$behaviors yii\base\Behavior[] List of behaviors attached to this component. yii\base\Component
$bordered boolean Whether the tab content should be boxed within a bordered container. kartik\tabs\TabsX
$bsColCssPrefixes array The bootstrap grid column css prefixes mapping, the key is the bootstrap versions, and the value is an array containing the sizes and their corresponding grid column css prefixes. kartik\base\BootstrapTrait
$bsCssMap array CSS conversion mappings across bootstrap library versions. kartik\base\BootstrapTrait
$bsExtBasename integer The yii2 bootstrap extension base name (readonly property available via getter method getBsExtBasename()) kartik\base\BootstrapTrait
$bsVer integer Bootstrap version number currently set (readonly property available via getter method getBsVer()) kartik\base\BootstrapTrait
$bsVersion integer|string The bootstrap library version that you wish to use for this specific extension / widget. kartik\base\BootstrapTrait
$containerOptions array The HTML attributes for the TabsX container. kartik\tabs\TabsX
$counter integer A counter used to generate $id for widgets. yii\base\Widget
$defaultBtnCss string Default bootstrap button CSS (readonly property available via getter method getDefaultBtnCss()) kartik\base\BootstrapTrait
$defaultIconPrefix string Default icon prefix (readonly property available via getter method getDefaultIconPrefix()) kartik\base\BootstrapTrait
$defaultOptions array Default HTML attributes or other settings for widgets. kartik\base\WidgetTrait
$defaultPluginOptions array Default plugin options for the widget kartik\base\WidgetTrait
$dropdownClass string Name of a class to use for rendering dropdowns withing this widget. kartik\tabs\TabsX
$enableStickyTabs boolean Whether to enable sticky tabs plugin to maintain tabs push state on browser back and forward. kartik\tabs\TabsX
$encodeLabels boolean Whether the labels for header items should be HTML-encoded. kartik\tabs\TabsX
$fade boolean Whether to fade in each tab pane using the fade animation effect. kartik\tabs\TabsX
$hashVarLoadPosition integer The position where the client JS hash variables for the input widget will be loaded. kartik\base\WidgetTrait
$headerOptions array List of HTML attributes for the header container tags. kartik\tabs\TabsX
$height string Whether the tab body content height should be of a fixed size. kartik\tabs\TabsX
$i18n array The the internalization configuration for this widget. kartik\base\TranslationTrait
$id string|null ID of the widget. Note that the type of this property differs in getter and setter. See getId() and setId() for details. yii\base\Widget
$itemOptions array List of HTML attributes for the item container tags. kartik\tabs\TabsX
$items array List of tabs in the tabs widget. kartik\tabs\TabsX
$linkOptions array List of HTML attributes for the tab header link tags. kartik\tabs\TabsX
$moduleId string The module identifier if this widget is part of a module. kartik\base\WidgetTrait
$navType string Specifies the Bootstrap tab styling. kartik\tabs\TabsX
$options array HTML attributes or other settings for widgets. kartik\base\Widget
$pjaxContainerId string The identifier for the PJAX widget container if the widget is to be rendered inside a PJAX container. kartik\base\WidgetTrait
$pjaxDuplicationFix boolean Prevent duplication of pjax containers when browser back & forward buttons are pressed. kartik\base\WidgetTrait
$pluginDestroyJs string The javascript that will be used to destroy the jQuery plugin kartik\base\WidgetTrait
$pluginEvents array Widget JQuery events. kartik\base\WidgetTrait
$pluginName string The plugin name kartik\base\WidgetTrait
$pluginOptions array Widget plugin options. kartik\base\WidgetTrait
$position string The position of the tabs with respect to the tab content Should be one of the TabsX::POS constants. kartik\tabs\TabsX
$printCrumbSeparator string The crumb separator for the dropdown headers in the print view when printHeaderCrumbs is true kartik\tabs\TabsX
$printHeaderCrumbs boolean Whether the headers in print view will prepend the main label to the item label in case of dropdowns. kartik\tabs\TabsX
$printHeaderOptions array The HTML attributes for the tab content header in print view. kartik\tabs\TabsX
$printable boolean Whether this tab widget should be printable. kartik\tabs\TabsX
$renderTabContent boolean Whether to render the tab-content container and its content. kartik\tabs\TabsX
$sideways boolean Whether the tab header text orientation should be rotated sideways. kartik\tabs\TabsX
$sourcePath string Directory path to the original widget source. kartik\base\WidgetTrait
$stack yii\base\Widget[] The widgets that are currently being rendered (not ended). yii\base\Widget
$stickyTabsOptions array Sticky tabs plugin options. kartik\tabs\TabsX
$tabContentOptions array List of HTML attributes for the tab-content container. kartik\tabs\TabsX
$view yii\web\View The view object that can be used to render views or view files. Note that the type of this property differs in getter and setter. See getView() and setView() for details. yii\base\Widget
$viewPath string The directory containing the view files for this widget. yii\base\Widget

Protected Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$_bsVer integer Current bootstrap version number kartik\base\BootstrapTrait
$_dataVar string The HTML5 data variable name that will be used to store the Json encoded pluginOptions within the element on which the jQuery plugin will be initialized. kartik\base\WidgetTrait
$_defaultBtnCss string Default bootstrap button CSS kartik\base\BootstrapTrait
$_defaultIconPrefix string Default icon CSS prefix kartik\base\BootstrapTrait
$_encOptions string The JSON encoded plugin options. kartik\base\WidgetTrait
$_hashVar string The generated hashed variable name that will store the JSON encoded pluginOptions in yii\web\View::POS_HEAD. kartik\base\WidgetTrait
$_isAbove boolean Whether the $position is set to kartik\tabs\TabsX::POS_ABOVE kartik\tabs\TabsX
$_isBelow boolean Whether the $position is set to kartik\tabs\TabsX::POS_BELOW kartik\tabs\TabsX
$_isBs4 boolean Flag to detect whether bootstrap 4. kartik\base\BootstrapTrait
$_isLeft boolean Whether the $position is set to kartik\tabs\TabsX::POS_LEFT kartik\tabs\TabsX
$_isRight boolean Whether the $position is set to kartik\tabs\TabsX::POS_RIGHT kartik\tabs\TabsX
$_msgCat string Translation message file category name for i18n. kartik\base\TranslationTrait

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. yii\base\Component
__clone() This method is called after the object is created by cloning an existing one. yii\base\Component
__construct() Constructor. yii\base\BaseObject
__get() Returns the value of a component property. yii\base\Component
__isset() Checks if a property is set, i.e. defined and not null. yii\base\Component
__set() Sets the value of a component property. yii\base\Component
__unset() Sets a component property to be null. yii\base\Component
addCssClass() Adds bootstrap CSS class to options by parsing the bootstrap version for the specified Bootstrap CSS type. kartik\base\BootstrapTrait
afterRun() This method is invoked right after a widget is executed. yii\base\Widget
attachBehavior() Attaches a behavior to this component. yii\base\Component
attachBehaviors() Attaches a list of behaviors to the component. yii\base\Component
beforeRun() This method is invoked right before the widget is executed. yii\base\Widget
begin() Begins a widget. yii\base\Widget
behaviors() Returns a list of behaviors that this component should behave as. yii\base\Component
canGetProperty() Returns a value indicating whether a property can be read. yii\base\Component
canSetProperty() Returns a value indicating whether a property can be set. yii\base\Component
className() Returns the fully qualified name of this class. yii\base\BaseObject
detachBehavior() Detaches a behavior from the component. yii\base\Component
detachBehaviors() Detaches all behaviors from the component. yii\base\Component
end() Ends a widget. yii\base\Widget
ensureBehaviors() Makes sure that the behaviors declared in behaviors() are attached to this component. yii\base\Component
getBSClass() Gets the respective Bootstrap class based on currently configured bootstrap version. kartik\base\BootstrapTrait
getBaseSourcePath() Get parsed base source path based on $sourcePath setting. If $sourcePath is not set, it will return the current working directory of this widget class. kartik\base\WidgetTrait
getBehavior() Returns the named behavior object. yii\base\Component
getBehaviors() Returns all behaviors attached to this component. yii\base\Component
getBsVer() Gets the current set bootstrap version number. kartik\base\BootstrapTrait
getCssClass() Gets bootstrap css class by parsing the bootstrap version for the specified BS CSS type. kartik\base\BootstrapTrait
getDefaultBtnCss() Gets the default button CSS kartik\base\BootstrapTrait
getDefaultIconPrefix() Gets the default icon css prefix kartik\base\BootstrapTrait
getDropdownClass() Gets the respective bootstrap dropdown class name based on currently configured bootstrap version. kartik\base\BootstrapTrait
getId() Returns the ID of the widget. yii\base\Widget
getView() kartik\base\WidgetTrait
getViewPath() Returns the directory containing the view files for this widget. yii\base\Widget
hasEventHandlers() Returns a value indicating whether there is any handler attached to the named event. yii\base\Component
hasMethod() Returns a value indicating whether a method is defined. yii\base\Component
hasProperty() Returns a value indicating whether a property is defined for this component. yii\base\Component
init() Initializes the object. kartik\base\Widget
initI18N() Yii i18n messages configuration for generating translations kartik\base\TranslationTrait
initWidget() Initializes the widget settings. kartik\tabs\TabsX
isBs() Validate Bootstrap version kartik\base\BootstrapTrait
isBs4() Validate if Bootstrap 4.x version. kartik\base\BootstrapTrait
off() Detaches an existing event handler from this component. yii\base\Component
on() Attaches an event handler to an event. yii\base\Component
registerAssets() Registers the assets for kartik\tabs\TabsX widget. kartik\tabs\TabsX
registerWidgetJs() Registers a JS code block for the widget. kartik\base\WidgetTrait
removeCssClass() Removes bootstrap CSS class from options by parsing the bootstrap version for the specified Bootstrap CSS type. kartik\base\BootstrapTrait
render() Renders a view. yii\base\Widget
renderFile() Renders a view file. yii\base\Widget
run() Executes the widget. kartik\tabs\TabsX
setId() Sets the ID of the widget. yii\base\Widget
setView() Sets the view object to be used by this widget. yii\base\Widget
trigger() Triggers an event. yii\base\Component
widget() Creates a widget instance and runs it. yii\base\Widget

Protected Methods

Hide inherited methods

MethodDescriptionDefined By
activateFirstVisibleTab() Sets the first visible tab as active. kartik\tabs\TabsX
addAsset() Adds an asset to the view. kartik\base\WidgetTrait
configureBsVersion() Configures the bootstrap version settings kartik\base\BootstrapTrait
fixPjaxDuplication() Fix for weird PJAX container duplication behavior on pressing browser back and forward buttons. kartik\base\WidgetTrait
getBsExtBasename() The yii2-bootstrap extension base name. kartik\base\BootstrapTrait
getCss() Parse the CSS content to append based on condition. kartik\tabs\TabsX
getLabel() Gets the label for an item configuration. kartik\tabs\TabsX
getPluginScript() Returns the plugin registration script. kartik\base\WidgetTrait
hasActiveTab() kartik\tabs\TabsX
hashPluginOptions() Generates a hashed variable to store the pluginOptions. kartik\base\WidgetTrait
initBsVersion() Initializes bootstrap versions for the widgets and asset bundles. kartik\base\BootstrapTrait
initDestroyJs() Generates the pluginDestroyJs script if it is not set. kartik\base\WidgetTrait
isSameVersion() Compares two versions and checks if they are of the same major BS version. kartik\base\BootstrapTrait
mergeDefaultOptions() Merge default options kartik\base\WidgetTrait
parseVer() Parses and returns the major BS version kartik\base\BootstrapTrait
registerPlugin() Registers a specific plugin and the related events kartik\base\WidgetTrait
registerPluginOptions() Registers plugin options by storing within a uniquely generated javascript variable. kartik\base\WidgetTrait
renderDropdown() Normalizes dropdown item options by removing tab specific keys content and contentOptions, and also configure panes accordingly. kartik\tabs\TabsX
renderItems() Renders tab items as specified in $items. kartik\tabs\TabsX
setDataVar() Sets a HTML5 data variable. kartik\base\WidgetTrait

Events

Hide inherited events

EventTypeDescriptionDefined By
EVENT_AFTER_RUN yii\base\WidgetEvent An event raised right after executing a widget. (available since version 2.0.11) yii\base\Widget
EVENT_BEFORE_RUN yii\base\WidgetEvent An event raised right before executing a widget. (available since version 2.0.11) yii\base\Widget
EVENT_INIT yii\base\Event An event that is triggered when the widget is initialized via init(). (available since version 2.0.11) yii\base\Widget

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
ALIGN_CENTER 'center' Tab aligned to the center kartik\tabs\TabsX
ALIGN_LEFT 'left' Tab aligned to the left kartik\tabs\TabsX
ALIGN_RIGHT 'right' Tab aligned to the right kartik\tabs\TabsX
POS_ABOVE 'above' Tabs position above kartik\tabs\TabsX
POS_BELOW 'below' Tabs position below kartik\tabs\TabsX
POS_LEFT 'left' Tabs position on left kartik\tabs\TabsX
POS_RIGHT 'right' Tabs position on right kartik\tabs\TabsX

Property Details

$_isAbove protected property

Whether the $position is set to kartik\tabs\TabsX::POS_ABOVE

protected boolean $_isAbove false
$_isBelow protected property

Whether the $position is set to kartik\tabs\TabsX::POS_BELOW

protected boolean $_isBelow false
$_isLeft protected property

Whether the $position is set to kartik\tabs\TabsX::POS_LEFT

protected boolean $_isLeft false
$_isRight protected property

Whether the $position is set to kartik\tabs\TabsX::POS_RIGHT

protected boolean $_isRight false
$align public property

The alignment of the tab headers with respect to the tab content. Should be one of the TabsX::ALIGN constants.

public string $align self::ALIGN_LEFT
$bordered public property

Whether the tab content should be boxed within a bordered container.

public boolean $bordered false
$containerOptions public property

The HTML attributes for the TabsX container.

$dropdownClass public property

Name of a class to use for rendering dropdowns withing this widget. Defaults to Dropdown.

public string $dropdownClass null
$enableStickyTabs public property

Whether to enable sticky tabs plugin to maintain tabs push state on browser back and forward.

public boolean $enableStickyTabs false
$encodeLabels public property

Whether the labels for header items should be HTML-encoded.

public boolean $encodeLabels true
$fade public property

Whether to fade in each tab pane using the fade animation effect.

public boolean $fade true
$headerOptions public property

List of HTML attributes for the header container tags. This will be overwritten by the "headerOptions" set in individual $items.

See also yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.

public array $headerOptions = []
$height public property

Whether the tab body content height should be of a fixed size. You should pass one of the TabsX::SIZE constants. Applicable only when position is one of kartik\tabs\TabsX::POS_ABOVE or kartik\tabs\TabsX::POS_BELOW. Defaults to empty string (meaning dynamic height).

public string $height ''
$itemOptions public property

List of HTML attributes for the item container tags. This will be overwritten by the "options" set in individual $items. The following special options are recognized:

  • tag: string, defaults to "div", the tag name of the item container tags.

See also yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.

public array $itemOptions = []
$items public property

List of tabs in the tabs widget. Each array element represents a single tab with the following structure:

  • label: string, required, the tab header label.
  • encode: bool, optional, whether this label should be HTML-encoded. This param will override global $this->encodeLabels param.
  • headerOptions: array, optional, the HTML attributes of the tab header.
  • linkOptions: array, optional, the HTML attributes of the tab header link tags.
  • content: string, optional, the content (HTML) of the tab pane.
  • url: string, optional, an external URL. When this is specified, clicking on this tab will bring the browser to this URL. This option is available since version 2.0.4.
  • options: array, optional, the HTML attributes of the tab pane container.
  • active: bool, optional, whether this item tab header and pane should be active. If no item is marked as 'active' explicitly - the first one will be activated.
  • visible: bool, optional, whether the item tab header and pane should be visible or not. Defaults to true.
  • items: array, optional, can be used instead of content to specify a dropdown items configuration array. Each item can hold three extra keys, besides the above ones:
    • active: bool, optional, whether the item tab header and pane should be visible or not.
    • content: string, required if items is not set. The content (HTML) of the tab pane.
    • contentOptions: optional, array, the HTML attributes of the tab content container.
public array $items = []
$linkOptions public property

List of HTML attributes for the tab header link tags. This will be overwritten by the "linkOptions" set in individual $items.

See also yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.

public array $linkOptions = []
$navType public property

Specifies the Bootstrap tab styling.

public string $navType 'nav-tabs'
$position public property

The position of the tabs with respect to the tab content Should be one of the TabsX::POS constants.

public string $position self::POS_ABOVE
$printCrumbSeparator public property

The crumb separator for the dropdown headers in the print view when printHeaderCrumbs is true

public string $printCrumbSeparator ' » '
$printHeaderCrumbs public property

Whether the headers in print view will prepend the main label to the item label in case of dropdowns.

$printHeaderOptions public property

The HTML attributes for the tab content header in print view.

public array $printHeaderOptions = [
    'class' => 'h4'
]
$printable public property

Whether this tab widget should be printable.

public boolean $printable true
$renderTabContent public property

Whether to render the tab-content container and its content. You may set this property to be false so that you can manually render tab-content yourself in case your tab contents are complex.

public boolean $renderTabContent true
$sideways public property

Whether the tab header text orientation should be rotated sideways. Applicable only when position

is one of [[TabsX::POS_LEFT]] or [[TabsX::POS_RIGHT]].
public boolean $sideways false
$stickyTabsOptions public property

Sticky tabs plugin options.

$tabContentOptions public property

List of HTML attributes for the tab-content container. This will always contain the CSS class tab-content.

See also yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.

Method Details

activateFirstVisibleTab() protected method

Sets the first visible tab as active.

This method activates the first tab that is visible and not explicitly set to inactive ('active' => false).

protected void activateFirstVisibleTab ( )
getCss() protected static method

Parse the CSS content to append based on condition.

protected static string getCss ( $prop '', $condition true )
$prop string

The css property

$condition boolean

The validation to append the CSS class

return string

The parsed CSS

getLabel() protected method

Gets the label for an item configuration.

protected string getLabel ( $item = [] )
$item array

Tabs item configuration

throws yii\base\InvalidConfigException
hasActiveTab() protected method

protected boolean hasActiveTab ( )
return boolean

If there's active tab defined

initWidget() public method

Initializes the widget settings.

public void initWidget ( )
throws yii\base\InvalidConfigException
registerAssets() public method

Registers the assets for kartik\tabs\TabsX widget.

public void registerAssets ( )
renderDropdown() protected method

Normalizes dropdown item options by removing tab specific keys content and contentOptions, and also configure panes accordingly.

protected boolean renderDropdown ( $itemNumber, &$items, &$panes )
$itemNumber string

Number of the item

$items array

The dropdown items configuration.

$panes array

The panes reference array.

return boolean

Whether any of the dropdown items is active or not.

throws yii\base\InvalidConfigException
renderItems() protected method

Renders tab items as specified in $items.

protected string renderItems ( )
return string

The rendering result.

throws yii\base\InvalidConfigException
throws Exception
run() public method

Executes the widget.

public string|void run ( )
return string|void

The rendering result may be directly "echoed" or returned as a string

throws yii\base\InvalidConfigException