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

Don't update saturation based on parsed color #536

Merged
merged 23 commits into from
Feb 5, 2024

Conversation

bjarnef
Copy link
Contributor

@bjarnef bjarnef commented Jul 18, 2023

Description

This PR fixes an issue in color picker component, when dragging the handle to the bottom, where it sometimes jump to bottom left, because when the color value of #000000 then const { h, s, l } = parsed.toHsl(); returns a saturation value of 0, which affect the gridHandleX to be 0.

#533

chrome_qFG9VWOgbD.mp4

Types of changes

  • 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 change)
  • Chore (minor updates related to the tooling or maintenance of the repository, does not impact compiled assets)

Motivation and context

How to test?

Screenshots (if appropriate)

Checklist

  • If my change requires a change to the documentation, I have updated the documentation in this pull request.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.

@github-actions
Copy link

github-actions bot commented Jul 18, 2023

Hi there @bjarnef, thank you for this contribution! 👍

While we wait for the team to have a look at your work, we wanted to let you know about that we have a checklist for some of the things we will consider during review:

  • It's clear what problem this is solving, there's a connected issue or a description of what the changes do and how to test them
  • The automated tests all pass (see "Checks" tab on this PR)
  • The level of security for this contribution is the same or improved
  • The level of performance for this contribution is the same or improved
  • Avoids creating breaking changes; note that behavioral changes might also be perceived as breaking
  • If this is a new feature, Umbraco HQ provided guidance on the implementation beforehand
  • 💡 The contribution looks original and the contributor is presumably allowed to share it

Don't worry if you got something wrong. We like to think of a pull request as the start of a conversation, we're happy to provide guidance on improving your contribution.

If you realize that you might want to make some changes then you can do that by adding new commits to the branch you created for this work and pushing new commits. They should then automatically show up as updates to this pull request.

Thanks, from your friendly Umbraco GitHub bot 🤖 🙂

@iOvergaard
Copy link
Contributor

Excellent, @bjarnef. Can we just cross saturation out like that for all scenarios? If yes, feel free to fix the linting errors and remove the console.log's and we'll get it merged 😎

@iOvergaard iOvergaard added bug Something isn't working community/pr labels Jul 19, 2023
@bjarnef
Copy link
Contributor Author

bjarnef commented Jul 19, 2023

@iOvergaard an issue with this is that saturation (and eventually hue as well) is not set the specific color value.
If commented hue the spectrum doesn't update, when hue slider value change.

It is fine that #000000 initially set the saturation to 0 and grid handle position at bottom left. We just don't want to update it while dragging the handle and the color value hit black color at bottom.

I think we may need some variables to keeper track of the grid handle coordinates, initially from color value and updated as handle is moved around, which update e.g. hue and saturation values, but doesn't affect current handle position Even though color is black at different positions.

However when a color from palette is selected it update the value property in <uui-color-area>, which update the hue, saturation etc. and the grid handle position based on that.

Another thing I noticed is that moving the handle using left/right arrow keys no longer seems to keep same Y-coordinate as it originally did https://shoelace.style/components/color-picker - it does in <uui-color-area> itself, but not when used in <uui-color-picker>

@iOvergaard
Copy link
Contributor

Ok, @bjarnef, I think I see what you are getting at. I think we could try your proposal out by not updating the saturation. We can add additional variables to keep the handle coordinates in sync if needed down the road.

Would you like to try and get this PR to pass the automated tests?

@bjarnef
Copy link
Contributor Author

bjarnef commented Jul 24, 2023

@iOvergaard yeah, but not updating the saturation in value property means the spectrum isn't initially correct from color value set, or e.g. when hue slider change or a color from palette is selected.

It is also a similar issue with hue, e.g. with a green'ish gradient in color area, when dragging handle to bottom (black) it updates the value, which then parse the color and from #000000 hue and saturation value is zero, so the color area updates to a red'ish color spectrum.

chrome_VAGHi5Gj69.mp4

