yii2-bootstrap4 icon indicating copy to clipboard operation
yii2-bootstrap4 copied to clipboard

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

Open alex-code opened this issue 5 years ago • 4 comments

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 avatar May 12 '20 10:05 alex-code

@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?

alex-code avatar May 17 '20 12:05 alex-code

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.

simialbi avatar May 17 '20 13:05 simialbi

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

alex-code avatar May 17 '20 14:05 alex-code

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

samdark avatar May 17 '20 20:05 samdark