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

Cant type in 4 or 8 letter color names in editable input anymore #552

Open
aditigoel23 opened this issue Oct 19, 2018 · 4 comments
Open

Comments

@aditigoel23
Copy link

On the react color demo page I am able to type in "blue" into any of the editable inputs and that is recognized as valid.
Since this fix - 669bf04#diff-012ff5a8f8316a2507102ec918eaf81b
I am not able to type in 4 or 8 letter color names. They return as invalid because of the length check. So while "red" or "yellow" works fine, "blue" or "gray" doesnt.

Is there a work around for this?

@casesandberg
Copy link
Owner

I wonder if we need to revert the fix in that commit and find another solution for the problem that was solving.

@Tintef
Copy link

Tintef commented Apr 27, 2019

@casesandberg What do you think about having a list with the available colors (['red', 'blue', 'yellow', ...]) and skip the length test if the hex value is inside the list? (this will mean that it's a valid "word" color not an hex code)

@casesandberg
Copy link
Owner

@Tintef That would be a workaround but not a fix for the problem. We want to support all valid hexadecimal strings including alpha values and hexadecimal numbers.

@dreamyguy
Copy link

@casesandberg I'd like to propose using https://www.npmjs.com/package/validate-color to validate colours passed directly in the input. This package currently supports:

  • hex - #bada55
  • name - LightGoldenrodYellow
  • special name - currentColor
  • rgb - rgb(0 0 0)
  • rgba - rgba(0, 0, 0, .45)
  • hsl - hsl(4.71239rad, 60%, 70%)
  • hsla - hsla(180deg 100% 50% / .8)
  • hwb - hwb(180deg 0% 0% / 100%)
  • lab - lab(2000.1337% -8.6911 -159.131231 / .987189732)

Disclaimer though, this package is mine. Having said that, I wrote exhaustive tests on each function, that can be run separately or combined in one (ie. ValidateColor('#faa')). It is all achieved by advanced and modular regex. 🎱

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants