Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
fix(TInputAdorment): 修复因为 tdesign.css 升级造成的组件样式变形
Browse files Browse the repository at this point in the history
  • Loading branch information
teacher-zhou committed May 22, 2023
1 parent d634d2a commit 7f45e63
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 40 deletions.
5 changes: 1 addition & 4 deletions doc/TDesign.Docs.ServerSide/TDesign.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 1 addition & 4 deletions doc/TDesign.Docs.WebAssembly/wwwroot/TDesign.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

61 changes: 45 additions & 16 deletions src/TDesign.Test/Components/Input/InputAdornmentTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using ComponentBuilder;
using ComponentBuilder.FluentRenderTree;
using Microsoft.AspNetCore.Components.Forms;
using System;
using System.Collections.Generic;
Expand All @@ -21,39 +22,67 @@ public void Test_Render()
public void Test_Prepend_Parameter()
{
RenderComponent(m => m.Add(p => p.Prepend, "http"))
.Should()
.HaveClass("t-input-adornment--prepend")
.And
.HaveChildMarkup(builder => builder.CreateElement(0, "span", "http", new { @class = "t-input-adornment__prepend" }));
.MarkupMatches(builder =>
{
builder.Div("t-input-adornment").Content(prepend =>
{
prepend.Span("t-input-adornment__prepend").Content(text =>
{
text.Span("t-input-adornment__text").Content("http").Close();
}).Close();
})
.Close();
});
}

[Fact(DisplayName = "InputAdornment - PrependContent 参数")]
public void Test_PrependContent_Parameter()
{
RenderComponent(m => m.Add(p => p.PrependContent, builder => builder.AddContent(0, "html content")))
.Should()
.HaveClass("t-input-adornment--prepend")
.And
.HaveChildMarkup(builder => builder.CreateElement(0, "span", content => content.AddContent(0, "html content"), new { @class = "t-input-adornment__prepend" }));
.MarkupMatches(builder =>
{
builder.Div("t-input-adornment").Content(prepend =>
{
prepend.Span("t-input-adornment__prepend").Content(text =>
{
text.Span("t-input-adornment__text").Content("html content").Close();
}).Close();
})
.Close();
});
}
[Fact(DisplayName = "InputAdornment - Append 参数")]
public void Test_Append_Parameter()
{
RenderComponent(m => m.Add(p => p.Append, "http"))
.Should()
.HaveClass("t-input-adornment--append")
.And
.HaveChildMarkup(builder => builder.CreateElement(0, "span", "http", new { @class = "t-input-adornment__append" }));
.MarkupMatches(builder =>
{
builder.Div("t-input-adornment").Content(prepend =>
{
prepend.Span("t-input-adornment__append").Content(text =>
{
text.Span("t-input-adornment__text").Content("http").Close();
}).Close();
})
.Close();
});
}

[Fact(DisplayName = "InputAdornment - AppendContent 参数")]
public void Test_AppendContent_Parameter()
{
RenderComponent(m => m.Add(p => p.AppendContent, builder => builder.AddContent(0, "html content")))
.Should()
.HaveClass("t-input-adornment--append")
.And
.HaveChildMarkup(builder => builder.CreateElement(0, "span", content => content.AddContent(0, "html content"), new { @class = "t-input-adornment__append" }));
.MarkupMatches(builder =>
{
builder.Div("t-input-adornment").Content(prepend =>
{
prepend.Span("t-input-adornment__append").Content(text =>
{
text.Span("t-input-adornment__text").Content("html content").Close();
}).Close();
})
.Close();
});
}

}
Expand Down
25 changes: 9 additions & 16 deletions src/TDesign/Components/Forms/TInputAdornment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,28 @@ public class TInputAdornment : BlazorComponentBase, IHasChildContent
[Parameter]public RenderFragment? AppendContent { get; set; }

/// <inheritdoc/>
protected override void OnParametersSet()
protected override void AfterSetParameters(ParameterView parameters)
{
base.OnParametersSet();

if ( !string.IsNullOrEmpty(Prepend) )
base.AfterSetParameters(parameters);
if (!string.IsNullOrWhiteSpace( Prepend ))
{
PrependContent ??= builder => builder.AddContent(0, Prepend);
}
if ( !string.IsNullOrEmpty(Append) )
if ( !string.IsNullOrWhiteSpace(Append) )
{
AppendContent ??= builder => builder.AddContent(0, Append);
}
}

/// <inheritdoc/>
protected override void BuildCssClass(ICssClassBuilder builder)
{
builder.Append("t-input-adornment--prepend", PrependContent is not null)
.Append("t-input-adornment--append",AppendContent is not null)
;
}

/// <inheritdoc/>
protected override void AddContent(RenderTreeBuilder builder, int sequence)
{
builder.CreateElement(sequence, "span", PrependContent, new { @class = "t-input-adornment__prepend" }, PrependContent is not null);

builder.Span("t-input-adornment__prepend",PrependContent is not null).Content(text => BuildText(text, PrependContent)).Close();
builder.AddContent(sequence + 1, ChildContent);
builder.Span("t-input-adornment__append", AppendContent is not null).Content(text => BuildText(text, AppendContent)).Close();

builder.CreateElement(sequence+2, "span", AppendContent, new { @class = "t-input-adornment__append" },AppendContent is not null);
}

void BuildText(RenderTreeBuilder builder, RenderFragment? fragment)
=> builder.Span("t-input-adornment__text").Content(fragment).Close();
}

0 comments on commit 7f45e63

Please sign in to comment.