Skip to content

Commit 45e0e69

Browse files
CopilotArgoZhang
andcommitted
Fix TimePicker culture-specific decimal separator in CSS transform
Co-authored-by: ArgoZhang <[email protected]>
1 parent e598c94 commit 45e0e69

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/BootstrapBlazor/Components/TimePicker/TimePickerCell.razor.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
55

6+
using System.Globalization;
7+
68
namespace BootstrapBlazor.Components;
79

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

5759
private string? UpIconString => CssBuilder.Default("time-spinner-arrow time-up")

test/UnitTest/Components/TimePickerTest.cs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone
55

6+
using System.Globalization;
7+
68
namespace UnitTest.Components;
79

810
public class TimePickerTest : BootstrapBlazorTestBase
@@ -98,4 +100,46 @@ public async Task OnClickConfirm_Ok()
98100
await cut.InvokeAsync(() => btn.Click());
99101
Assert.True(confirm);
100102
}
103+
104+
[Fact]
105+
public void TimePickerCell_StyleName_CultureInvariant()
106+
{
107+
// Save original culture
108+
var originalCulture = CultureInfo.CurrentCulture;
109+
var originalUICulture = CultureInfo.CurrentUICulture;
110+
111+
try
112+
{
113+
// Set culture to Turkish which uses comma as decimal separator
114+
var turkishCulture = new CultureInfo("tr-TR");
115+
CultureInfo.CurrentCulture = turkishCulture;
116+
CultureInfo.CurrentUICulture = turkishCulture;
117+
118+
var cut = Context.RenderComponent<TimePickerCell>(pb =>
119+
{
120+
pb.Add(a => a.ViewMode, TimePickerCellViewMode.Hour);
121+
pb.Add(a => a.Value, TimeSpan.FromHours(2.5));
122+
});
123+
124+
// Call OnHeightCallback to set internal height
125+
cut.InvokeAsync(() => cut.Instance.OnHeightCallback(36.59375));
126+
127+
// The StyleName property should use dots, not commas, even in Turkish culture
128+
var styleElement = cut.Find("ul.time-spinner-list");
129+
var style = styleElement.GetAttribute("style");
130+
131+
// CSS should use dots for decimal values, not commas
132+
Assert.Contains(".", style);
133+
Assert.DoesNotContain(",", style);
134+
135+
// Should contain valid translateY with dot decimal separator
136+
Assert.Matches(@"transform:\s*translateY\(-?\d+\.\d*px\);", style);
137+
}
138+
finally
139+
{
140+
// Restore original culture
141+
CultureInfo.CurrentCulture = originalCulture;
142+
CultureInfo.CurrentUICulture = originalUICulture;
143+
}
144+
}
101145
}

0 commit comments

Comments
 (0)