Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// See the LICENSE file in the project root for more information.
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone

using System.Globalization;

namespace BootstrapBlazor.Components;

/// <summary>
Expand Down Expand Up @@ -51,7 +53,7 @@ public partial class TimePickerCell
/// 获得 组件单元数据样式
/// </summary>
private string? StyleName => CssBuilder.Default()
.AddClass($"transform: translateY({CalcTranslateY()}px);")
.AddClass($"transform: translateY({CalcTranslateY().ToString(CultureInfo.InvariantCulture)}px);")
.Build();

private string? UpIconString => CssBuilder.Default("time-spinner-arrow time-up")
Expand Down
35 changes: 35 additions & 0 deletions test/UnitTest/Components/TimePickerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// See the LICENSE file in the project root for more information.
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone

using System.Globalization;

namespace UnitTest.Components;

public class TimePickerTest : BootstrapBlazorTestBase
Expand Down Expand Up @@ -98,4 +100,37 @@ public async Task OnClickConfirm_Ok()
await cut.InvokeAsync(() => btn.Click());
Assert.True(confirm);
}

[Fact]
public async Task TimePickerCell_StyleName_CultureInvariant()
{
// 保存老的 Culture 设置
var originalCulture = CultureInfo.CurrentCulture;
var originalUICulture = CultureInfo.CurrentUICulture;

// 设置为土耳其文化环境 小数点使用逗号
var trCulture = new CultureInfo("tr-TR");
CultureInfo.CurrentCulture = trCulture;
CultureInfo.CurrentUICulture = trCulture;

var cut = Context.RenderComponent<TimePickerCell>(pb =>
{
pb.Add(a => a.ViewMode, TimePickerCellViewMode.Hour);
pb.Add(a => a.Value, TimeSpan.FromHours(2.5));
});

// 调用 OnHeightCallback 方法设置高度
await cut.InvokeAsync(() => cut.Instance.OnHeightCallback(12.25));
cut.SetParametersAndRender();

// 检查高度样式是否正确生成应该是用点而不是逗号
var styleElement = cut.Find("ul.time-spinner-list");
var style = styleElement.GetAttribute("style");

Assert.Contains("-24.5px", style);

// 恢复当前线程文化设置
CultureInfo.CurrentCulture = originalCulture;
CultureInfo.CurrentUICulture = originalUICulture;
}
}
Loading