Hello,
I want to change the background color of the container only when some value is selected.
What css can I use to achieve that?
Thank you
Hi Pavel,
We suggest you use the CssClass to achieve your requirement. We have attached the sample code below.
Find the code example here:
|
<SfMultiSelect CssClass="e-color-green" DataSource="@LocalData" HideSelectedItem=false TItem="Games" TValue="string[]" @bind-Value="@BindingValue"> <MultiSelectFieldSettings Text="Text" Value="ID"></MultiSelectFieldSettings> </SfMultiSelect>
@code { private List<string> ValidationErrors { get; set; } = new(); //preselect the value private string[] BindingValue { get; set; } = new string[] { "Game1", "Game4" };
public class Games { public string ID { get; set; } public string Text { get; set; } } List<Games> LocalData = new List<Games> { new Games() { ID= "Game1", Text= "American Football" }, new Games() { ID= "Game2", Text= "Badminton" }, new Games() { ID= "Game3", Text= "Basketball" }, new Games() { ID= "Game4", Text= "Cricket" }, new Games() { ID= "Game5", Text= "Football" }, new Games() { ID= "Game6", Text= "Golf" }, new Games() { ID= "Game7", Text= "Hockey" }, new Games() { ID= "Game8", Text= "Rugby"}, new Games() { ID= "Game9", Text= "Snooker" }, new Games() { ID= "Game10", Text= "Tennis"}, }; } <style> .e-color-green .e-dropdownbase .e-list-item.e-active, .e-dropdownbase .e-list-item.e-active.e-hover { background-color: antiquewhite; color: green; }
</style> |
Find the sample in the attachment:
Note: If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.
Regards,
Sureshkumar P
Hello,
the css you provided does not satisfy the requirement. I want to get the background color of main container (not pop out) when item is selected. I have attached a screen shot with two items selected. I would like to change the css of the circled container
Hi Pavel,
Based on your shared information, we have modified the previously attached sample, in this sample we have added the CssClass property based on component value property.
Find the code example here:
|
<SfMultiSelect CssClass="@CustomClass" DataSource="@LocalData" HideSelectedItem=false TItem="Games" TValue="string[]" @bind-Value="@BindingValue">
<MultiSelectFieldSettings Text="Text" Value="ID"></MultiSelectFieldSettings>
<MultiSelectEvents TItem="Games" TValue="string[]" ValueChange="@ValueChangeHandler" Created="@CreatedHandler"></MultiSelectEvents> </SfMultiSelect>
@code {
private List<string> ValidationErrors { get; set; } = new(); //preselect the value private string[] BindingValue { get; set; } = new string[] { "Game1", "Game4" };
private string CustomClass {get;set;}
public class Games { public string ID { get; set; } public string Text { get; set; } } List<Games> LocalData = new List<Games> { new Games() { ID= "Game1", Text= "American Football" }, new Games() { ID= "Game2", Text= "Badminton" }, new Games() { ID= "Game3", Text= "Basketball" }, new Games() { ID= "Game4", Text= "Cricket" }, new Games() { ID= "Game5", Text= "Football" }, new Games() { ID= "Game6", Text= "Golf" }, new Games() { ID= "Game7", Text= "Hockey" }, new Games() { ID= "Game8", Text= "Rugby"}, new Games() { ID= "Game9", Text= "Snooker" }, new Games() { ID= "Game10", Text= "Tennis"}, };
private void ValueChangeHandler(MultiSelectChangeEventArgs<string[]> args) { // Here you can customize your code if (BindingValue != null && BindingValue.Length >0){ this.CustomClass = "e-color-green"; } else { this.CustomClass = ""; } }
private void CreatedHandler(Object args) { // Here you can customize your code if (BindingValue != null && BindingValue.Length > 0) { this.CustomClass = "e-color-green"; } else { this.CustomClass = ""; } } } <style> .e-multiselect.e-control-wrapper.e-input-group.e-color-green { background-color: antiquewhite; }
</style> |
Find the modified sample in the attachment:
Note: If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.
Regards,
Sureshkumar P
this works! I'm just surprised there isn't a class specific for selected values and we have to overwrite a generic multiselecontainer
Hi Pavel,
We suspect that you want to customize the selected chips only rather than the container element. So, we suggest you refer to our online chip-customization sample to achieve your requirement.
Find the online sample here: https://blazor.syncfusion.com/demos/multiselect-dropdown/chip-customization?theme=fluent
Note: If this post is helpful, please consider Accepting it as the solution so that other members can locate it more quickly.
Regards,
Sureshkumar P