You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think I've encountered a bug with the ColorPicker , or perhaps the utility hsbToHex. Using only the HueSlider I'm ending up with a value of #NaNNaNNan. Initially posted in the Polaris slack channel.
Expected behavior
Clicking on only the HueSlider should not output the value of #NaNNaNNan. I would expect it to either choose some default value that's appropriate for that part of the slider or to not output any value until an actual color is chosen in the left main area of the ColorPicker (unsure of the name of this part -- Slidable?).
Actual behavior
Here's a video showing what actually happens. When you click only on the HueSlider and nowhere else, the value of #NaNNanNan gets outputted.
Looks like most recent change to the actual Polaris ColorPicker component was 4 months ago. web's shared ColorPicker > TextPicker had changes on 8/30/2023, but they seem to be translation related, so unconnected?
I have traced it down to some utilities, I think, but none of them have changed recently. Unsure why this is happening now (or maybe it always did?) In ColorEdit we get a value back from the color picker such as {hue: 190.7462686567164, brightness: NaN, saturation: NaN, alpha: 1} and pass that to a utility from Polaris called hsbToHex. That utility is returning the #NaNNanNan value. Internally, hbsToHex calls hsbToRgb, and that is converting the value above to {red: NaN, green: NaN, blue: NaN, alpha: 1} , which is then trying to parse the red/green/blue NaN values.
Start a new spin instance (or use mine/any that already has a color metafield, and skip to step 5.)
Go to Settings > Custom Data. Then select Products under Metafields.
Click Add Definition. Create a new definition with the name "Color Picker Test", and select Color for the Type. You can ignore the other options. Click Save.
Close the Settings modal
Cick on Products. Select whatever product is first to go to the Product Details Page for that product.
After it fully loads, scroll to bottom and look for the Metafields section. Click on the link Show all in top right of that card.
Start with an empty value for the "Color Picker Test" metafield you created. If needed, you can click on the field for that metafield, then click Clear to remove any previous value.
With the metafield empty of any value, click on the field. A color picker should appear in a popover. Click on the vertical HueSlider, but do not click anywhere else.
You should now have #NaNNaNNaN in the value field of the metafield.
For the reduced test case
Open the browser console to see logs.
Click on the TextField. Do not enter a value.
Click on the HueSlider. Do no click anywhere else.
Browser: Chrome Version 116.0.5845.140 (Official Build) (arm64)
Device: Macbook M1 Pro 14-inch, 2021
Operating System: MacOS 13.5.1 (22G90)
Or run npx envinfo --system --binaries --browsers --npmPackages react,react-dom,@shopify/polaris to provide specifications on your environment including version numbers, browser, device, and operating system.
Can you take this on and open a PR @shopifybradleystaples? I'd be happy to review. I think these utilities were built, or more likely copied, from some resource like 5 years ago. I'd be happy to review
Issue summary
I think I've encountered a bug with the
ColorPicker
, or perhaps the utilityhsbToHex
. Using only theHueSlider
I'm ending up with a value of #NaNNaNNan. Initially posted in the Polaris slack channel.Expected behavior
Clicking on only the
HueSlider
should not output the value of #NaNNaNNan. I would expect it to either choose some default value that's appropriate for that part of the slider or to not output any value until an actual color is chosen in the left main area of theColorPicker
(unsure of the name of this part --Slidable
?).Actual behavior
Here's a video showing what actually happens. When you click only on the
HueSlider
and nowhere else, the value of #NaNNanNan gets outputted.Looks like most recent change to the actual Polaris ColorPicker component was 4 months ago.
web
's sharedColorPicker
> TextPicker had changes on 8/30/2023, but they seem to be translation related, so unconnected?I have traced it down to some utilities, I think, but none of them have changed recently. Unsure why this is happening now (or maybe it always did?) In ColorEdit we get a value back from the color picker such as
{hue: 190.7462686567164, brightness: NaN, saturation: NaN, alpha: 1}
and pass that to a utility from Polaris called hsbToHex. That utility is returning the #NaNNanNan value. Internally,hbsToHex
callshsbToRgb
, and that is converting the value above to{red: NaN, green: NaN, blue: NaN, alpha: 1}
, which is then trying to parse the red/green/blue NaN values.Steps to reproduce the problem
For a spin instance
I have duplicated this on a color metafield on my staff store in production, but also have a spin instance at https://admin.web.color-picker-bug.bradley-staples.us.spin.dev/store/shop1/products/1/metafields to show it as well.
Settings
>Custom Data
. Then selectProducts
underMetafields
.Add Definition
. Create a new definition with the name "Color Picker Test", and selectColor
for the Type. You can ignore the other options. ClickSave
.Settings
modalProducts
. Select whatever product is first to go to the Product Details Page for that product.Metafields
section. Click on the linkShow all
in top right of that card.Clear
to remove any previous value.HueSlider
, but do not click anywhere else.For the reduced test case
TextField
. Do not enter a value.HueSlider
. Do no click anywhere else.TextField
has a value of #NaNNaNNanReduced test case
https://codesandbox.io/s/shopify-polaris-react-typescript-playground-forked-wdmxdh?file=/src/index.tsx
Specifications
Or run
npx envinfo --system --binaries --browsers --npmPackages react,react-dom,@shopify/polaris
to provide specifications on your environment including version numbers, browser, device, and operating system.Paste the results here:
The text was updated successfully, but these errors were encountered: