mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-15 17:31:42 +08:00
71bac2e85d
* Children components using CascadingParameter add itself to parent component.However, when children components disposed, they are not remove from parent component. For example, when items in checkgroup have changed , it may causes Index was outside the bounds of the array at AntDesign.CheckboxGroup.OnCheckboxChange.To fix these bug, Adding remove function in dispose process is the solution of this commit. * fix: some exception Co-authored-by: ElderJames <shunjiey@hotmail.com>
70 lines
1.7 KiB
C#
70 lines
1.7 KiB
C#
using System.Threading.Tasks;
|
|
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.AspNetCore.Components.Web;
|
|
|
|
namespace AntDesign
|
|
{
|
|
public partial class MentionsOption
|
|
{
|
|
[CascadingParameter] public Mentions Mentions { get; set; }
|
|
|
|
[Parameter] public string Value { get; set; }
|
|
|
|
[Parameter] public bool Disable { get; set; }
|
|
|
|
[Parameter] public RenderFragment ChildContent { get; set; }
|
|
|
|
public bool Selected { get; set; }
|
|
|
|
public bool Active { get; set; }
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
Mentions?.RemoveOption(this);
|
|
base.Dispose(disposing);
|
|
}
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
Mentions?.AddOption(this);
|
|
|
|
SetClassMap();
|
|
|
|
base.OnInitialized();
|
|
}
|
|
|
|
private void SetClassMap()
|
|
{
|
|
var prefixCls = "ant-mentions-dropdown-menu-item";
|
|
this.ClassMapper.Clear()
|
|
.Add(prefixCls)
|
|
.If($"{prefixCls}-disable", () => this.Disable)
|
|
.If($"{prefixCls}-selected", () => this.Selected)
|
|
.If($"{prefixCls}-active", () => this.Active)
|
|
;
|
|
|
|
InvokeStateHasChanged();
|
|
}
|
|
|
|
internal void OnMouseEnter()
|
|
{
|
|
this.Selected = true;
|
|
}
|
|
|
|
internal void OnMouseLeave()
|
|
{
|
|
this.Selected = false;
|
|
}
|
|
|
|
internal async Task OnClick(MouseEventArgs args)
|
|
{
|
|
if (args.Button == 0) //left click
|
|
{
|
|
await Mentions.OnOptionClick(this);
|
|
}
|
|
|
|
InvokeStateHasChanged();
|
|
}
|
|
}
|
|
}
|