ui5-webcomponents icon indicating copy to clipboard operation
ui5-webcomponents copied to clipboard

addCustomCSS changes the style for all instances of the element

Open akshaykmr080 opened this issue 7 years ago • 3 comments

I am looking for a way to change the CSS properties of 'ui5-button'. I am using the ui5-button component in 2 locations in my React App. I want to change different CSS properties for each occurrence of the ui5-button.

Currently when i say

addCustomCSS('ui5-button', 'sap_belize_hcb', .sapMBtn { background-color: var(--sapAccentColor4) !important})

it changes the background-color of all the ui5-buttons on the page. Is there a way to change the style for a specific instance of the button ?

akshaykmr080 avatar May 20 '19 18:05 akshaykmr080

Hello @akshaykmr080

In general, if you add a class to the ui5-button you want to change, you can alter the CSS variable, that defines its background colour, then only that button would change.

https://codesandbox.io/s/0on8215xnl?fontsize=14&module=%2Findex.html

.special {
     --sapUiButtonBackground: red;
  }
<ui5-button class=“special”>press me</ui5-button> // would be changed
<ui5-button>press me</ui5-button> // would not be changed

Written this way, would mean the CSS Variable "--sapUiButtonBackground" would be "red" in all themes. Do you need to change the background for this particular button only in HCB?

ilhan007 avatar May 20 '19 19:05 ilhan007

And a question from my side - do you need IE 11 support :D

MapTo0 avatar May 20 '19 20:05 MapTo0

Thanks a lot for resolving the issue. Yes, i do need IE 11 support

akshaykmr080 avatar May 21 '19 23:05 akshaykmr080