diff --git a/components/checkbox/CheckboxGroup.razor.cs b/components/checkbox/CheckboxGroup.razor.cs index 6a6c0b4718..fe42b96e1a 100644 --- a/components/checkbox/CheckboxGroup.razor.cs +++ b/components/checkbox/CheckboxGroup.razor.cs @@ -173,7 +173,7 @@ protected override void OnAfterRender(bool firstRender) { if (firstRender) { - if (ChildContent is not null && _checkboxItems.Count > 0) + if (ChildContent is not null && _checkboxItems?.Count > 0) { _constructedOptions = CreateConstructedOptions(); } diff --git a/components/core/Base/AntInputComponentBase.cs b/components/core/Base/AntInputComponentBase.cs index cba989a285..a9d9a5c5b0 100644 --- a/components/core/Base/AntInputComponentBase.cs +++ b/components/core/Base/AntInputComponentBase.cs @@ -226,13 +226,6 @@ protected virtual string FormatValueAsString(TValue value) /// True if the value could be parsed; otherwise false. protected virtual bool TryParseValueFromString(string value, out TValue result, out string validationErrorMessage) { - if (string.IsNullOrWhiteSpace(value)) - { - result = default; - validationErrorMessage = null; - return true; - } - TValue parsedValue = default; bool success; diff --git a/components/core/Helpers/DateHelper.cs b/components/core/Helpers/DateHelper.cs index d626f2d879..d5914c5df8 100644 --- a/components/core/Helpers/DateHelper.cs +++ b/components/core/Helpers/DateHelper.cs @@ -158,7 +158,13 @@ public static DateTime GetNextStartDateOfDay(DateTime date) int? minute = null, int? second = null) { - return new DateTime(year ?? date.Year, month ?? date.Month, day ?? date.Day, hour ?? date.Hour, minute ?? date.Minute, second ?? date.Second); + var yearValue = year ?? date.Year; + var monthValue = month ?? date.Month; + var dayValue = day ?? date.Day; + var daysInMonth = DateTime.DaysInMonth(yearValue, monthValue); + dayValue = dayValue > daysInMonth ? daysInMonth : dayValue; + + return new DateTime(yearValue, monthValue, dayValue, hour ?? date.Hour, minute ?? date.Minute, second ?? date.Second); } public static DateTime? FormatDateByPicker(DateTime? dateTime, string picker) diff --git a/components/core/JsInterop/modules/components/mentionsHelper.ts b/components/core/JsInterop/modules/components/mentionsHelper.ts index 9449793463..1b2fa39c14 100644 --- a/components/core/JsInterop/modules/components/mentionsHelper.ts +++ b/components/core/JsInterop/modules/components/mentionsHelper.ts @@ -6,8 +6,9 @@ mentionsHelper.isPopShowFlag = show; } - public static setEditorKeyHandler = function (Mentions: any, textArea: HTMLTextAreaElement): void { + public static setEditorKeyHandler = function (Mentions: any, element: HTMLTextAreaElement): void { + var textArea = mentionsHelper.getTextarea(element); textArea.onkeydown = async (ev): Promise => { //判断isPopShow不能用异步方法 if (!mentionsHelper.isPopShowFlag) return; @@ -27,10 +28,13 @@ } public static getProp = function (e: HTMLElement, propName: string): any { - return e[propName]; + var textArea = mentionsHelper.getTextarea(e); + + return textArea[propName]; } - public static getCursorXY = function (textArea: HTMLTextAreaElement) { + public static getCursorXY = function (element: HTMLElement) { + var textArea = mentionsHelper.getTextarea(element); let format = function (value) { value = value.replace(/<|>|`|"|&/g, '?'); return value; @@ -60,5 +64,17 @@ return [left, top]; }; + private static getTextarea(element: HTMLElement) { + const textAreaTag = "TEXTAREA"; + var textarea = element; + if (element.tagName != textAreaTag) { + var allTextareas = element.getElementsByTagName(textAreaTag); + if (allTextareas.length == 0) { + throw "Mentions requires a textarea to be rendered, but none were found."; + } + textarea = allTextareas[0] as HTMLTextAreaElement; + } + return textarea as HTMLTextAreaElement; + } } diff --git a/components/image/ImagePreview.razor b/components/image/ImagePreview.razor index 8d1561163a..eab751abb1 100644 --- a/components/image/ImagePreview.razor +++ b/components/image/ImagePreview.razor @@ -1,33 +1,43 @@ @namespace AntDesign - -
- -
- @if (ImageRef.ImageCount > 1) - { -
- + +
+
-
- + @if (ImageRef.ImageCount > 1) + { +
+ +
+
+ +
+ } + + +
+
    + @if (ImageRef.ImageCount > 1) + { +
  • @(ImageRef.CurrentIndex+1) / @ImageRef.ImageCount
  • + } +
  • + +
  • +
  • + +
  • +
  • + +
  • +
  • + +
  • +
  • + +
  • +
- } +
\ No newline at end of file diff --git a/components/input/Input.cs b/components/input/Input.cs index a99a3d35f9..8ee026b6af 100644 --- a/components/input/Input.cs +++ b/components/input/Input.cs @@ -89,7 +89,7 @@ public bool AutoFocus /// /// Delays the processing of the KeyUp event until the user has stopped - /// typing for a predetermined amount of time + /// typing for a predetermined amount of time. Default is 250 ms. /// [Parameter] public int DebounceMilliseconds diff --git a/components/input/TextArea.razor b/components/input/TextArea.razor index 015bcea8ab..fb0e0a1533 100644 --- a/components/input/TextArea.razor +++ b/components/input/TextArea.razor @@ -39,29 +39,34 @@ } } -
- @if (Suffix != null || AllowClear || FormItem?.FeedbackIcon != null) - { - - +
+
+
  • + Test User +
  • +
    "); + } + + [Fact] + public void StandardRender_ShouldCallJavascriptCallbackToDisplayOverlayWhenTypingAtSymbol() + { + SetupJavascript(); + var systemUnderTest = GetStandardRenderSystemUnderTest(); + + JSInterop.Setup("AntDesign.interop.mentionsHelper.setPopShowFlag", true); + + systemUnderTest.Find("textarea").Input("@"); + + JSInterop.VerifyInvoke("AntDesign.interop.mentionsHelper.setPopShowFlag", 1); + } + + [Fact] + public void TemplatedRender_ShouldCallJavascriptCallbackToDisplayOverlayWhenTypingAtSymbol() + { + SetupJavascript(); + var systemUnderTest = GetStandardRenderSystemUnderTest(); + + JSInterop.Setup("AntDesign.interop.mentionsHelper.setPopShowFlag", true); + + systemUnderTest.Find("textarea").Input("@"); + + JSInterop.VerifyInvoke("AntDesign.interop.mentionsHelper.setPopShowFlag", 1); + } + +#if NET6_0_OR_GREATER + private IRenderedComponent GetTemplatedRenderSystemUnderTest() + { + JSInterop.Setup("AntDesign.interop.inputHelper.getTextAreaInfo", _ => true); + + return Render( + @ + + Test User + + + + +
    +
  • + Test User +
  • +
    "); + } +#endif +} \ No newline at end of file diff --git a/tests/AntDesign.Tests/Typography/LinkTests.cs b/tests/AntDesign.Tests/Typography/LinkTests.cs index e6c1da2d6b..be29f0a195 100644 --- a/tests/AntDesign.Tests/Typography/LinkTests.cs +++ b/tests/AntDesign.Tests/Typography/LinkTests.cs @@ -120,13 +120,14 @@ public void ItShouldRenderCopyIconWhenCopyable() .AddChildContent("Something")); systemUnderTest.MarkupMatches($@" - Something - - - - - - + Something +
    + + + + + +
    "); } @@ -141,7 +142,7 @@ public void ItShouldCopyElementByDefault_WhenCopyIconLinkClicked() .Add(x => x.Copyable, true) .AddChildContent("Something")); - systemUnderTest.Find("a[data-id=copy-link]").Click(); + systemUnderTest.Find(".ant-typography-copy").Click(); JSInterop.VerifyInvoke(JSInteropConstants.CopyElement, "Copy JS was not called"); } @@ -161,7 +162,7 @@ public void ItShouldCopyTextWhenCopyConfigSet_WhenCopyIconLinkClicked() .Add(x => x.Copyable, true) .AddChildContent("Something")); - systemUnderTest.Find("a[data-id=copy-link]").Click(); + systemUnderTest.Find(".ant-typography-copy").Click(); JSInterop.VerifyInvoke(JSInteropConstants.Copy, "Copy JS was not called"); } @@ -184,7 +185,7 @@ public void ItShouldCallCopyConfigOnCopy_WhenCopyIconLinkClicked() .Add(x => x.Copyable, true) .AddChildContent("Something")); - systemUnderTest.Find("a[data-id=copy-link]").Click(); + systemUnderTest.Find(".ant-typography-copy").Click(); methodCalled.Should().BeTrue(); } diff --git a/tests/AntDesign.Tests/Typography/ParagraphTests.cs b/tests/AntDesign.Tests/Typography/ParagraphTests.cs index af9a99b209..d653f2dc3f 100644 --- a/tests/AntDesign.Tests/Typography/ParagraphTests.cs +++ b/tests/AntDesign.Tests/Typography/ParagraphTests.cs @@ -16,9 +16,10 @@ public void ItShouldRenderBasicProperly() var systemUnderTest = RenderComponent(parameters => parameters .AddChildContent("Something")); - systemUnderTest.MarkupMatches($@"
    - Something -
    "); + systemUnderTest.MarkupMatches($@" +
    + Something +
    "); } [Theory] @@ -32,7 +33,7 @@ public void ItShouldRenderTypesProperly(string type, string expectedClass) .AddChildContent("Something")); systemUnderTest.MarkupMatches($@"
    - Something + Something
    "); } @@ -44,7 +45,7 @@ public void ItShouldRenderCustomStyleOnDiv() .AddChildContent("Something")); systemUnderTest.MarkupMatches($@"
    - Something + Something
    "); } @@ -56,9 +57,7 @@ public void ItShouldRenderMark() .AddChildContent("Something")); systemUnderTest.MarkupMatches($@"
    - - Something - + Something
    "); } @@ -70,9 +69,7 @@ public void ItShouldRenderDelete() .AddChildContent("Something")); systemUnderTest.MarkupMatches($@"
    - - Something - + Something
    "); } @@ -84,9 +81,7 @@ public void ItShouldRenderUnderline() .AddChildContent("Something")); systemUnderTest.MarkupMatches($@"
    - - Something - + Something
    "); } @@ -98,24 +93,20 @@ public void ItShouldRenderCode() .AddChildContent("Something")); systemUnderTest.MarkupMatches($@"
    - - Something - + Something
    "); } [Fact] public void ItShouldRenderKeyboard() { - var systemUnderTest = RenderComponent(parameters => parameters + var systemUnderTest = RenderComponent(parameters => parameters .Add(x => x.Keyboard, true) .AddChildContent("Something")); - systemUnderTest.MarkupMatches($@"
    - - Something - -
    "); + systemUnderTest.MarkupMatches($@" + Something + "); } [Fact] @@ -126,9 +117,7 @@ public void ItShouldRenderStrong() .AddChildContent("Something")); systemUnderTest.MarkupMatches($@"
    - - Something - + Something
    "); } @@ -140,7 +129,7 @@ public void ItShouldRenderDisabled() .AddChildContent("Something")); systemUnderTest.MarkupMatches($@"
    - Something + Something
    "); } @@ -151,16 +140,17 @@ public void ItShouldRenderCopyIconWhenCopyable() .Add(x => x.Copyable, true) .AddChildContent("Something")); - systemUnderTest.MarkupMatches($@""); } #region Copy functionality @@ -174,7 +164,7 @@ public void ItShouldCopyElementByDefault_WhenCopyIconLinkClicked() .Add(x => x.Copyable, true) .AddChildContent("Something")); - systemUnderTest.Find("a").Click(); + systemUnderTest.Find(".ant-typography-copy").Click(); JSInterop.VerifyInvoke(JSInteropConstants.CopyElement, "Copy JS was not called"); } @@ -194,7 +184,7 @@ public void ItShouldCopyTextWhenCopyConfigSet_WhenCopyIconLinkClicked() .Add(x => x.Copyable, true) .AddChildContent("Something")); - systemUnderTest.Find("a").Click(); + systemUnderTest.Find(".ant-typography-copy").Click(); JSInterop.VerifyInvoke(JSInteropConstants.Copy, "Copy JS was not called"); } @@ -217,7 +207,7 @@ public void ItShouldCallCopyConfigOnCopy_WhenCopyIconLinkClicked() .Add(x => x.Copyable, true) .AddChildContent("Something")); - systemUnderTest.Find("a").Click(); + systemUnderTest.Find(".ant-typography-copy").Click(); methodCalled.Should().BeTrue(); } diff --git a/tests/AntDesign.Tests/Typography/TextTests.cs b/tests/AntDesign.Tests/Typography/TextTests.cs index ebcdf6ef90..308be41f10 100644 --- a/tests/AntDesign.Tests/Typography/TextTests.cs +++ b/tests/AntDesign.Tests/Typography/TextTests.cs @@ -120,15 +120,14 @@ public void ItShouldRenderCopyIconWhenCopyable() .AddChildContent("Something")); systemUnderTest.MarkupMatches($@" - Something - - - - - + Something
    + + + + - - "); +
    +
    "); } #region Copy functionality @@ -142,7 +141,7 @@ public void ItShouldCopyElementByDefault_WhenCopyIconLinkClicked() .Add(x => x.Copyable, true) .AddChildContent("Something")); - systemUnderTest.Find("a").Click(); + systemUnderTest.Find(".ant-typography-copy").Click(); JSInterop.VerifyInvoke(JSInteropConstants.CopyElement, "Copy JS was not called"); } @@ -162,7 +161,7 @@ public void ItShouldCopyTextWhenCopyConfigSet_WhenCopyIconLinkClicked() .Add(x => x.Copyable, true) .AddChildContent("Something")); - systemUnderTest.Find("a").Click(); + systemUnderTest.Find(".ant-typography-copy").Click(); JSInterop.VerifyInvoke(JSInteropConstants.Copy, "Copy JS was not called"); } @@ -185,7 +184,7 @@ public void ItShouldCallCopyConfigOnCopy_WhenCopyIconLinkClicked() .Add(x => x.Copyable, true) .AddChildContent("Something")); - systemUnderTest.Find("a").Click(); + systemUnderTest.Find(".ant-typography-copy").Click(); methodCalled.Should().BeTrue(); } diff --git a/tests/AntDesign.Tests/Typography/TitleTests.cs b/tests/AntDesign.Tests/Typography/TitleTests.cs index 0ea7b75b70..b3cc1ed8ac 100644 --- a/tests/AntDesign.Tests/Typography/TitleTests.cs +++ b/tests/AntDesign.Tests/Typography/TitleTests.cs @@ -123,15 +123,17 @@ public void ItShouldRenderCopyIconWhenCopyable() .Add(x => x.Copyable, true) .AddChildContent("Something")); - systemUnderTest.MarkupMatches($@"

    Something - - - - - + systemUnderTest.MarkupMatches($@" +

    + Something +

    "); + +

    "); } #region Copy functionality @@ -146,7 +148,7 @@ public void ItShouldCopyElementByDefault_WhenCopyIconLinkClicked() .Add(x => x.Copyable, true) .AddChildContent("Something")); - systemUnderTest.Find("a").Click(); + systemUnderTest.Find(".ant-typography-copy").Click(); JSInterop.VerifyInvoke(JSInteropConstants.CopyElement, "Copy JS was not called"); } @@ -167,7 +169,7 @@ public void ItShouldCopyTextWhenCopyConfigSet_WhenCopyIconLinkClicked() .Add(x => x.Copyable, true) .AddChildContent("Something")); - systemUnderTest.Find("a").Click(); + systemUnderTest.Find(".ant-typography-copy").Click(); JSInterop.VerifyInvoke(JSInteropConstants.Copy, "Copy JS was not called"); } @@ -191,7 +193,7 @@ public void ItShouldCallCopyConfigOnCopy_WhenCopyIconLinkClicked() .Add(x => x.Copyable, true) .AddChildContent("Something")); - systemUnderTest.Find("a").Click(); + systemUnderTest.Find(".ant-typography-copy").Click(); methodCalled.Should().BeTrue(); }