diff --git a/src/Offcanvas.php b/src/Offcanvas.php index 443c295..d3ebece 100644 --- a/src/Offcanvas.php +++ b/src/Offcanvas.php @@ -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 = ''; } diff --git a/tests/OffcanvasTest.php b/tests/OffcanvasTest.php index 8af4c30..c32a4c6 100644 --- a/tests/OffcanvasTest.php +++ b/tests/OffcanvasTest.php @@ -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 = << -
-
Offcanvas title
+
+
+

Offcanvas title

Woohoo, you're reading this text in an offcanvas!