Skip to content

fix: Value "[object Object]" is set to css variable when using WithDefault/ToSwatch #2158

@guimabdo

Description

@guimabdo

🐛 Bug Report

When using .WithDefault on a color value Design Token, the related css variable is set with an invalid value [object Object]
image

💻 Repro or Code Sample

<FluentCard>
    Test
</FluentCard>
<FluentDivider />
<FluentButton OnClick="ChangeUsingCsharp">
    WithDefault (C#)
</FluentButton>
<FluentButton OnClick="ChangeUsingJs">
    WithDefault (JS)
</FluentButton>
@code {
    [Inject]
    public NeutralStrokeLayerRest NeutralStrokeLayerRest { get; set; } = default!;
    [Inject]
    public IJSRuntime JSRuntime { get; set; } = default!;

    // This produces invalid css variable value
    private async Task ChangeUsingCsharp()
    {
        await NeutralStrokeLayerRest.WithDefault("red".ToSwatch());
    }

    // This one works correctly
    private async Task ChangeUsingJs()
    {
        var module = await JSRuntime.InvokeAsync<IJSObjectReference>("import", "./_content/Microsoft.FluentUI.AspNetCore.Components/Microsoft.FluentUI.AspNetCore.Components.lib.module.js");
        await module.InvokeVoidAsync("neutralStrokeLayerRest.withDefault", "red");
    }
}

🤔 Expected Behavior

When clicking "WithDefault (C#)" the --neutral-stroke-layer-rest should be set to red:
image

😯 Current Behavior

--neutral-stroke-layer-rest is set to [object Object]
image

💁 Possible Solution

I currently don't have a suggestion for the fix.
But as a warkaround it is possible to load the JS module and call the design token .withDefault directly:

var module = await JSRuntime.InvokeAsync<IJSObjectReference>("import", "./_content/Microsoft.FluentUI.AspNetCore.Components/Microsoft.FluentUI.AspNetCore.Components.lib.module.js");
await module.InvokeVoidAsync("neutralStrokeLayerRest.withDefault", "red");

🔦 Context

🌍 Your Environment

  • OS & Device: Windows on PC
  • Browser: Microsoft Edge
  • .NET 8.0.x and Fluent UI Blazor 4.7.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageNew issue. Needs to be looked at

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions