yiisoft / yii2-bootstrap4

Yii 2 Bootstrap 4 Extension
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
216 stars 106 forks source link

First tab in `Tabs` is active even if URL activates another #192

Open alex-code opened 4 years ago

alex-code commented 4 years ago
Tabs::widget([
  'renderTabContent' => false,
  'items' => [
    [
      'label' => 'Tab 1',
      'url' => ['/default/index'],
    ],
    [
      'label' => 'Tab 2',
      'url' => ['/default/page2'],
    ],
   ]
]);

The Tabs widget uses the Nav widget to build the tabs which causes a conflict with activating.

If the route matches the url for Tab 2 Nav will activate it but Tab 1 has already been activated by Tabs.

I was thinking of either adding an option to turn off Tabs::activateFirstVisibleTab() or if the items have urls then defer activation to Nav.

Q A
Yii vesion 2.0.35
Yii BS4 version 2.0.8
alex-code commented 4 years ago

@samdark I can do a PR for this but wondering which way is preferable?

An option to disable the Tabs::activateFirstVisibleTab method or if the items use url's then let Nav do the activation?

simialbi commented 4 years ago

In my opinion there should be an active option in items array, if there is none (in none of the items), the first will be activated, otherwhise the one activated.

alex-code commented 4 years ago

@simialbi This is the way it works currently but if you try to activate a tab using the route you get multiple tabs activated.

samdark commented 4 years ago

If there's explicit active we should not check for route, I think.