From 36c2c5acfeac9b59b7984209b8d2659c46c5f52e Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Fri, 21 Feb 2014 00:37:36 +0400 Subject: [PATCH] Fixes #2425: Tabs widget now selects first tab if no active tab is specified --- CHANGELOG.md | 1 + Tabs.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7eef113..5fced15 100644 --- a/CHANGELOG.md +++ b/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) diff --git a/Tabs.php b/Tabs.php index a001edd..2192746 100644 --- a/Tabs.php +++ b/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.