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

This commit is contained in:
octicon-git-branch(16/)
octicon-tag(16/)
Alexander Makarov
2014-02-21 00:37:36 +04:00
gitea-unlock(16/)
parent 8f491f2836
commit 46ca87a41a
octicon-diff(16/tw-mr-1) 2 changed files with 19 additions and 0 deletions

1
extensions/bootstrap/CHANGELOG.md
View File

@@ -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
extensions/bootstrap/Tabs.php
View File

@@ -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.");
@@ -167,6 +172,19 @@ class Tabs extends Widget
. Html::tag('div', implode("\n", $panes), ['class' => 'tab-content']);
}
/**
* @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.