Class SfChip
The SfChip component displays a list of chip each of which contains a block of essential information that triggers an event on click action.
Inherited Members
Namespace: Syncfusion.Blazor.Buttons
Assembly: Syncfusion.Blazor.dll
Syntax
public class SfChip : SfBaseComponent
Constructors
SfChip()
Declaration
public SfChip()
Properties
ChildContent
Specifies the ChildContent.
Declaration
public RenderFragment ChildContent { get; set; }
Property Value
| Type |
|---|
| Microsoft.AspNetCore.Components.RenderFragment |
Chips
This chips property helps to render chipitem component.
Declaration
public List<ChipItem> Chips { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Collections.Generic.List<ChipItem> | Accepts the list of chip items. Each chip item should contain a text value. |
CssClass
Gets or sets the custom CSS classes for the chip element, allowing customization of the chip component's appearance.
Declaration
public string CssClass { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String | A string containing CSS class names separated by spaces. The default value is an empty string. |
Remarks
Use this property to apply one or more CSS classes, separated by spaces, to modify the look and feel of the chip component.
Enabled
Gets or sets a boolean value to enable or disable the chipitem component.
Declaration
public bool Enabled { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
|
EnableDelete
Gets or sets a boolean value to enable delete functionality.
Declaration
public bool EnableDelete { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
|
EnableRtl
Gets or sets a value to enable or disable the component rendering in right to left direction.
Declaration
public bool EnableRtl { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
|
HtmlAttributes
Gets or sets the additional html attributes such as title, native events etc., to the wrapper element.
Declaration
public Dictionary<string, object> HtmlAttributes { get; set; }
Property Value
| Type |
|---|
| System.Collections.Generic.Dictionary<System.String, System.Object> |
Remarks
Additional attributes can be added by specifying as inline attributes or by specifying @attributes directive.
SelectedChips
Gets or sets the selected chip items text.
Declaration
public string[] SelectedChips { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String[] | Accepts the array of string (chip's text) to select items in chips. The default value is an empty array. |
Remarks
Use this property to specify or retrieve the text of the chip items currently selected.
SelectedChipsChanged
Gets or sets the event callback to trigger when the selected chips changes.
Declaration
public EventCallback<string[]> SelectedChipsChanged { get; set; }
Property Value
| Type | Description |
|---|---|
| Microsoft.AspNetCore.Components.EventCallback<System.String[]> | An event callback function. |
Remarks
You can get the updated SelectedChips value.
Examples
In the below code example, the SelectedChips value can be obtained from the SelectedChipsChanged event.
<SfChip Selection="SelectionType.Multiple" SelectedChipsChanged="SelectedChipsChanged">
<ChipItems>
<ChipItem Text = "Small"></ChipItem>
<ChipItem Text = "Medium"></ChipItem>
<ChipItem Text = "Large"></ChipItem>
<ChipItem Text = "Extra Large"></ChipItem>
</ChipItems>
</SfChip>
@code {
private void SelectedChipsChanged(string[] args) {
string[] selectedChipItem = args;
}
}
Selection
Gets or sets the chip selection type.
Declaration
public SelectionType Selection { get; set; }
Property Value
| Type | Description |
|---|---|
| SelectionType | One of the SelectionType enumeration that specifies the selection of chip items in selection mode. The default value is None. |
Methods
AddChip(ChipItem)
A function that adds the chip items based on given input.
Declaration
public void AddChip(ChipItem item)
Parameters
| Type | Name | Description |
|---|---|---|
| ChipItem | item | Chip Item to be added should be passed. |
BuildRenderTree(RenderTreeBuilder)
Declaration
protected override void BuildRenderTree(RenderTreeBuilder __builder)
Parameters
| Type | Name | Description |
|---|---|---|
| Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder | __builder |
FindChip(String)
A function that finds chip based on given chip value.
Declaration
public ChipItem FindChip(string chipValue)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | chipValue | Value of the chip need to be passed to get the corresponding chip model. |
Returns
| Type | Description |
|---|---|
| ChipItem | GetItem. |
GetSelectedChips()
A function that returns the selected chips data.
Declaration
public List<ChipItem> GetSelectedChips()
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.List<ChipItem> | selectedChipModels. |
OnAfterRenderAsync(Boolean)
Method invoked after each time the component has been rendered.
Declaration
protected override Task OnAfterRenderAsync(bool firstRender)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Boolean | firstRender | Set to true for the first time component rendering; otherwise gets false. |
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task | ="Task". |
Overrides
OnInitializedAsync()
Method gets invoked when the component is ready to start.
Declaration
protected override Task OnInitializedAsync()
Returns
| Type | Description |
|---|---|
| System.Threading.Tasks.Task | ="Task". |
Overrides
RemoveChips(String[])
A function that removes the chip items based on given chip values.
Declaration
public void RemoveChips(string[] removableChipValues)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String[] | removableChipValues | Values of the chips which are to be removed should be passed. |
SelectChips(String[])
A function that selects chip items based on given index.
Declaration
public void SelectChips(string[] selectableChips)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String[] | selectableChips | Values of the chips which are to be selected should be passed. |
UpdateAttributes()
Updates the class and multiselection attributes of the chip root element.
Declaration
protected void UpdateAttributes()
UpdateAttributes(Dictionary<String, Object>)
Updates the attributes value.
Declaration
protected void UpdateAttributes(Dictionary<string, object> htmlAttributes = null)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.Dictionary<System.String, System.Object> | htmlAttributes | The htmlAttributes. |