MudBlazor icon indicating copy to clipboard operation
MudBlazor copied to clipboard

MudColorPicker: Distingish between internal color view and external

Open just-the-benno opened this issue 2 years ago • 1 comments

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.

just-the-benno avatar Jul 25 '22 04:07 just-the-benno

Codecov Report

Merging #4949 (fc332a1) into dev (a2fc21a) will increase coverage by 0.00%. The diff coverage is 100.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.

codecov[bot] avatar Jul 25 '22 05:07 codecov[bot]

@henon Ready for your review

just-the-benno avatar Aug 22 '22 07:08 just-the-benno

I agree Benno, this is the best way to fix it. Thanks!

henon avatar Aug 22 '22 10:08 henon