File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -47,12 +47,20 @@ function updateInputWidthOnFontLoad(element) {
47
47
document . fonts . addEventListener ( 'loadingdone' , onLoadingDone ) ;
48
48
}
49
49
50
- function getSelectionString ( ) {
51
- if ( typeof window === 'undefined' ) {
52
- return null ;
50
+ function getSelectionString ( input ) {
51
+ /**
52
+ * window.getSelection().toString() returns empty string in IE11 and Firefox,
53
+ * so alternatives come first.
54
+ */
55
+ if ( input && 'selectionStart' in input && input . selectionStart !== null ) {
56
+ return input . value . slice ( input . selectionStart , input . selectionEnd ) ;
57
+ }
58
+
59
+ if ( 'getSelection' in window ) {
60
+ return window . getSelection ( ) . toString ( ) ;
53
61
}
54
62
55
- return window . getSelection ( ) . toString ( ) ;
63
+ return null ;
56
64
}
57
65
58
66
function makeOnKeyPress ( maxLength ) {
@@ -65,7 +73,7 @@ function makeOnKeyPress(maxLength) {
65
73
const { value } = input ;
66
74
67
75
const isNumberKey = ! isNaN ( parseInt ( key , 10 ) ) ;
68
- const selection = getSelectionString ( ) ;
76
+ const selection = getSelectionString ( input ) ;
69
77
70
78
if ( isNumberKey && ( selection || value . length < maxLength ) ) {
71
79
return ;
You can’t perform that action at this time.
0 commit comments