Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
44 changes: 44 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,46 @@ public async Task OnClickConfirm_Ok()
await cut.InvokeAsync(() => btn.Click());
Assert.True(confirm);
}

[Fact]
public void TimePickerCell_StyleName_CultureInvariant()
{
// Save original culture
var originalCulture = CultureInfo.CurrentCulture;
var originalUICulture = CultureInfo.CurrentUICulture;

try
{
// Set culture to Turkish which uses comma as decimal separator
var turkishCulture = new CultureInfo("tr-TR");
CultureInfo.CurrentCulture = turkishCulture;
CultureInfo.CurrentUICulture = turkishCulture;

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

// Call OnHeightCallback to set internal height
cut.InvokeAsync(() => cut.Instance.OnHeightCallback(36.59375));

// The StyleName property should use dots, not commas, even in Turkish culture
var styleElement = cut.Find("ul.time-spinner-list");
var style = styleElement.GetAttribute("style");

// CSS should use dots for decimal values, not commas
Assert.Contains(".", style);
Assert.DoesNotContain(",", style);

// Should contain valid translateY with dot decimal separator
Assert.Matches(@"transform:\s*translateY\(-?\d+\.\d*px\);", style);
}
finally
{
// Restore original culture
CultureInfo.CurrentCulture = originalCulture;
CultureInfo.CurrentUICulture = originalUICulture;
}
}
}
Loading