Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collapse: Added item option to define custom options for list of items #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Collapse.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class Collapse extends Widget
* - content: array|string|object, required, the content (HTML) of the group
* - options: array, optional, the HTML attributes of the group
* - contentOptions: optional, the HTML attributes of the group's content
* - contentListOptions: optional, options merged with default and passed to `Html::ul` when content is array
*/
public $items = [];

Expand Down Expand Up @@ -148,13 +149,14 @@ public function renderItem($header, $item, $index)
if (is_string($item['content']) || is_object($item['content'])) {
$content = Html::tag('div', $item['content'], ['class' => 'panel-body']) . "\n";
} elseif (is_array($item['content'])) {
$content = Html::ul($item['content'], [
$contentListOptions = ArrayHelper::merge([
'class' => 'list-group',
'itemOptions' => [
'class' => 'list-group-item'
],
'encode' => false,
]) . "\n";
], ArrayHelper::getValue($item, 'contentListOptions', []));
$content = Html::ul($item['content'], $contentListOptions) . "\n";
if (isset($item['footer'])) {
$content .= Html::tag('div', $item['footer'], ['class' => 'panel-footer']) . "\n";
}
Expand Down
18 changes: 18 additions & 0 deletions tests/CollapseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ public function testRender()
'encode' => true,
'footer' => 'Footer3'
],
[
'label' => '<h1>Collapsible Group Item #5</h1>',
'content' => [
'<h2>test content1</h2>',
'<h2>test content2</h2>'
],
'contentListOptions' => [
'class' => 'list-group list-group-custom',
'encode' => true,
],
],
]
]);

Expand Down Expand Up @@ -103,6 +114,13 @@ public function testRender()
</ul>
<div class="panel-footer">Footer3</div>
</div></div>
<div class="panel panel-default"><div class="panel-heading"><h4 class="panel-title"><a class="collapse-toggle" href="#w0-collapse5" data-toggle="collapse" data-parent="#w0">&lt;h1&gt;Collapsible Group Item #5&lt;/h1&gt;</a>
</h4></div>
<div id="w0-collapse5" class="panel-collapse collapse"><ul class="list-group list-group-custom">
<li class="list-group-item">&lt;h2&gt;test content1&lt;/h2&gt;</li>
<li class="list-group-item">&lt;h2&gt;test content2&lt;/h2&gt;</li>
</ul>
</div></div>
</div>

HTML
Expand Down