Sidebar css change with theme change

I have used the documentation for theme: https://blazor.syncfusion.com/documentation/appearance/themes and this solution for implementing dark theme using a separate dark theme css: https://www.syncfusion.com/forums/171882/problems-with-implementing-dark-themes.

But I am facing an issue where my custom css for sidebar in mainlayout is not getting overwritten by the one in dark theme css. Is there a way to change my custom css with the dark theme one for the sidebar?


4 Replies 1 reply marked as answer

NI Nick March 11, 2022 03:05 AM UTC

I have attached a sample showing what I am describing. I would also like to know how I can modify the text of sidebar menus in my case.


Attachment: BlazorAppTest_eb5dced5.zip


KR Keerthana Rajendran Syncfusion Team March 11, 2022 10:36 AM UTC

Hi Nick,  
 
Thanks for contacting Syncfusion support. 
 
In the attached sample, the background is set for direct Sidebar class (“e-sidebar”) which overrides the theme styles applied on dark theme change.  
 
The dark theme changes are applied in the sample if the below line is commented.  
 
    .e-sidebar { 
        top: 50px !important; /*To make the sidebar sit flush with the header*/ 
        margin-top: 5px; 
        position: fixed; 
       /* background: linear-gradient(to right, #a4d8e3, #d5edfa);*/ 
        color: white; 
        box-shadow: 2px 3px 5px rgba(0, 0, 0, 0.4); 
    } 
 
 
You can edit the text of TreeView(within Sidebar) by setting allowEditing property as true.  
 
Refer to the following UG links for more details on this scenario. 
 
 
 
Regards, 
Keerthana R. 



NI Nick March 11, 2022 06:50 PM UTC

I would like to assign my own css background for the sidebar background and css color for the treeview text in both light and dark themes. How would I do this?



KR Keerthana Rajendran Syncfusion Team March 14, 2022 12:59 PM UTC

Hi Nick, 
 
You can set different class names using HtmlAttributes of Sidebar and cssClass property of TreeView based on theme value through OnInitializedAsync and apply required styles based on these class names. 
 
Refer to the following code. 
 
protected async override Task OnInitializedAsync() 
    { 
        userName = "Test User"; 
        var theme = GetThemeName(); 
        if(theme.Contains("dark")) 
        { 
            cssClass = "dark-treeview"; /*set class name for TreeView in dark theme */ 
            HtmlAttribute= new Dictionary<string, object>(){{"class", "dark-sidebar" }}; /*set class name for Sidebar in dark theme */ 
        } 
        else 
        { 
            cssClass = "main-treeview"; 
            HtmlAttribute = new Dictionary<string, object>() { { "class", "sidebar-treeview" } }; 
        } 
        themeName = theme.Contains("bootstrap5") ? "bootstrap5" : theme; 
    } 
 
<style> 
    .sidebar-treeview{ 
        background:#7db1e4; /*background for light Sidebar*/ 
    } 
    .dark-sidebar{ 
      background:#1e2731; /*background for dark Sidebar*/ 
    } 
    .dark-treeview.e-treeview .e-list-item.e-active>.e-text-content .e-list-text 
    { 
       color:#097eed; /*color for dark TreeView active text*/ 
    }     
</style> 
 
 
We have modified the sample and attached in the following link. 
 
 
Similar to this way, you can apply your own styles for Sidebar and TreeView components. 
 
API links: 
 
 
 
Please let us know if you need any further assistance. 
 
Regards, 
Keerthana R. 


Marked as answer
Loader.
Up arrow icon