!795 feat(#I2AGVU): add OnValueChanged delegate on Toggle/Switch

* docs: 更新 Toggle/Switch OnValueChanged 文档
* feat: Toggle 组件增加 OnValueChanged 回调委托
This commit is contained in:
Argo 2020-12-23 00:17:51 +08:00
parent d26df34bda
commit 7c8ab6e1fd
3 changed files with 24 additions and 2 deletions

View File

@ -155,6 +155,13 @@ namespace BootstrapBlazor.Shared.Pages
ValueList = " — ",
DefaultValue = " — "
},
new AttributeItem() {
Name = "OnValueChanged",
Description = "值发生改变时回调委托方法",
Type = "Func<bool, Task>",
ValueList = " — ",
DefaultValue = " — "
}
};
/// <summary>
@ -168,7 +175,7 @@ namespace BootstrapBlazor.Shared.Pages
Name = "ValueChanged",
Description="获取选择改变的值",
Type ="EventCallback<bool>"
},
}
};
}
}

View File

@ -61,7 +61,7 @@ namespace BootstrapBlazor.Shared.Pages
Name = "ValueChanged",
Description="获取选择改变的值",
Type ="EventCallback<bool>"
},
}
};
/// <summary>
@ -127,6 +127,13 @@ namespace BootstrapBlazor.Shared.Pages
ValueList = " — ",
DefaultValue = " — "
},
new AttributeItem() {
Name = "OnValueChanged",
Description = "值发生改变时回调委托方法",
Type = "Func<bool, Task>",
ValueList = " — ",
DefaultValue = " — "
}
};
}
}

View File

@ -8,6 +8,7 @@
// **********************************
using Microsoft.AspNetCore.Components;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
@ -67,6 +68,12 @@ namespace BootstrapBlazor.Components
[Parameter]
public Color Color { get; set; } = Color.Success;
/// <summary>
///
/// </summary>
[Parameter]
public Func<bool, Task>? OnValueChanged { get; set; }
/// <summary>
/// 点击控件时触发此方法
/// </summary>
@ -76,6 +83,7 @@ namespace BootstrapBlazor.Components
{
Value = !Value;
if (ValueChanged.HasDelegate) await ValueChanged.InvokeAsync(Value);
OnValueChanged?.Invoke(Value);
}
}
}