allow override of title tag, added some more options to tests
This commit is contained in:
parent
5fbad0fa2f
commit
6ba5b34c2c
@ -97,6 +97,11 @@ class Offcanvas extends Widget
|
||||
|
||||
/**
|
||||
* @var array Additional title options.
|
||||
*
|
||||
* The following special options are supported:
|
||||
*
|
||||
* - tag: string, the tag name of the button. Defaults to 'h5'.
|
||||
*
|
||||
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
|
||||
*/
|
||||
public $titleOptions = [];
|
||||
@ -142,8 +147,9 @@ class Offcanvas extends Widget
|
||||
{
|
||||
$button = $this->renderCloseButton();
|
||||
if (isset($this->title)) {
|
||||
$tag = ArrayHelper::remove($this->titleOptions, 'tag', 'h5');
|
||||
Html::addCssClass($this->titleOptions, ['widget' => 'offcanvas-title']);
|
||||
$header = Html::tag('h5', $this->title, $this->titleOptions);
|
||||
$header = Html::tag($tag, $this->title, $this->titleOptions);
|
||||
} else {
|
||||
$header = '';
|
||||
}
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
namespace yiiunit\extensions\bootstrap5;
|
||||
|
||||
use yii\bootstrap5\Html;
|
||||
use yii\bootstrap5\Modal;
|
||||
use yii\bootstrap5\Offcanvas;
|
||||
|
||||
/**
|
||||
@ -42,6 +40,13 @@ HTML;
|
||||
ob_start();
|
||||
Offcanvas::begin([
|
||||
'title' => 'Offcanvas title',
|
||||
'headerOptions' => [
|
||||
'data-test' => 'Test'
|
||||
],
|
||||
'titleOptions' => [
|
||||
'tag' => 'h2'
|
||||
],
|
||||
'placement' => Offcanvas::PLACEMENT_END,
|
||||
'backdrop' => false,
|
||||
'scrolling' => true,
|
||||
'closeButton' => false
|
||||
@ -52,9 +57,9 @@ HTML;
|
||||
|
||||
$expected = <<<HTML
|
||||
|
||||
<div id="w0" class="offcanvas offcanvas-start" tabindex="-1" data-bs-backdrop="false" data-bs-scroll="true" aria-labelledby="w0-label">
|
||||
<div class="offcanvas-header">
|
||||
<h5 id="w0-label" class="offcanvas-title">Offcanvas title</h5>
|
||||
<div id="w0" class="offcanvas offcanvas-end" tabindex="-1" data-bs-backdrop="false" data-bs-scroll="true" aria-labelledby="w0-label">
|
||||
<div class="offcanvas-header" data-test="Test">
|
||||
<h2 id="w0-label" class="offcanvas-title">Offcanvas title</h2>
|
||||
</div>
|
||||
<div class="offcanvas-body">
|
||||
<p>Woohoo, you're reading this text in an offcanvas!</p>
|
||||
|
Loading…
Reference in New Issue
Block a user