Skip to content

Commit

Permalink
#17 - Fixed hex value validation issue
Browse files Browse the repository at this point in the history
  • Loading branch information
pIvan committed May 27, 2020
1 parent 698bf18 commit ddbc586
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
<link rel="stylesheet" href="styles.98e1b6419defcfe09605.css"></head>
<body>
<app-root></app-root>
<script src="runtime-es2015.0811dcefd377500b5b1a.js" type="module"></script><script src="runtime-es5.0811dcefd377500b5b1a.js" nomodule defer></script><script src="polyfills-es5.c219b7059a7feb126472.js" nomodule defer></script><script src="polyfills-es2015.3fd94ed6a324eee92aec.js" type="module"></script><script src="main-es2015.34cfc18e03394d18b4d1.js" type="module"></script><script src="main-es5.34cfc18e03394d18b4d1.js" nomodule defer></script></body>
<script src="runtime-es2015.0811dcefd377500b5b1a.js" type="module"></script><script src="runtime-es5.0811dcefd377500b5b1a.js" nomodule defer></script><script src="polyfills-es5.c219b7059a7feb126472.js" nomodule defer></script><script src="polyfills-es2015.3fd94ed6a324eee92aec.js" type="module"></script><script src="main-es2015.34c003b1ea2585bb6332.js" type="module"></script><script src="main-es5.34c003b1ea2585bb6332.js" nomodule defer></script></body>
</html>

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion projects/iplab/ngx-color-picker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "",
"homepage": "https://github.com/pIvan/ngx-color-picker",
"bugs": "https://github.com/pIvan/ngx-color-picker/issues",
"version": "2.0.0",
"version": "2.0.1",
"author": "Ivan Pintar",
"license": "MIT",
"readmeFilename": "README.md",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ export class HexComponent {
const value = inputValue.toLowerCase().replace('#', '');
if (value.length === 3 || value.length === 6 || value.length === 8) {
const hex = parseInt(value, 16);
const hexStr = hex.toString(16);

/**
* if value is valid
* change color else do nothing
* after parsing number leading 0 is removed,
* compare length and add leading 0 before comparing two values
*/
if (hex.toString(16) === value && this.value !== value) {
if (hexStr.padStart(value.length, '0') === value && this.value !== value) {
const newColor = new Color(`#${value}`);
const hue = new Color().setHsva(newColor.getHsva().hue);
this.hueChange.emit(hue);
Expand Down

0 comments on commit ddbc586

Please sign in to comment.