Skip to content

Commit

Permalink
[Issue-143] Fix Android browser cursor not jumping issue
Browse files Browse the repository at this point in the history
  • Loading branch information
nosir committed Jan 13, 2017
1 parent 1829976 commit 1e294e8
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 10 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"form",
"input"
],
"version": "0.7.14",
"version": "0.7.15",
"author": {
"name": "Max Huang",
"email": "[email protected]",
Expand Down
20 changes: 20 additions & 0 deletions dist/cleave-angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ return /******/ (function(modules) { // webpackBootstrap

pps.maxLength = Cleave.Util.getMaxLength(pps.blocks);

owner.isAndroid = Cleave.Util.isAndroid();

owner.onChangeListener = owner.onChange.bind(owner);
owner.onKeyDownListener = owner.onKeyDown.bind(owner);
owner.onCutListener = owner.onCut.bind(owner);
Expand Down Expand Up @@ -320,6 +322,16 @@ return /******/ (function(modules) { // webpackBootstrap
updateValueState: function () {
var owner = this;

// fix Android browser type="text" input field
// cursor not jumping issue
if (owner.isAndroid) {
window.setTimeout(function () {
owner.element.value = owner.properties.result;
}, 1);

return;
}

owner.element.value = owner.properties.result;
},

Expand Down Expand Up @@ -863,6 +875,14 @@ return /******/ (function(modules) { // webpackBootstrap
});

return result;
},

isAndroid: function () {
if (navigator && /android/i.test(navigator.userAgent)) {
return true;
}

return false;
}
};

Expand Down
4 changes: 2 additions & 2 deletions dist/cleave-angular.min.js

Large diffs are not rendered by default.

22 changes: 21 additions & 1 deletion dist/cleave-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ return /******/ (function(modules) { // webpackBootstrap

pps.maxLength = Util.getMaxLength(pps.blocks);

owner.isAndroid = Util.isAndroid();

owner.initPhoneFormatter();
owner.initDateFormatter();
owner.initNumeralFormatter();
Expand Down Expand Up @@ -348,7 +350,17 @@ return /******/ (function(modules) { // webpackBootstrap
},

updateValueState: function updateValueState() {
this.setState({ value: this.properties.result });
var owner = this;

if (owner.isAndroid) {
window.setTimeout(function () {
owner.setState({ value: owner.properties.result });
}, 1);

return;
}

owner.setState({ value: owner.properties.result });
},

render: function render() {
Expand Down Expand Up @@ -842,6 +854,14 @@ return /******/ (function(modules) { // webpackBootstrap
});

return result;
},

isAndroid: function isAndroid() {
if (navigator && /android/i.test(navigator.userAgent)) {
return true;
}

return false;
}
};

Expand Down
4 changes: 2 additions & 2 deletions dist/cleave-react.min.js

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions dist/cleave.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ return /******/ (function(modules) { // webpackBootstrap

pps.maxLength = Cleave.Util.getMaxLength(pps.blocks);

owner.isAndroid = Cleave.Util.isAndroid();

owner.onChangeListener = owner.onChange.bind(owner);
owner.onKeyDownListener = owner.onKeyDown.bind(owner);
owner.onCutListener = owner.onCut.bind(owner);
Expand Down Expand Up @@ -320,6 +322,16 @@ return /******/ (function(modules) { // webpackBootstrap
updateValueState: function () {
var owner = this;

// fix Android browser type="text" input field
// cursor not jumping issue
if (owner.isAndroid) {
window.setTimeout(function () {
owner.element.value = owner.properties.result;
}, 1);

return;
}

owner.element.value = owner.properties.result;
},

Expand Down Expand Up @@ -863,6 +875,14 @@ return /******/ (function(modules) { // webpackBootstrap
});

return result;
},

isAndroid: function () {
if (navigator && /android/i.test(navigator.userAgent)) {
return true;
}

return false;
}
};

Expand Down
4 changes: 2 additions & 2 deletions dist/cleave.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"form",
"input"
],
"version": "0.7.14",
"version": "0.7.15",
"author": {
"name": "Max Huang",
"url": "http://github.com/nosir",
Expand Down
12 changes: 12 additions & 0 deletions src/Cleave.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Cleave.prototype = {

pps.maxLength = Cleave.Util.getMaxLength(pps.blocks);

owner.isAndroid = Cleave.Util.isAndroid();

owner.onChangeListener = owner.onChange.bind(owner);
owner.onKeyDownListener = owner.onKeyDown.bind(owner);
owner.onCutListener = owner.onCut.bind(owner);
Expand Down Expand Up @@ -264,6 +266,16 @@ Cleave.prototype = {
updateValueState: function () {
var owner = this;

// fix Android browser type="text" input field
// cursor not jumping issue
if (owner.isAndroid) {
window.setTimeout(function () {
owner.element.value = owner.properties.result;
}, 1);

return;
}

owner.element.value = owner.properties.result;
},

Expand Down
14 changes: 13 additions & 1 deletion src/Cleave.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ var Cleave = React.createClass({

pps.maxLength = Util.getMaxLength(pps.blocks);

owner.isAndroid = Util.isAndroid();

owner.initPhoneFormatter();
owner.initDateFormatter();
owner.initNumeralFormatter();
Expand Down Expand Up @@ -286,7 +288,17 @@ var Cleave = React.createClass({
},

updateValueState: function () {
this.setState({value: this.properties.result});
var owner = this;

if (owner.isAndroid) {
window.setTimeout(function () {
owner.setState({value: owner.properties.result});
}, 1);

return;
}

owner.setState({value: owner.properties.result});
},

render: function () {
Expand Down
8 changes: 8 additions & 0 deletions src/utils/Util.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ var Util = {
});

return result;
},

isAndroid: function () {
if (navigator && /android/i.test(navigator.userAgent)) {
return true;
}

return false;
}
};

Expand Down

0 comments on commit 1e294e8

Please sign in to comment.