yii2-bootstrap icon indicating copy to clipboard operation
yii2-bootstrap copied to clipboard

yii\bootstrap\ButtonDropdown <ul> element id should follow master id property

Open tsdogs opened this issue 6 years ago • 0 comments

What steps will reproduce the problem?

Creating a ButtonDropDown inside a page which then loads code via ajax needs the "id" property to be set to avoid conflicts:

<?= ButtonDropdown::widget([
    'label'=>'Example Dropdown',
    'id'=>'dropdown-button',
    'dropdown'=>[
        'items'=>$items,
    ],
]) ?>

To make it non conflicting you need to sepcify the id also in the 'dropdown' options like

<?= ButtonDropdown::widget([
    'label'=>'Example Dropdown',
    'id'=>'dropdown-button',
    'dropdown'=>[
        'items'=>$items,
        'options' => [ 'id' => 'dropdown-button-ul' ],
    ],
]) ?>

What's expected?

The rendered UL should assume at least a base id dependent something like:

<div class="btn-group" style="width: 15%;">
<button id="dropdown-button" class="btn btn-success dropdown-toggle"  data-toggle="dropdown" aria-expanded="false">Example Dropdown <span class="caret"></span></button>

<ul id="dropdown-button-w0" class="dropdown-menu-right dropdown-menu"><li><a href="#1" tabindex="-1">Option 1</a></li>
<li><a href="#2" tabindex="-1">Option 2</a></li>
</ul>
</div>

What do you get instead?

<div class="btn-group" style="width: 15%;">
<button id="dropdown-button" class="btn btn-success dropdown-toggle"  data-toggle="dropdown" aria-expanded="false">Example Dropdown <span class="caret"></span></button>

<ul id="w0" class="dropdown-menu-right dropdown-menu"><li><a href="#1" tabindex="-1">Option 1</a></li>
<li><a href="#2" tabindex="-1">Option 2</a></li>
</ul>
</div>

Additional info

It works correctly if there is no ajax loading with javascript attached to widgets. Beside the fact that id's in sub widgets should follow the master widget schema imho, maybe there should be a better default to handle ajax requests which generate a more unique id if not explicitly specified.

tsdogs avatar Apr 04 '18 13:04 tsdogs