E.g. compare with how the Shoelace color picker handle this, where saturation and brightness are updated and events emitted:
https://github.com/shoelace-style/shoelace/blob/current/src/components/color-picker/color-picker.ts#L297-L305

but it also parsed color as hsva:
https://github.com/shoelace-style/shoelace/blob/current/src/components/color-picker/color-picker.ts#L576

where we here parse from hsla:

`hsla(${hue}, ${saturation}%, ${lightness}%, ${alpha / 100})`

@bjarnef
Copy link
Contributor Author

bjarnef commented Sep 28, 2023

@iOvergaard I think it is related to this, but I noticed when color is black and changing the hue slider, the color area doesn't change - probably due how it parse the HSL values from #000000 (in color area component).
E.g. compare with this how color spectrum change, when color in black and hue is changing.
https://shoelace.style/components/color-picker

In the Shoelace color picker the values are modified directly, but here we have e.g. color area in an isolated component.
By default hue value from #000000 is zero, so we probably need a way to track this is use e.g. changed hue to 50, but selected color yet is #000000.

It also seems a change has been made and the picker icon is no longer shown here?
https://uui.umbraco.com/?path=/story/uui-color-picker--overview

@bjarnef
Copy link
Contributor Author

bjarnef commented Sep 28, 2023

@iOvergaard regarding change of hue slider, something weird happens in setColor() in color picker component.
originally the parameter was string, but now accept string or HslaColor.

Even though hue parsed in is greather than zero, the parse color using Colord instance return 0.

chrome_9dOIC9SrbN

I added a workaround in 9fe8a29

chrome_nLnJEbp5c6.mp4

I also noticed something that has affected the opacity slider - when dragging the slider value, it shouldn't change opacify of the slider itself, only the preview, so it still show the color gradient like this: https://shoelace.style/components/color-picker#opacity

Fixed in dd34062 as well.

@bjarnef
Copy link
Contributor Author

bjarnef commented Sep 29, 2023

@iOvergaard can you review these changes? 👍

It solves a few issues.

  • When dragging handle to bottom (black), it doesn't just to bottom left. It also mean when picking black color it may not always set handle to bottom left, because or saturation but I think it is okay for now.
  • If alpha/transparency it set, the handle reflect this as in the Shoelace component.
  • Dragging opacify slider doesn't change opacify of slider itself as the color value may contain opacity - we need the color value without alpha.
  • Changing hue slider while color is black updates the color spectrum / color area as well.

It also noticed some issues with vertical slider mostly where click/drag to a position, sometimes the handle jumps back or move a few pixels afterwards, but we can looks at this in another PR.

@iOvergaard
Copy link
Contributor

Hi @bjarnef, thanks for your updates and yes, we'll get it reviewed 👍

@bjarnef
Copy link
Contributor Author

bjarnef commented Sep 29, 2023

I think there may be a bug in Colord, when passing in HslaColor object to the Colord instance.
omgovich/colord#116

@loivsen
Copy link
Contributor

loivsen commented Sep 29, 2023

Hey Bjarne, really great work! I have a few things that I have noticed looking at your color picker

When the color area is (for example) at a blueish tone and you drag the handle down, there is a slight color change of the color-area. See picture
color-area
The number 194 also appears twice?

Lastly, I noticed that the disabled option only disables the input itself, but you can still pick colors.

@bjarnef
Copy link
Contributor Author

bjarnef commented Sep 29, 2023

Hi @loivsen

Yes, I think it may be because of saturation: https://github.com/umbraco/Umbraco.UI/pull/536/files#diff-e26cfd40613cb37d73b2bf9ca447a92b2d7caac910979aa0dc992c7976494c0bR161

Maybe we could update it as well like with hue if value is not zero.

Regarding the duplicate 194 value, it was to output the hue in color picker (the other is inside hue slider). I will remove that.

@bjarnef
Copy link
Contributor Author

bjarnef commented Oct 2, 2023

Regarding the disabled feature its another issue, but in e.g. Codepen example of the Shoelace Color Picker, it looks something like this:
https://shoelace.style/components/color-picker

