!2844 feat(#I5AAU1): add aria-disabled attribute on button

* test: 更新单元测试
* refactor: 更新按钮 aria-disabled 值
* feat: 更新 aria-disabled 值
This commit is contained in:
Argo 2022-06-01 02:24:12 +00:00
parent edd4ad25ce
commit b2d21b9153
8 changed files with 19 additions and 12 deletions

View File

@ -1,12 +1,12 @@
@namespace BootstrapBlazor.Components
@inherits ButtonBase
<button @attributes="@AdditionalAttributes" type="@ButtonType.ToDescriptionString()" @onclick="@OnClickButton" id="@Id" class="@ClassName" disabled="@Disabled" role="button" aria-disabled="@Disabled" tabindex="@Tab" @onclick:stopPropagation="@StopPropagation" @ref="ButtonElement">
@if(!string.IsNullOrEmpty(ButtonIcon))
<button @attributes="@AdditionalAttributes" type="@ButtonType.ToDescriptionString()" @onclick="@OnClickButton" id="@Id" class="@ClassName" disabled="@Disabled" role="button" aria-disabled="@DisabledString" tabindex="@Tab" @onclick:stopPropagation="@StopPropagation" @ref="ButtonElement">
@if (!string.IsNullOrEmpty(ButtonIcon))
{
<i class="@ButtonIcon"></i>
}
@if(!string.IsNullOrEmpty(Text))
@if (!string.IsNullOrEmpty(Text))
{
<span>@Text</span>
}

View File

@ -31,6 +31,11 @@ public abstract class ButtonBase : TooltipComponentBase
/// </summary>
protected string? Disabled => IsDisabled ? "disabled" : null;
/// <summary>
/// 获得 按钮 aria-disabled 属性
/// </summary>
protected string DisabledString => IsDisabled ? "true" : "false";
/// <summary>
/// 获得 按钮 tabindex 属性
/// </summary>

View File

@ -1,7 +1,7 @@
@namespace BootstrapBlazor.Components
@inherits ButtonBase
<a @attributes="AdditionalAttributes" class="@ClassString" id="@Id" href="@Url" disabled="@Disabled" role="button" aria-disabled="@Disabled" tabindex="@Tab" @onclick:stopPropagation="@StopPropagation" @onclick:preventDefault="@Prevent" @onclick="OnClick">
<a @attributes="AdditionalAttributes" class="@ClassString" id="@Id" href="@Url" disabled="@Disabled" role="button" aria-disabled="@DisabledString" tabindex="@Tab" @onclick:stopPropagation="@StopPropagation" @onclick:preventDefault="@Prevent" @onclick="OnClick">
@if (!string.IsNullOrEmpty(Icon))
{
<i class="@Icon"></i>

View File

@ -3,7 +3,7 @@
<DynamicElement TagName="@TagName" OnClick="Show"
data-bs-toggle="confirm" data-bs-placement="@Placement.ToDescriptionString()" id="@Id" type="@ElementType"
class="@PopButtonClassName" disabled="@Disabled" role="button" aria-disabled="@Disabled" tabindex="@Tab">
class="@PopButtonClassName" disabled="@Disabled" role="button" aria-disabled="@DisabledString" tabindex="@Tab">
@if (!string.IsNullOrEmpty(Icon))
{
<i class="@Icon"></i>

View File

@ -1,7 +1,7 @@
@namespace BootstrapBlazor.Components
@inherits ButtonBase
<a @attributes="@AdditionalAttributes" target="@Target" href="@PreviewUrl" class="@ClassName" disabled="@Disabled" role="button" aria-disabled="@Disabled" tabindex="@Tab">
<a @attributes="@AdditionalAttributes" target="@Target" href="@PreviewUrl" class="@ClassName" disabled="@Disabled" role="button" aria-disabled="@DisabledString" tabindex="@Tab">
@if (!string.IsNullOrEmpty(ButtonIcon))
{
<i class="@ButtonIcon"></i>

View File

@ -233,13 +233,15 @@ public class ButtonTest : BootstrapBlazorTestBase
}
[Fact]
public void SetDisable_Ok()
public async Task SetDisable_Ok()
{
var cut = Context.RenderComponent<Button>();
Assert.DoesNotContain("disabled", cut.Markup);
Assert.DoesNotContain("disabled=\"disabled\"", cut.Markup);
Assert.Contains("aria-disabled=\"false\"", cut.Markup);
cut.InvokeAsync(() => cut.Instance.SetDisable(true));
await cut.InvokeAsync(() => cut.Instance.SetDisable(true));
Assert.Contains("disabled=\"disabled\"", cut.Markup);
Assert.Contains("aria-disabled=\"true\"", cut.Markup);
}
[Fact]

View File

@ -16,7 +16,7 @@ public class PrintTest : BootstrapBlazorTestBase
{
pb.AddChildContent<PrintButton>();
});
Assert.Contains("<a onclick=\"$.bb_printview(this)\" class=\"btn btn-primary\" role=\"button\"><i class=\"fa fa-print\"></i><span>打印</span></a>", HttpUtility.HtmlDecode(cut.Markup));
Assert.Contains("<a onclick=\"$.bb_printview(this)\" class=\"btn btn-primary\" role=\"button\" aria-disabled=\"false\"><i class=\"fa fa-print\"></i><span>打印</span></a>", HttpUtility.HtmlDecode(cut.Markup));
var button = cut.FindComponent<PrintButton>();
button.SetParametersAndRender(pb =>

View File

@ -346,14 +346,14 @@ public class UploadTest : BootstrapBlazorTestBase
pb.Add(a => a.IsDisabled, false);
pb.Add(a => a.IsSingle, false);
});
Assert.DoesNotContain("disabled", button.ToMarkup());
Assert.DoesNotContain("disabled=\"disabled\"", button.ToMarkup());
cut.SetParametersAndRender(pb =>
{
pb.Add(a => a.IsDisabled, false);
pb.Add(a => a.IsSingle, true);
});
Assert.DoesNotContain("disabled", button.ToMarkup());
Assert.DoesNotContain("disabled=\"disabled\"", button.ToMarkup());
cut.SetParametersAndRender(pb =>
{