MudBlazor
MudBlazor copied to clipboard
MudColorPicker: Distingish between internal color view and external
Description
The color picker has a different view mode. If the toolbar is enabled, a user can switch between these views. At the same time, the developer can set the value too. This leads to a situation that is described in #4899, where as soon as there is a value selected in spectrum mode, which closes the picker, starts a new render cycle, and ends up displaying the picker in the initial view.
I saw two options to resolve it.
First is to think about the ColorPickerView
as a bindable property since the user can change it. However, there are only a few situations where saving this state in the own code makes sense.
So, I choose to implement the approach of creating a new field, internal to the color picker, that remembers the active (or current) state. So, if a user changes the mode, not the property, but the field changes. This resolves the described issue, and that also means that if a user has selected a color and reopened the same picker again, it will display the latest view.
How Has This Been Tested?
Added a unit tests (and modify existing ones) based on the trymud provided in #4899
Types of changes
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
Checklist:
- [x] The PR is submitted to the correct branch (
dev
). - [x] My code follows the code style of this project.
- [x] I've added relevant tests.
Codecov Report
Merging #4949 (fc332a1) into dev (a2fc21a) will increase coverage by
0.00%
. The diff coverage is100.00%
.
@@ Coverage Diff @@
## dev #4949 +/- ##
=======================================
Coverage 90.01% 90.01%
=======================================
Files 371 371
Lines 13309 13311 +2
=======================================
+ Hits 11980 11982 +2
Misses 1329 1329
Impacted Files | Coverage Δ | |
---|---|---|
...Blazor/Components/ColorPicker/MudColorPicker.razor | 100.00% <100.00%> (ø) |
|
...zor/Components/ColorPicker/MudColorPicker.razor.cs | 98.04% <100.00%> (+0.01%) |
:arrow_up: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 67202c1...fc332a1. Read the comment docs.
@henon Ready for your review
I agree Benno, this is the best way to fix it. Thanks!