Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
guimabdo opened this issue Jun 5, 2024 · 2 comments 路 Fixed by #2159
Closed
Labels
triage New issue. Needs to be looked at

Comments

@guimabdo
Copy link

guimabdo commented Jun 5, 2024

馃悰 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
@microsoft-github-policy-service microsoft-github-policy-service bot added the triage New issue. Needs to be looked at label Jun 5, 2024
@vnbaaij
Copy link
Collaborator

vnbaaij commented Jun 6, 2024

As described on https://fluentui-blazor.net/DesignTokens:

For Design Tokens that work with a color value, you must call the聽ToSwatch()聽extension method on a string value or use one of the Swatch constructors. This makes sure the color is using a format that Design Tokens can handle. A Swatch has a lot of commonality with the聽System.Drawing.Color聽struct. Instead of the values of the components being between 0 and 255, in a Swatch the components are expressed as a value between 0 and 1.

What it does not mention but should be clear, is that this won't work on a 'named' color. So instead of "red" use "#ff0000" and it should work.

@vnbaaij
Copy link
Collaborator

vnbaaij commented Jun 6, 2024

Apparently, there is an issue when passing a Swatch to WithDefault. I addded an overload that takes a string value (see PR #2159). Your code will work once this addition is released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage New issue. Needs to be looked at
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants