SitecoreAI - Styles land on the outer host of your component

I was working on a component library integration in a SitecoreAI head app - Angular, Content SDK - and ran into something that cost me more time than it should have. An author picks a Style in Pages, saves, refreshes... and nothing happens on the front-end. The class is there in the DOM, but the component looks exactly the same.
Lets break this down.
What actually happens with Styles
When an author selects a Style in the Design > Styling panel in Pages, that selection comes down in the layout service response as a rendering parameter. In your front-end it arrives as params.Styles - a plain, space-separated string of CSS class names.
The starter kit (and most SXA-based setups) then take that string and slap it on the outer wrapper of the component. In an Angular Content SDK app that is typically done in a shared base component with something like a rootClass() helper on the SXA component:
<div class="component my-component {{ params.Styles }}">
<!-- your component content -->
</div>
So far so good. The class lands on the outer host of your component.
Where it goes wrong
Here is the thing. If you are using a design-system component library, those components usually render their own inner host element and paint their own background, spacing and colours from their own configuration.
In my case the library component took a backgroundColor value out of its own config - a SelectListItem - and turned it into something like a u-bg-<Key> class on its inner host.
Two different hosts. Two different sources of truth.
Simplified, the DOM looks like this:
<my-component class="component u-bg-Blue"> <-- Sitecore Styles land here
<ds-content-block class="u-bg-White"> <-- the design system paints here
...
</ds-content-block>
</my-component>
The Sitecore class is present. It is just sitting on an element that never had a background to begin with, and the element that does paint the background never hears about it.
So: making a Style appear in Pages is not the same as making it render. The front-end has to bridge the two. Either you map the incoming class to the library's own config value, or you make sure your CSS actually targets the inner element from the outer host.
Nothing is broken here, it is just two systems doing their own thing. But you have to be aware of it.
If you need something more granular: use Rendering Parameters
Styles are great for the broad strokes - "make this section grey", "remove the margins". They are a flat list of CSS classes on the outer element and that is all they will ever be.
The moment you need to style or configure something inside your component - a specific heading, a button variant, the shape of a banner, the background of one inner block - Styles are the wrong tool. That is what Rendering Parameters are for.
What they are
Rendering parameters are extra properties on the rendering itself, separate from the datasource. Same component, same content, different presentation. They are defined on a parameters template that you link to your rendering.
Setting them up
- Create a parameters template, for example under
/sitecore/templates/Project/<YourSite>/Rendering Parameters/. - Inherit from the base templates you need.
Base Rendering Parametersbrings in the usual suspects:- IStyling - adds the Styles field and the styling button on the edit frame.
- IComponentVariant - adds the variant dropdown.
- Grid Parameters - adds the grid field.
- IRenderingID - lets an author set an HTML id.
- Add your own fields on top. A droplist for
shape, a droptree pointing to a list of colours, a checkbox to flip a layout - whatever your component needs. - On your rendering, under Editor Options, set the Parameters Template field to your new template.
Reading them in the front-end
All parameters arrive in the same params object as key/value pairs:
type MyComponentProps = {
params: { [key: string]: string };
fields: Fields;
};
Which means params.Styles is your outer wrapper class string, and params.shape or params.backgroundColor is yours to do whatever you want with - including handing it straight to your design-system component as its own config value.
That is the granularity you don't get from Styles.
Bonus: data-class-change and the component class
Two small things from the Build your first component page that are related, and that I mixed up myself at first. Whatever your front-end framework is, in the end it is just markup.
If your component has styles that authors can configure in the right-hand panel, you can put the data-class-change attribute on the HTML element those classes belong on. When the author changes something in the styling menu, Pages reflects it on that element in the preview canvas, without reloading the page. Rendered, it looks like this:
<!-- root element: grid parameters + styles, and the component class -->
<div class="container-default component col-12 my-style">
<!-- the element the styles belong on -->
<div data-class-change class="my-style">
...
</div>
</div>
Note that this is a Pages canvas concern. It makes the author experience correct, it does not change what your component renders in production. So it is not a fix for the outer/inner host mismatch above - you still need the front-end to do that bridging.
Second: make sure the root element of your component keeps the component class. That is how the Pages editor locates your component in the canvas and applies styling changes in real time. Drop it, and style changes from the right-hand panel only show up after a full page refresh - which is exactly the kind of thing that makes an author think the feature is broken.
Choose what suits your project the best. But at least now you know why that Style you added is sitting quietly in the DOM doing absolutely nothing :-)
Styles come down as CSS classes on the outer host of your component. If you need to reach inside, use Rendering Parameters instead.
Koen Heye