Skip to content

Commit

Permalink
Fixed #293
Browse files Browse the repository at this point in the history
  • Loading branch information
mertsincan committed Jan 24, 2018
1 parent 7fcfe91 commit 360fa05
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/components/spinner/Spinner.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class Spinner extends Component {
this.onInputKeyUp = this.onInputKeyUp.bind(this);
this.onInputKeyDown = this.onInputKeyDown.bind(this);
this.onInputKeyPress = this.onInputKeyPress.bind(this);
this.onInputBlur = this.onInputBlur.bind(this);
this.onChange = this.onChange.bind(this);

this.onUpButtonMouseLeave = this.onUpButtonMouseLeave.bind(this);
Expand Down Expand Up @@ -111,6 +112,15 @@ export class Spinner extends Component {
return String(Math.round(value * power) / power);
}

updateValue(val) {
if(this.precision) {
return this.parseValue(parseFloat(val).toFixed(this.precision));
}
else {
return val;
}
}

onUpButtonMouseDown(event) {
if (!this.props.disabled) {
this.inputEl.focus();
Expand Down Expand Up @@ -218,6 +228,26 @@ export class Spinner extends Component {
this.updateFilledState();
}

onInputBlur(event) {
let val = this.value;
if(val !== undefined && val != null) {
this.value = this.updateValue(val);
}

this.formatValue();
this.updateFilledState();

if(this.inputEl.value !== this.valueAsString) {
this.inputEl.value = this.valueAsString;

if (this.props.onChange) {
this.props.onChange({
value: this.value
})
}
}
}

parseValue(val) {
let value;
val = val.split(this.props.thousandSeparator).join('');
Expand Down Expand Up @@ -279,7 +309,11 @@ export class Spinner extends Component {
}

componentWillMount() {
this.value = this.props.value;
let val = this.props.value;
if(val !== undefined && val != null) {
this.value = this.updateValue(val);
}

this.formatValue();
this.updateFilledState();
}
Expand Down

0 comments on commit 360fa05

Please sign in to comment.