1

I'm trying to change the style of a Fluent UI switch, so that the color of the dot is different when the switch is off.

My Html:

<FluentSwitch @ref="ref1"/>

And my code behind:

private Microsoft.FluentUI.AspNetCore.Components.DesignTokens.Swatch customColor = "#0473ce".ToSwatch();

[Inject]
private NeutralForegroundRest neutralForegroundRest { get; set; } = default!;

private FluentSwitch? ref1;

protected override async Task OnAfterRenderAsync(bool firstRender)
{
    if (firstRender)
    {
        await neutralForegroundRest.SetValueFor(ref1!.Element, customColor);
    }
}

This code seems to work, and actually update the value for the CSS element, however, it changes to [object Object] instead of the expected Hex code.

enter image description here

How should this be fixed so that the hex code is actually set instead of the [object Object]?

0

1 Answer 1

0

This is a bug. If you create an issue in the repository, it can be triaged.

One way of achieving what you want would be to target the variables matching the design token used to render the underlying web component fluent-switch.

<style>
    fluent-switch.mySwitch {
        --custom-color : limegreen;
        --neutral-foreground-rest: var(--custom-color);
    }
</style>

<FluentSwitch />
<FluentSwitch Class="mySwitch" />
Sign up to request clarification or add additional context in comments.

2 Comments

In the interim, here is a workaround ``` <style> fluent-switch.mySwitch { --myColor: yellowgreen; --neutral-foreground-rest: var(--myColor); --accent-fill-hover: var(--myColor); --accent-fill-active: var(--myColor); --accent-fill-rest: var(--myColor); } </style> <FluentSwitch /> <FluentSwitch Class="mySwitch"/>```

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.