Skip to content

Commit ea36c55

Browse files
committed
Fix typing over values on Internet Explorer 11
1 parent 3c7dd3b commit ea36c55

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/DateInput/Input.jsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,20 @@ function updateInputWidthOnFontLoad(element) {
4747
document.fonts.addEventListener('loadingdone', onLoadingDone);
4848
}
4949

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();
5361
}
5462

55-
return window.getSelection().toString();
63+
return null;
5664
}
5765

5866
function makeOnKeyPress(maxLength) {
@@ -65,7 +73,7 @@ function makeOnKeyPress(maxLength) {
6573
const { value } = input;
6674

6775
const isNumberKey = !isNaN(parseInt(key, 10));
68-
const selection = getSelectionString();
76+
const selection = getSelectionString(input);
6977

7078
if (isNumberKey && (selection || value.length < maxLength)) {
7179
return;

0 commit comments

Comments
 (0)