Browse Source

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

tags/2.0.0-beta
Alexander Makarov 11 years ago
parent
commit
36c2c5acfe
  1. 1
      CHANGELOG.md
  2. 18
      Tabs.php

1
CHANGELOG.md

@ -11,6 +11,7 @@ Yii Framework 2 bootstrap extension Change Log
- Enh #1562: Added `yii\bootstrap\Tabs::linkOptions` (kartik-v)
- 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 #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 #1820: Update Progress to use bootstrap 3 markup (samdark)

18
Tabs.php

@ -124,6 +124,11 @@ class Tabs extends Widget
{
$headers = [];
$panes = [];
if (!$this->hasActiveTab() && !empty($this->items)) {
$this->items[0]['active'] = true;
}
foreach ($this->items as $n => $item) {
if (!isset($item['label'])) {
throw new InvalidConfigException("The 'label' option is required.");
@ -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
* configure `panes` accordingly.
* @param array $items the dropdown items configuration.

Loading…
Cancel
Save