Browse Source

Fixes #107: Added `yii\bootstrap\Collapse::$autoCloseItems` to allow keeping multiple items open at the same time

tags/2.0.7
Carsten Brandt 8 years ago committed by Alexander Makarov
parent
commit
6a4f64aa11
  1. 2
      CHANGELOG.md
  2. 19
      Collapse.php
  3. 24
      tests/CollapseTest.php

2
CHANGELOG.md

@ -4,6 +4,8 @@ Yii Framework 2 bootstrap extension Change Log
2.0.7 under development 2.0.7 under development
----------------------- -----------------------
- Enh #107: Added `yii\bootstrap\Collapse::$autoCloseItems` to allow keeping multiple items open at the same time (cebe)
- Enh #131: Added `tabContentOptions` to set HTML attributes for 'tab-content' container in `Tabs` widget (AndrewKorpusov)
- Bug #157: Active status of multilevel submenu items of the `yii\bootstrap\Nav` class is determined correctly now (PowerGamer1) - Bug #157: Active status of multilevel submenu items of the `yii\bootstrap\Nav` class is determined correctly now (PowerGamer1)
- Enh #64: Added simplified syntax for specifying `Collapse` widget `$items` (Faryshta, cebe) - Enh #64: Added simplified syntax for specifying `Collapse` widget `$items` (Faryshta, cebe)
- Enh #131 Added `tabContentOptions` to set HTML attributes for 'tab-content' container in `Tabs` widget (AndrewKorpusov) - Enh #131 Added `tabContentOptions` to set HTML attributes for 'tab-content' container in `Tabs` widget (AndrewKorpusov)

19
Collapse.php

@ -90,6 +90,12 @@ class Collapse extends Widget
* @var boolean whether the labels for header items should be HTML-encoded. * @var boolean whether the labels for header items should be HTML-encoded.
*/ */
public $encodeLabels = true; public $encodeLabels = true;
/**
* @var boolean whether to close other items if an item is opened. Defaults to `true` which causes an
* accordion effect. Set this to `false` to allow keeping multiple items open at once.
* @since 2.0.7
*/
public $autoCloseItems = true;
/** /**
@ -164,11 +170,14 @@ class Collapse extends Widget
$header = Html::encode($header); $header = Html::encode($header);
} }
$headerToggle = Html::a($header, '#' . $id, [ $headerOptions = [
'class' => 'collapse-toggle', 'class' => 'collapse-toggle',
'data-toggle' => 'collapse', 'data-toggle' => 'collapse',
'data-parent' => '#' . $this->options['id'] ];
]) . "\n"; if ($this->autoCloseItems) {
$headerOptions['data-parent'] = '#' . $this->options['id'];
}
$headerToggle = Html::a($header, '#' . $id, $headerOptions) . "\n";
$header = Html::tag('h4', $headerToggle, ['class' => 'panel-title']); $header = Html::tag('h4', $headerToggle, ['class' => 'panel-title']);

24
tests/CollapseTest.php

@ -214,4 +214,28 @@ HTML
HTML HTML
, $output); , $output);
} }
public function testAutoCloseItems()
{
$items = [
[
'label' => 'Item 1',
'content' => 'Content 1',
],
[
'label' => 'Item 2',
'content' => 'Content 2',
],
];
$output = Collapse::widget([
'items' => $items
]);
$this->assertContains('data-parent="', $output);
$output = Collapse::widget([
'autoCloseItems' => false,
'items' => $items
]);
$this->assertNotContains('data-parent="', $output);
}
} }

Loading…
Cancel
Save