From 8a7fffd570c5008224896fcb1d4d4cec73f5d75c Mon Sep 17 00:00:00 2001 From: Simon Karlen Date: Tue, 13 Jul 2021 17:23:28 +0200 Subject: [PATCH] several fixes in popover widget --- src/Popover.php | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/Popover.php b/src/Popover.php index 87d29e1..afec04c 100644 --- a/src/Popover.php +++ b/src/Popover.php @@ -14,7 +14,7 @@ use yii\helpers\ArrayHelper; * The following example will show the content enclosed between the [[begin()]] * and [[end()]] calls within the modal window: * - * ~~~php + * ```php * Popover::begin([ * 'title' => 'Hello world', * 'toggleButton' => ['label' => 'click me'], @@ -23,7 +23,7 @@ use yii\helpers\ArrayHelper; * echo 'Say hello...'; * * Popover::end(); - * ~~~ + * ``` * * @see https://getbootstrap.com/docs/5.0/components/popovers/ * @author Simon Karlen @@ -100,7 +100,9 @@ class Popover extends Widget { $content = ob_get_clean(); - $this->clientOptions['content'] = $content; + if (!empty($content)) { + $this->clientOptions['content'] = $content; + } $html = $this->renderToggleButton(); $this->registerPlugin('popover'); @@ -124,14 +126,8 @@ class Popover extends Widget */ protected function renderHeader(): string { - if (isset($this->title)) { - $header = $this->title; - } else { - $header = ''; - } - Html::addCssClass($this->headerOptions, ['widget' => 'popover-header']); - return Html::tag('h3', "\n" . $header . "\n", $this->headerOptions); + return Html::tag('h3', '', $this->headerOptions); } /** @@ -141,7 +137,7 @@ class Popover extends Widget protected function renderBody(): string { Html::addCssClass($this->bodyOptions, ['widget' => 'popover-body']); - return Html::tag('div', $this->bodyOptions); + return Html::tag('div', '', $this->bodyOptions); } /** @@ -172,10 +168,11 @@ class Popover extends Widget 'role' => 'tooltip', ], $this->options, ['id' => $this->options['id'] . '-popover']); Html::addCssClass($options, ['widget' => 'popover']); - $template = Html::tag('div', $options); + $template = Html::beginTag('div', $options); $template .= $this->renderArrow(); $template .= $this->renderHeader(); $template .= $this->renderBody(); + $template .= Html::endTag('div'); $this->clientOptions = array_merge([ 'template' => $template, @@ -187,7 +184,6 @@ class Popover extends Widget if ($this->toggleButton !== false) { $this->toggleButton = array_merge([ - 'data-bs-toggle' => 'popover', 'type' => 'button', ], $this->toggleButton); }