6

How can we set class with mSetting?

For example:

new sap.m.Button({}).addStyleClass("my-class"); //work

Another way?

new sap.m.Button({
  styleClass: "my-class" // did'n work
});

Any possibility to set class that way?

Ivan
  • 98
  • 1
  • 1
  • 7
  • 2
    For JavaScript Views `.addStyleClass()` is the only built-in way to attach a style class. In XML Views you can simply write `` – Tim Gerlach Apr 08 '15 at 12:13
  • 3
    styleClass is not a property hence there is no way to set it via the settings object. But you are totally right, it SHOULD work this way (and thereby also allow binding)! – cschuff Apr 09 '15 at 12:56
  • For other readers who still consider using JS Views: please use [typed views](https://openui5.hana.ondemand.com/topic/e6bb33d076dc4f23be50c082c271b9f0) instead. `sap.ui.core.mvc.JSView` and `sap.ui.jsview` are deprecated. – Boghyon Hoffmann Apr 22 '21 at 22:31
  • Some control renderers provide hook methods which can be overwritten to add some HTML attributes in the custom control. Here is an example with `sap.m.Input`: https://stackoverflow.com/a/67919830/5846045 (added `styleClass`). The same could be applied to extended Buttons as the base [Button renderer provides `renderButtonAttributes` hook](https://github.com/SAP/openui5/blob/fd75f5f8f0d99b21ce02fe6df618f46c8d157f44/src/sap.m/src/sap/m/ButtonRenderer.js#L164-L167). – Boghyon Hoffmann Jul 17 '21 at 20:32

1 Answers1

8

As of now (till version SAPUI5 1.28.4), styleClass is not a supported property of sap.m.Button nor its base type's( sap.ui.core.Control) property. Hence you have to use addStyleClass(sStyleClass) OR in XML view directly.

As @Ivan said, you can use busy property because this exists in the base type sap.ui.core.Control

Hopefully we will this basic functionality in higher releases.

Update: for multiple CSS classes

var oLabel =  new sap.m.Label({text:"Sample"}).addStyleClass("sample1 sample2");

OR

var oLabel =  new sap.m.Label({text:"Sample"}).addStyleClass("sample1").addStyleClass("sample2");
Sunil B N
  • 4,159
  • 1
  • 31
  • 52