I have an accordion implemented in lightning data table, and I want to change the style (background color) of the accordion Summary whenever the section is opened.
I didn't know how to implement a CSS for the opened section.
I tried the (Styling Hooks) below but it didn't work:
.THIS .slds-is-open > .slds-accordion__summary-heading {
background-color: var(--sds-c-accordion-summary-color-background, red);
}
Best Answer
That's now how that works. You should specify the selector to use, and the hook you wish to modify. Normally, this will be something like:
The documentation explains how it works in the background, using the CSS var() function, but the part you need to focus on is setting the value.
To get this to work, you have to set a property you have access to. After some experimentation, I came up with the following code:
We use the sectiontoggle event to determine what's open, then attach a custom data element to the section. We can use this attribute to trigger the custom CSS.