ant-design-blazor/components/mentions/MentionsOption.razor.cs
dingyanwu 7ad15664fe
refactor(module: mentions): refactor and fixed positioning and display issues (#2874)
* refactor mentions

* 修复:定位和隐藏的问题。

* fix: 修复定位和显示的一些bug

* fix:手误

Co-authored-by: 丁某 <dingyanwu518@hotmail.com>
2022-11-13 13:57:41 +08:00

42 lines
1.2 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 RenderFragment ChildContent { get; set; }
public bool Active => Mentions?.ActiveOptionValue == Value;
protected override async Task OnInitializedAsync()
{
Mentions?.AddOption(this);
SetClassMap();
await base.OnInitializedAsync();
}
private void SetClassMap()
{
var prefixCls = "ant-mentions-dropdown-menu-item";
ClassMapper.Clear().Add(prefixCls).If("ant-mentions-dropdown-menu-item-active", () => Active);
InvokeStateHasChanged();
}
internal void OnMouseOver()
{
Mentions.ActiveOptionValue = Value;
}
internal async Task OnClick(MouseEventArgs args)
{
if (args.Button == 0) //left click
{
await Mentions.ItemClick(Value);
}
}
}
}