yiisoft / yii2-bootstrap4

Yii 2 Bootstrap 4 Extension
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
216 stars 106 forks source link

Do not hardcode container CSS class #161

Closed lubosdz closed 5 years ago

lubosdz commented 5 years ago

What steps will reproduce the problem?

Custom templates for breadcrumbs may use different container class, than currently hard-coded breadcrumb.

What's expected?

Make CSS class name configurable - extract as a public property.

What do you get instead?

Mixed up default BS4 classes & custom template classes. Additional Html::removeCssClass(options, 'breadcrumbs') must be called to fix the isssue.

Q A
Yii version 2.0.22
PHP version 7.0.33
Operating system Win/CentOS

Issue #160 .

simialbi commented 5 years ago

It's not necessary. You can override this class with:

Breadcrumb::widget([
    'options' => [
        'class' => ['widget' => 'my-breadcrumb-class']
    ]
])

See https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseHtml.php#L1990

lubosdz commented 5 years ago

Yes, it works as you suggested, thank you. So I must use following:

public $options = [
    'class' => [
        'widget' => '', // remove default *breadcrumb* class
        'u-list-inline g-color-gray-dark-v6', // add any custom CSS
    ],
];

I am wondering if it was necessary to implement it in such a complicated way. It takes time to find out which class will be injected via which attribute. Separate attribute for container CSS would be more developer-friendly. Also if the widget is empty, it should skip injecting empty value - has no effect.

samdark commented 5 years ago

Closing since @simialbi explained how to achieve it.