octicon-rss(16/)
You've already forked yii2
mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-10 02:13:17 +08:00
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/)
octicon-diff(16/tw-mr-1) 2 changed files with 19 additions and 0 deletions
@@ -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)
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user