Skip to content

Commit

Permalink
Fix(InputItem): add try catch to setSelection (#3120) (#3124)
Browse files Browse the repository at this point in the history
* Fix(InputItem): add try catch to setSelection (#3120)

* Doc(InputItem): add MDN link
  • Loading branch information
zack24q authored and doxiaodong committed Mar 21, 2019
1 parent 9359453 commit 05b9d86
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion components/input-item/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,12 @@ class InputItem extends React.Component<InputItemProps, any> {
case 'phone':
case 'number':
// controlled input type needs to adjust the position of the caret
el.selectionStart = el.selectionEnd = this.calcPos(prePos || 0, preCtrlVal, rawVal, ctrlValue, [' '], /\D/g)
try {
// set selection may throw error (https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/setSelectionRange)
el.selectionStart = el.selectionEnd = this.calcPos(prePos || 0, preCtrlVal, rawVal, ctrlValue, [' '], /\D/g);
} catch (error) {
console.warn('Set selection error:', error);
}
break;
default:
break;
Expand Down

0 comments on commit 05b9d86

Please sign in to comment.