Commit 46ca87a4 by Alexander Makarov

Fixes #2425: Tabs widget now selects first tab if no active tab is specified

parent 8f491f28
...@@ -11,6 +11,7 @@ Yii Framework 2 bootstrap extension Change Log ...@@ -11,6 +11,7 @@ Yii Framework 2 bootstrap extension Change Log
- Enh #1562: Added `yii\bootstrap\Tabs::linkOptions` (kartik-v) - Enh #1562: Added `yii\bootstrap\Tabs::linkOptions` (kartik-v)
- Enh #1601: Added support for tagName and encodeLabel parameters in ButtonDropdown (omnilight) - Enh #1601: Added support for tagName and encodeLabel parameters in ButtonDropdown (omnilight)
- Enh #1881: Improved `yii\bootstrap\NavBar` with `containerOptions`, `innerContainerOptions` and `renderInnerContainer` (creocoder) - Enh #1881: Improved `yii\bootstrap\NavBar` with `containerOptions`, `innerContainerOptions` and `renderInnerContainer` (creocoder)
- Enh #2425: Tabs widget now selects first tab if no active tab is specified (samdark)
- Chg #1459: Update Collapse to use bootstrap 3 classes (tonydspaniard) - Chg #1459: Update Collapse to use bootstrap 3 classes (tonydspaniard)
- Chg #1820: Update Progress to use bootstrap 3 markup (samdark) - Chg #1820: Update Progress to use bootstrap 3 markup (samdark)
......
...@@ -124,6 +124,11 @@ class Tabs extends Widget ...@@ -124,6 +124,11 @@ class Tabs extends Widget
{ {
$headers = []; $headers = [];
$panes = []; $panes = [];
if (!$this->hasActiveTab() && !empty($this->items)) {
$this->items[0]['active'] = true;
}
foreach ($this->items as $n => $item) { foreach ($this->items as $n => $item) {
if (!isset($item['label'])) { if (!isset($item['label'])) {
throw new InvalidConfigException("The 'label' option is required."); throw new InvalidConfigException("The 'label' option is required.");
...@@ -168,6 +173,19 @@ class Tabs extends Widget ...@@ -168,6 +173,19 @@ class Tabs extends Widget
} }
/** /**
* @return boolean if there's active tab defined
*/
protected function hasActiveTab()
{
foreach ($this->items as $item) {
if (isset($item['active']) && $item['active']===true) {
return true;
}
}
return false;
}
/**
* Normalizes dropdown item options by removing tab specific keys `content` and `contentOptions`, and also * Normalizes dropdown item options by removing tab specific keys `content` and `contentOptions`, and also
* configure `panes` accordingly. * configure `panes` accordingly.
* @param array $items the dropdown items configuration. * @param array $items the dropdown items configuration.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment