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.
|
* @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.
|
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered.
|
||||||
*/
|
*/
|
||||||
public $titleOptions = [];
|
public $titleOptions = [];
|
||||||
@ -142,8 +147,9 @@ class Offcanvas extends Widget
|
|||||||
{
|
{
|
||||||
$button = $this->renderCloseButton();
|
$button = $this->renderCloseButton();
|
||||||
if (isset($this->title)) {
|
if (isset($this->title)) {
|
||||||
|
$tag = ArrayHelper::remove($this->titleOptions, 'tag', 'h5');
|
||||||
Html::addCssClass($this->titleOptions, ['widget' => 'offcanvas-title']);
|
Html::addCssClass($this->titleOptions, ['widget' => 'offcanvas-title']);
|
||||||
$header = Html::tag('h5', $this->title, $this->titleOptions);
|
$header = Html::tag($tag, $this->title, $this->titleOptions);
|
||||||
} else {
|
} else {
|
||||||
$header = '';
|
$header = '';
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
namespace yiiunit\extensions\bootstrap5;
|
namespace yiiunit\extensions\bootstrap5;
|
||||||
|
|
||||||
use yii\bootstrap5\Html;
|
|
||||||
use yii\bootstrap5\Modal;
|
|
||||||
use yii\bootstrap5\Offcanvas;
|
use yii\bootstrap5\Offcanvas;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -42,6 +40,13 @@ HTML;
|
|||||||
ob_start();
|
ob_start();
|
||||||
Offcanvas::begin([
|
Offcanvas::begin([
|
||||||
'title' => 'Offcanvas title',
|
'title' => 'Offcanvas title',
|
||||||
|
'headerOptions' => [
|
||||||
|
'data-test' => 'Test'
|
||||||
|
],
|
||||||
|
'titleOptions' => [
|
||||||
|
'tag' => 'h2'
|
||||||
|
],
|
||||||
|
'placement' => Offcanvas::PLACEMENT_END,
|
||||||
'backdrop' => false,
|
'backdrop' => false,
|
||||||
'scrolling' => true,
|
'scrolling' => true,
|
||||||
'closeButton' => false
|
'closeButton' => false
|
||||||
@ -52,9 +57,9 @@ HTML;
|
|||||||
|
|
||||||
$expected = <<<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 id="w0" class="offcanvas offcanvas-end" tabindex="-1" data-bs-backdrop="false" data-bs-scroll="true" aria-labelledby="w0-label">
|
||||||
<div class="offcanvas-header">
|
<div class="offcanvas-header" data-test="Test">
|
||||||
<h5 id="w0-label" class="offcanvas-title">Offcanvas title</h5>
|
<h2 id="w0-label" class="offcanvas-title">Offcanvas title</h2>
|
||||||
</div>
|
</div>
|
||||||
<div class="offcanvas-body">
|
<div class="offcanvas-body">
|
||||||
<p>Woohoo, you're reading this text in an offcanvas!</p>
|
<p>Woohoo, you're reading this text in an offcanvas!</p>
|
||||||
|
Loading…
Reference in New Issue
Block a user