`BitColorPicker` alpha slider throwing exception when `CultureInfo` number format differs from invariant
Is there an existing issue for this?
- [x] I have searched the existing issues
Describe the bug
Alpha slider change handler processes the input without explicitly specifying CultureInfo.InvariantCulture. This causes applications that are using CultureInfo with number formatting different than english to throw.
There is also a related issue (possibly related to the #11763) that renders the current selection dot incorrectly. The style positioning the dot also does not specify invariant culture, so the css is created using the thread culture. E.g. instead of top: 5.5..., top: 5,5... (decimal comma) is used.
Using
_color.A = Convert.ToDouble(args.Value, CultureInfo.InvariantCulture);
and
style=@(FormattableString.Invariant($"top:{_saturationPickerThumbPosition?.Top}px;left:{_saturationPickerThumbPosition?.Left}px;background-color:{Rgb}"))
seems to fix the issues.
Expected Behavior
Using non-english culture info should not break the component.
Steps To Reproduce
@page "/colorpicker-culture"
<BitColorPicker ShowAlphaSlider />
@code {
protected override void OnInitialized()
{
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.GetCultureInfo("cs-CZ");
}
}
Using the sample above, trying to interact with the slider throws exception.
Exceptions (if any)
System.FormatException: The input string '0.66' was not in a correct format.
at System.Number.ThrowFormatException[TChar](ReadOnlySpan`1 value)
at System.String.System.IConvertible.ToDouble(IFormatProvider provider)
at Bit.BlazorUI.BitColorPicker.HandleOnAlphaInput(ChangeEventArgs args) in C:\Users\Jakub\source\repos\bitplatform\src\BlazorUI\Bit.BlazorUI\Components\Inputs\ColorPicker\BitColorPicker.razor.cs:line 202
at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
.NET Version
No response
Anything else?
No response
📝 CodeRabbit Plan Mode
Generate an implementation plan and prompts that you can use with your favorite coding agent.
- [ ] Create Plan
🧪 Issue enrichment is currently in open beta.
You can configure auto-planning by selecting labels in the issue_enrichment configuration.
To disable automatic issue enrichment, add the following to your .coderabbit.yaml:
issue_enrichment:
auto_enrich:
enabled: false
💬 Have feedback or questions? Drop into our discord or schedule a call!
Hello there! I'm a wiki 🤖.
Based on the content of this thread, I've found a potentially relevant wiki page for you!
I hope this helps!
Thanks for contacting us. We're investigating this issue. We'll let you know if it's possible to work on this issue.
The issue is accepted and planned. Resolving it will start ASAP.
Resolving this issue has started. It will be announced when this issue is resolved.
This issue has been resolved, and it will be available in the next pre-release version. It will be announced when the pre-release becomes ready.