fix(module: input): fix incorrectly validation and required message (#3474)

* fix(module: input): fix incorrectly validation and required message

* add tests
This commit is contained in:
James Yeung 2023-10-29 16:34:02 +08:00 committed by GitHub
parent bd8d3fe3e4
commit 54d821e6ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 2 deletions

View File

@ -705,7 +705,7 @@ namespace AntDesign
if (FormItem?.IsRequiredByValidation ?? false)
{
builder.AddAttribute(65, "required", "required");
builder.AddAttribute(65, "aria-required", true);
}
// onchange 和 onblur 事件会导致点击 OnSearch 按钮时不触发 Click 事件,暂时取消这两个事件

View File

@ -1,9 +1,13 @@
@inherits AntDesignTestBase
@using System.ComponentModel.DataAnnotations
@inherits AntDesignTestBase
@code {
class Model
{
public string Name { get; set; } = "";
[Required]
public string? RequiredField { get; set; }
}
Model _model = new();
AntDesign.Form<Model>? _form;
@ -68,4 +72,27 @@
handlerExecuted.Should().BeTrue();
}
#endif
#if NET6_0_OR_GREATER
[Fact]
public void Form_EditContext_Build_Required()
{
//Arrange
JSInterop.Setup<AntDesign.JsInterop.Window>(JSInteropConstants.GetWindow)
.SetResult(new AntDesign.JsInterop.Window());
var cut = Render<AntDesign.Form<Model>>(
@<AntDesign.Form @ref="@_form" Model="@_model" >
<AntDesign.FormItem Label="RequiredField">
<AntDesign.Input @bind-Value=@context.RequiredField DebounceMilliseconds="0" />
</AntDesign.FormItem>
</AntDesign.Form>
);
//Act
var hasAriaRequried=cut.Find("input").HasAttribute("aria-required");
//Assert
hasAriaRequried.Should().BeTrue();
}
#endif
}