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
Uniform full length hex input like #ffffff is not preserved on output from .toHexString() #8
Comments
If you agree a fix is in order and have a preference on which approach you'd prefer, I'd be happy to submit a pull request, otherwise feel free to close as "will not fix" if you don't feel this is an issue worthy of addressing. |
Shortening if possible has been the default behavior since it was first built. However, this issue has been brought up a couple of times in the last few weeks. I have a modified version of TinyColor within spectrum that can do
Thoughts? |
I did eventually find the undocumented 'hex6' option in Spectrum, and this has solved my issue entirely. In my case, the data I am using to populate the spectrum
If it had been my project, I probably would have never implemented the shortening step to begin with so as to guarantee that the app always returned a consistent 6-char hex value, but that doesn't necessarily help address the question now. |
Thanks for the thoughts. I don't really mind slightly breaking backwards compatibility with a "version 1.0" as long as it is easy to resolve the problem (like setting That said, if we switched the default to 6 character, wouldn't you have the same problem come up if you inputted a 3 character and called toHexString() on it (since you would now be getting a 6 character return value). |
Yes, I was actually already drafting this update specifically in response to your point about I think this preservation is actually more important for Spectrum than TinyColor. Given that the only data supplied to the event handlers is the color selected, it's the only resource a programmer has to "find" any other related information they may need to use. Preserving the palette input precisely in the event it is hex might be more critical although this obviously complicates the code a bit. That actually reminds me too-- I have a feature request I will post separately. |
So the proposal is for |
Also, @beporter returning exactly the original string is not always possible or desirable. For instance,
In that case, it cleans up some of your formatting and normalizes it to a standard output format. I see where you would be wanting to use hexes as identifiers though. I have added the following functionality inside spectrum, which I could port back into tinycolor if you think it would solve your issue:
|
You're right that there is ambiguity abound in this topic. I don't believe any of us are going to be able to fully resolve it. (Let's not even talk about #FFFFFF vs. #ffffff!) The reason I prefer 6-char hex strings is because they are not special cases and don't need to be treated differently. #ffcc00 may be more verbose strictly than necessary, but it's just as accurate and (marginally) easier to shorten to 3 chars after the fact than it would be to length a shorthand value back up to 6. As for the result of creating a TinyColor with rgba and outputting the hex value-- I don't see any need to maintain input/output fidelity there because the format is already different and you'd explicitly be performing a format conversion. I was only concerned with hex in/out. Bottom line though is that as I mentioned in my comment from the 19th, the (undocumented) |
Yeah I understand your point about 6 character hex strings not having special cases. I think that we can add the option to |
If you create a new
tinycolor('#ffffff')
, the result of.toHexString()
is'#fff'
and does not match the input. See this fiddle for an example: http://jsfiddle.net/2va59/3/This causes problems if you happened to be keying an object by hex value, for example, and depend on the output of TinyColor (via the Spectrum color picker, btw) to look up the correct values.
{"#e55731":{"field":"9","detail":"386"},"#ffffff":{"field":"15","detail":"387"})
The simple solution is to disable this if() statement entirely, but I could see an argument for an alternative
.toFullHexString()
method or an passing an optional argument (in pseudo-code) along the lines of.toHexString(bool shortenHexIfPossible = false)
as well.The text was updated successfully, but these errors were encountered: