cositehq / sanity-plugin-simpler-color-input

A simpler color input for Sanity studio.
MIT License
25 stars 3 forks source link

Choosing "Clear" doesn't remove the annotation? #3

Closed jamiechong closed 8 months ago

jamiechong commented 8 months ago

Is it intended that clicking "Clear" doesn't actually remove the annotation? I end up in a state where my text is marked up, but without any color.

Screenshot 2023-12-28 at 10 19 59 AM Screenshot 2023-12-28 at 10 20 21 AM Screenshot 2023-12-28 at 10 23 52 AM

Edit: for some reason seems like screenshots didn't upload correctly. Trying again.

jamiechong commented 8 months ago

seems related to how GH handles image uploads to tickets. Please comment back if you want me to share this another way. But hopefully you understand the flow I'm describing.

AlyssaKirstine commented 8 months ago

Hi @jamiechong! This is intentional. Clicking the Clear button clears the color the user selected, but to remove the annotation itself, you'll need to click outside of the Tex color popup and click the trash icon (see below screenshot).

image

To prevent an empty color in my projects, I make the text color type required by setting it up like so under annotations:

{
    type: 'textColor',
    validation: (rule: Rule) => rule.required(),
}

Then the user will get an error message saying the field is required unless they delete it. image

Does this make sense? Happy to also consider your thoughts if you think there's a better solution.

jamiechong commented 8 months ago

Thanks - I'll try using the validation Rule so we don't end up in a weird state where the annotation is added, but no color is set. I wonder what the use case is for even having a Clear button. Imo there is either a color or there is not. "clearing" it to be empty doesn't make sense to me, which is why I expected it to behave like the delete button.

jamiechong commented 8 months ago

I just tried the validation: required approach, but feel the UX is even more confusing because it still let's me clear the color, but then I don't discover the color is required until after I've cleared it.

Possibly we can add an option to this plugin that let's us remove the Clear button?

AlyssaKirstine commented 8 months ago

Good point @jamiechong. Initially, I added the clear button when the color picker was built to be used outside the portable text editor (as an inline field for a document). In that case, you need a way to clear the color in cases where it is optional and you want to leave the field blank.

I agree that it is confusing when used in the portable text editor, however. I will look at the code when I get a chance to see what I can do to clear up the confusion!

AlyssaKirstine commented 8 months ago

Hey @jamiechong I just released v2.1.0 of this plugin which automatically hides the clear button when the field is marked as required. This is how the color input for other CMSs like Contentful behave, so I thought it made sense to do this instead of adding an additional option to the plugin config.

Cheers, Alyssa

jamiechong commented 8 months ago

amazing @AlyssaKirstine - we'll give this a try. thank you!