Skip to content

Incorrect CSS value generation when current culture uses comma as decimal separator #577

Closed

Description

@tomasjancicka

Description

When the application's current culture uses a comma as the decimal separator (for example cs-CZ, de-DE, or any culture for countries listed here: https://en.wikipedia.org/wiki/Decimal_separator#Countries_using_decimal_comma), some computed CSS values are generated using a comma instead of a dot.

In the Tree View (and also Tree Select) component:

Image

The computed CSS should be: padding-left: 1.75rem; but is generated as: padding-left: 1,75rem; which is not a valid CSS value.

During a quick review of BbTreeItem.razor.cs, I found the following code: private string NodeStyle => $"padding-left: {(Depth * 1.25) + 0.5}rem;";. Since string interpolation uses the current culture by default, a culture with a comma decimal separator produces invalid CSS.

Steps to Reproduce

  1. Set the browser (or application) culture to a locale that uses a comma as the decimal separator.
  2. Open the Tree View component documentation page.
  3. Navigate to the Data-Driven example. Notice that nodes such as Components and Pages appear at the same indentation level as src because the generated padding-left value is invalid.

Impact

The issue is immediately visible in the Tree View and Tree Select components because some nodes are not indented correctly.

However, this problem is likely not limited to these components. It could potentially occur anywhere numeric values are interpolated into CSS, inline styles or SVG attributes. In some cases, the issue may not be visually obvious, so there could be additional affected locations that have not yet been identified.

Suggested Fix

Use culture-invariant formatting when converting numeric values to strings, for example:

private string NodeStyle => $"padding-left: {((Depth * 1.25) + 0.5).ToString(CultureInfo.InvariantCulture)}rem;";

or apply FormattableString.Invariant($"...") to the entire interpolated string.

Metadata

Metadata

Assignees

No one assigned

    Labels

    v4.2.0Fixed in the v4.2.0 branch; ships with the v4.2.0 release

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions