From d97d4d702a4ecd926dfabdf8b31db2014b4211d2 Mon Sep 17 00:00:00 2001 From: case Date: Sun, 3 May 2020 16:45:12 -0700 Subject: [PATCH] Fix EdibleInput from rejecting 0% and 1% (#709) Fixes https://github.com/casesandberg/react-color/issues/707 --- src/components/chrome/ChromeFields.js | 16 ++++++++++++---- src/components/common/EditableInput.js | 1 - 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/components/chrome/ChromeFields.js b/src/components/chrome/ChromeFields.js index 48aa76bb..f7204cab 100644 --- a/src/components/chrome/ChromeFields.js +++ b/src/components/chrome/ChromeFields.js @@ -3,6 +3,7 @@ import React from 'react' import reactCSS from 'reactcss' import color from '../../helpers/color' +import isUndefined from 'lodash/isUndefined' import { EditableInput } from '../common' import UnfoldMoreHorizontalIcon from '@icons/material/UnfoldMoreHorizontalIcon' @@ -72,13 +73,20 @@ export class ChromeFields extends React.Component { }, e) } else if (data.h || data.s || data.l) { // Remove any occurances of '%'. - if (typeof(data.s) === 'string' && data.s.includes('%')) { data.s = data.s.replace('%', '') } + if (typeof(data.s) === 'string' && data.s.includes('%')) { data.s = data.s.replace('%', '') } if (typeof(data.l) === 'string' && data.l.includes('%')) { data.l = data.l.replace('%', '') } - + + // We store HSL as a unit interval so we need to override the 1 input to 0.01 + if (data.s == 1) { + data.s = 0.01 + } else if (data.l == 1) { + data.l = 0.01 + } + this.props.onChange({ h: data.h || this.props.hsl.h, - s: Number((data.s && data.s) || this.props.hsl.s), - l: Number((data.l && data.l) || this.props.hsl.l), + s: Number(!isUndefined(data.s) ? data.s : this.props.hsl.s), + l: Number(!isUndefined(data.l) ? data.l : this.props.hsl.l), source: 'hsl', }, e) } diff --git a/src/components/common/EditableInput.js b/src/components/common/EditableInput.js index 7da62b7d..f37089c4 100644 --- a/src/components/common/EditableInput.js +++ b/src/components/common/EditableInput.js @@ -52,7 +52,6 @@ export class EditableInput extends (PureComponent || Component) { } handleChange = (e) => { - console.log(e.target.value) this.setUpdatedValue(e.target.value, e) }