Browse Source

Fixed `yii\bootstrap\ToggleButtonGroup` toggles dropdown for both buttons in case `split` is enabled

tags/2.0.8
Klimov Paul 7 years ago
parent
commit
3ed9dcbd3d
  1. 17
      ButtonDropdown.php
  2. 1
      CHANGELOG.md

17
ButtonDropdown.php

@ -8,6 +8,7 @@
namespace yii\bootstrap; namespace yii\bootstrap;
use yii\helpers\ArrayHelper; use yii\helpers\ArrayHelper;
use yii\helpers\Url;
/** /**
* ButtonDropdown renders a group or split button dropdown bootstrap component. * ButtonDropdown renders a group or split button dropdown bootstrap component.
@ -104,11 +105,12 @@ class ButtonDropdown extends Widget
if ($this->encodeLabel) { if ($this->encodeLabel) {
$label = Html::encode($label); $label = Html::encode($label);
} }
if ($this->split) { if ($this->split) {
$options = $this->options; $options = $this->options;
$this->options['data-toggle'] = 'dropdown'; $this->options['data-toggle'] = 'dropdown';
Html::addCssClass($this->options, ['toggle' => 'dropdown-toggle']); Html::addCssClass($this->options, ['toggle' => 'dropdown-toggle']);
unset($this->options['id']); unset($options['id']);
$splitButton = Button::widget([ $splitButton = Button::widget([
'label' => '<span class="caret"></span>', 'label' => '<span class="caret"></span>',
'encodeLabel' => false, 'encodeLabel' => false,
@ -118,14 +120,21 @@ class ButtonDropdown extends Widget
} else { } else {
$label .= ' <span class="caret"></span>'; $label .= ' <span class="caret"></span>';
$options = $this->options; $options = $this->options;
if (!isset($options['href']) && $this->tagName === 'a') {
$options['href'] = '#';
}
Html::addCssClass($options, ['toggle' => 'dropdown-toggle']); Html::addCssClass($options, ['toggle' => 'dropdown-toggle']);
$options['data-toggle'] = 'dropdown'; $options['data-toggle'] = 'dropdown';
$splitButton = ''; $splitButton = '';
} }
if (isset($options['href'])) {
if (is_array($options['href'])) {
$options['href'] = Url::to($options['href']);
}
} else {
if ($this->tagName === 'a') {
$options['href'] = '#';
}
}
return Button::widget([ return Button::widget([
'tagName' => $this->tagName, 'tagName' => $this->tagName,
'label' => $label, 'label' => $label,

1
CHANGELOG.md

@ -4,6 +4,7 @@ Yii Framework 2 bootstrap extension Change Log
2.0.8 under development 2.0.8 under development
----------------------- -----------------------
- Bug #126: Fixed `yii\bootstrap\ToggleButtonGroup` toggles dropdown for both buttons in case `split` is enabled (klimov-paul)
- Enh #219: Add ability to use custom HTML in navbar-header (razvanphp) - Enh #219: Add ability to use custom HTML in navbar-header (razvanphp)
- Enh #171: Add ability to use a brandImage with the navbar (razvanphp) - Enh #171: Add ability to use a brandImage with the navbar (razvanphp)

Loading…
Cancel
Save