Skip to content

Commit d325482

Browse files
CopilotArgoZhang
andauthored
fix(TimePicker): Use culture-invariant formatting for CSS transform values (#6790)
* Initial plan * Fix TimePicker culture-specific decimal separator in CSS transform Co-authored-by: ArgoZhang <[email protected]> * refactor: 使用 AddStyle 重构代码 * refactor: 改用 AddClass 方法 * test: 更新单元测试 --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: ArgoZhang <[email protected]> Co-authored-by: Argo Zhang <[email protected]>
1 parent d82d766 commit d325482

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-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: 35 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,37 @@ public async Task OnClickConfirm_Ok()
98100
await cut.InvokeAsync(() => btn.Click());
99101
Assert.True(confirm);
100102
}
103+
104+
[Fact]
105+
public async Task TimePickerCell_StyleName_CultureInvariant()
106+
{
107+
// 保存老的 Culture 设置
108+
var originalCulture = CultureInfo.CurrentCulture;
109+
var originalUICulture = CultureInfo.CurrentUICulture;
110+
111+
// 设置为土耳其文化环境 小数点使用逗号
112+
var trCulture = new CultureInfo("tr-TR");
113+
CultureInfo.CurrentCulture = trCulture;
114+
CultureInfo.CurrentUICulture = trCulture;
115+
116+
var cut = Context.RenderComponent<TimePickerCell>(pb =>
117+
{
118+
pb.Add(a => a.ViewMode, TimePickerCellViewMode.Hour);
119+
pb.Add(a => a.Value, TimeSpan.FromHours(2.5));
120+
});
121+
122+
// 调用 OnHeightCallback 方法设置高度
123+
await cut.InvokeAsync(() => cut.Instance.OnHeightCallback(12.25));
124+
cut.SetParametersAndRender();
125+
126+
// 检查高度样式是否正确生成应该是用点而不是逗号
127+
var styleElement = cut.Find("ul.time-spinner-list");
128+
var style = styleElement.GetAttribute("style");
129+
130+
Assert.Contains("-24.5px", style);
131+
132+
// 恢复当前线程文化设置
133+
CultureInfo.CurrentCulture = originalCulture;
134+
CultureInfo.CurrentUICulture = originalUICulture;
135+
}
101136
}

0 commit comments

Comments
 (0)