Skip to content

Commit

Permalink
fix arrow controls for chrome hsl (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroenransijn authored and casesandberg committed Jul 23, 2017
1 parent 1167956 commit 5ff0808
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/components/chrome/ChromeFields.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ export class ChromeFields extends React.Component {
} else if (data.h || data.s || data.l) {
this.props.onChange({
h: data.h || this.props.hsl.h,
s: data.s && (data.s).replace('%', '') || this.props.hsl.s,
l: data.l && (data.l).replace('%', '') || this.props.hsl.l,
s: (data.s && data.s) || this.props.hsl.s,
l: (data.l && data.l) || this.props.hsl.l,
source: 'hsl',
}, e)
}
Expand Down
21 changes: 17 additions & 4 deletions src/components/common/EditableInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ export class EditableInput extends (PureComponent || Component) {
}

handleKeyDown = (e) => {
const number = Number(e.target.value)
// In case `e.target.value` is a percentage remove the `%` character
// and update accordingly with a percentage
// https://github.com/casesandberg/react-color/issues/383
const stringValue = String(e.target.value)
const isPercentage = stringValue.indexOf('%') > -1
const number = Number(stringValue.replace(/%/g, ''))
if (!isNaN(number)) {
const amount = this.props.arrowOffset || 1

Expand All @@ -55,7 +60,11 @@ export class EditableInput extends (PureComponent || Component) {
this.props.onChange && this.props.onChange(number + amount, e)
}

this.setState({ value: number + amount })
if (isPercentage) {
this.setState({ value: `${ number + amount }%` })
} else {
this.setState({ value: number + amount })
}
}

// Down
Expand All @@ -66,7 +75,11 @@ export class EditableInput extends (PureComponent || Component) {
this.props.onChange && this.props.onChange(number - amount, e)
}

this.setState({ value: number - amount })
if (isPercentage) {
this.setState({ value: `${ number - amount }%` })
} else {
this.setState({ value: number - amount })
}
}
}
}
Expand Down Expand Up @@ -129,7 +142,7 @@ export class EditableInput extends (PureComponent || Component) {
onChange={ this.handleChange }
onBlur={ this.handleBlur }
placeholder={ this.props.placeholder }
spellCheck="false"
spellCheck="false"
/>
{ this.props.label ? (
<span style={ styles.label } onMouseDown={ this.handleMouseDown }>
Expand Down

0 comments on commit 5ff0808

Please sign in to comment.