image

However it's still possible to toggle color format and pick a color via the eyedropper.

@loivsen
Copy link
Contributor

loivsen commented Oct 11, 2023

I would like to get these improvements merged in. @bjarnef can you look into the build error and then get the branch up to date as well? 😊

@bjarnef
Copy link
Contributor Author

bjarnef commented Oct 12, 2023

Hi @loivsen

I will have a look at this.
Meanwhile you could have a look at #589 but I think <uui-popover> need some changes, so "on outside click" works on what's visually is outside popover container.

@bjarnef
Copy link
Contributor Author

bjarnef commented Oct 17, 2023

@iOvergaard I tried creating a Pen to use the color picker from UI library.
I looks pretty good, but I noticed the handle position at hue and opacity slider doesn't change. Is that expected?

<script type="module" src="https://cdn.jsdelivr.net/npm/@umbraco-ui/uui@latest/dist/uui.min.js"></script>

<uui-color-picker inline opacity>
</uui-color-picker>
chrome_PFTfloSGK8.mp4

this.hue = h;
}

//this.saturation = s;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried the following here, but it seem it made the handle "jump" and bit anyway and the color spectrum seemed to be affected. When dragging the handle in the spectrum, I would expect the gradient shouldn't change.

if (s !== 0) {
    this.saturation= s;
}

@iOvergaard
Copy link
Contributor

@bjarnef that's a bit spooky, could you try with the latest RC to see if any related fixes are working?

The link is: https://cdn.jsdelivr.net/npm/@umbraco-ui/[email protected]/dist/uui.min.js

Something could also be happening in the CJS version, which your pen is using.

BTW @loivsen briefly mentioned that she thought it might not work in Firefox, did you notice if there are problems there?

@bjarnef
Copy link
Contributor Author

bjarnef commented Oct 23, 2023

@iOvergaard that didn't make a difference :)

<script type="module" src="https://cdn.jsdelivr.net/npm/@umbraco-ui/[email protected]/dist/uui.min.js"></script>

<uui-color-picker inline opacity>
</uui-color-picker>

image

It does seem the Color Picker works in Firefox as well at least when checking from https://uui.umbraco.com/

@bjarnef
Copy link
Contributor Author

bjarnef commented Nov 8, 2023

@iOvergaard do you want to have another look at this? or maybe @nielslyngsoe knows?

Although it don't quite fix this ensure issue, it also handle when hue and opacity change.
and a type in cssPropCurrentValue :)

Also any idea why the sliders doesn't work from codepen?

<script type="module" src="https://cdn.jsdelivr.net/npm/@umbraco-ui/uui@latest/dist/uui.min.js"></script>

<uui-color-picker inline opacity>
</uui-color-picker>
<script type="module" src="https://cdn.jsdelivr.net/npm/@umbraco-ui/[email protected]/dist/uui.min.js"></script>

<uui-color-picker inline opacity>
</uui-color-picker>

@bjarnef
Copy link
Contributor Author

bjarnef commented Feb 4, 2024

@iOvergaard can we merge this for now and improve later? I think this work better than the current version, but there is space for improvement.

@iOvergaard
Copy link
Contributor

@bjarnef sure thing... would you take a look at the failing build?

@bjarnef
Copy link
Contributor Author

bjarnef commented Feb 5, 2024

@iOvergaard it shows this, but it doesn't seem to be related to these changes.

image

@iOvergaard
Copy link
Contributor

@bjarnef Storybook won't deploy from forks, but still the "Tests" job is failing as well as the linter.

@bjarnef
Copy link
Contributor Author

bjarnef commented Feb 5, 2024

@iOvergaard the tests are happy now 😅

@iOvergaard iOvergaard merged commit d83b8ba into umbraco:v1/contrib Feb 5, 2024
6 of 7 checks passed
@bjarnef bjarnef deleted the bug/color-area-saturation branch February 18, 2024 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] uui-color-area: Sometimes resets coordinates when selecting a color
3 participants