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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

通过代码修改Result组件图标颜色失败(Failed to modify the color of the Result component icon through code) #1328

Closed
JiaChengLuo opened this issue Apr 9, 2021 · 10 comments · Fixed by #1336
Labels
🐛bug Something isn't working

Comments

@JiaChengLuo
Copy link
Contributor

Describe the bug

通过代码修改Result组件自定义的图标颜色失败
Failed to modify the custom icon color of the Result component through code

Steps to reproduce (please include code)

<Result Icon="smile-outline" Title="This is a title" Status="@status">
<Extra>
<Button OnClick="@(() => status = "error")">Change Status</Button>
</Extra>
</Result>

@code{ string status = "info"; }

Further technical details

  • AntDesign Nuget Package version 0.7.4
  • .NET 5.0.102
  • VS2019 16.8.4
@ElderJames ElderJames added the 🐛bug Something isn't working label Apr 9, 2021
@ElderJames
Copy link
Member

ElderJames commented Apr 9, 2021

Thanks for contacting us @JiaChengLuo
This is a little bug, would you be interested in helping us fix it?

@JiaChengLuo
Copy link
Contributor Author

@ElderJames I will try to solve it😂

@ElderJames
Copy link
Member

You just need to add StateHasChanged in Status setter.

@JiaChengLuo
Copy link
Contributor Author

😥 I encountered some problems when compiling the project, so I couldn’t test it.

@ElderJames
Copy link
Member

Please install the node.js first

@JiaChengLuo
Copy link
Contributor Author

The problem is solved, I will test it.😁

@JiaChengLuo
Copy link
Contributor Author

I try to add StateHasChanged in Status setter, but it didn't work.
I found that every time the property value is changed, the SetClass() method is called, and {PrefixCls}-{Status} is added to the ClassMapper, but the page seems to only use the css class added when constructing the component .
So I called ClassMapper.Clear() in the SetClass() method, and it worked.
The modified SetClass() method code is as follows

private void SetClass()
        {
            ClassMapper.Clear();
            ClassMapper.Add(PrefixCls)
                .Add($"{PrefixCls}-{Status}");

            IconClassMapper.Clear();
            IconClassMapper.Add($"{PrefixCls}-icon")
                .If($"{PrefixCls}-image", () => IsImage);
        }

@ElderJames
Copy link
Member

please use Get(()=>$"{PrefixCls}-{Status}") , and it will update every time.

@JiaChengLuo
Copy link
Contributor Author

I tried Get(()=>$"{PrefixCls}-{Status}") but got this exception System.ArgumentException:“An item with the same key has already been added. Key: System.Func1[System.String]”`.
Is there any error in my code?

ClassMapper.Add(PrefixCls).Get(() => $"{PrefixCls}-{Status}");

or

ClassMapper.Get(() => $"{PrefixCls}-{Status}");

Do I need to call ClassMapper.Clear() first?

@ElderJames
Copy link
Member

don't setup more than one time

JiaChengLuo added a commit to JiaChengLuo/ant-design-blazor that referenced this issue Apr 11, 2021
JiaChengLuo added a commit to JiaChengLuo/ant-design-blazor that referenced this issue Apr 11, 2021
ElderJames pushed a commit that referenced this issue Apr 12, 2021
…#1328) (#1336)

* fix(module:result): modify status unsuccessfully after initialization(#1328)

* fix(module:result): determine whether the Icon is empty string(#1328)

* doc: add changeTheResult demo(#1328)

* delete some lines
ElderJames pushed a commit that referenced this issue Apr 23, 2022
…#1328) (#1336)

* fix(module:result): modify status unsuccessfully after initialization(#1328)

* fix(module:result): determine whether the Icon is empty string(#1328)

* doc: add changeTheResult demo(#1328)

* delete some lines
ElderJames pushed a commit that referenced this issue Apr 30, 2022
…#1328) (#1336)

* fix(module:result): modify status unsuccessfully after initialization(#1328)

* fix(module:result): determine whether the Icon is empty string(#1328)

* doc: add changeTheResult demo(#1328)

* delete some lines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛bug Something isn't working
Projects
None yet
2 participants