Skip to content

Commit

Permalink
#55 / EDGE: Incorrect handling of non-text input fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Maximilian committed Jan 26, 2019
1 parent 93a646a commit 4841810
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
9 changes: 6 additions & 3 deletions datalist-polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@
}

// Handling IE10+ & EDGE
if (isGteIE10 || isEDGE) {
// As only EDGE doesn't trigger the input event after selecting an item via mouse, we need to differentiate here
if (isGteIE10 || (isEDGE && input.type === 'text')) {
// On keypress check for value
if (
getInputValue(input) !== '' &&
Expand Down Expand Up @@ -302,15 +303,17 @@

input.addEventListener('focusout', changesInputList, true);

if (isGteIE10 || isEDGE) {
// As only EDGE doesn't trigger the input event after selecting an item via mouse, we need to differentiate here
if (isGteIE10 || (isEDGE && input.type === 'text')) {
input.addEventListener('input', inputInputListIE);
}
} else if (eventType === 'blur') {
input.removeEventListener('keyup', inputInputList);

input.removeEventListener('focusout', changesInputList, true);

if (isGteIE10 || isEDGE) {
// As only EDGE doesn't trigger the input event after selecting an item via mouse, we need to differentiate here
if (isGteIE10 || (isEDGE && input.type === 'text')) {
input.removeEventListener('input', inputInputListIE);
}
}
Expand Down
9 changes: 7 additions & 2 deletions datalist-polyfill.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ var n=function(e){var t=e.target,a=t.list,i=e.keyCode===y||e.keyCode===f;
// Check for whether the events target was an input and still check for an existing instance of the datalist and polyfilling select
if("input"===t.tagName.toLowerCase()&&null!==a)
// Handling IE10+ & EDGE
if(s||d)
// As only EDGE doesn't trigger the input event after selecting an item via mouse, we need to differentiate here
if(s||d&&"text"===t.type)
// On keypress check for value
""===L(t)||i||e.keyCode===c||e.keyCode===v||(b(t,a),
// TODO: Check whether this update is necessary depending on the options values
Expand Down Expand Up @@ -110,7 +111,11 @@ e.setAttribute("autocomplete","off"),
// WAI ARIA attributes
e.setAttribute("role","textbox"),e.setAttribute("aria-haspopup","true"),e.setAttribute("aria-autocomplete","list"),e.setAttribute("aria-owns",e.getAttribute("list")),
// Bind the keyup event on the related datalists input
"focusin"===t?(e.addEventListener("keyup",n),e.addEventListener("focusout",E,!0),(s||d)&&e.addEventListener("input",h)):"blur"===t&&(e.removeEventListener("keyup",n),e.removeEventListener("focusout",E,!0),(s||d)&&e.removeEventListener("input",h)),
"focusin"===t?(e.addEventListener("keyup",n),e.addEventListener("focusout",E,!0),
// As only EDGE doesn't trigger the input event after selecting an item via mouse, we need to differentiate here
(s||d&&"text"===e.type)&&e.addEventListener("input",h)):"blur"===t&&(e.removeEventListener("keyup",n),e.removeEventListener("focusout",E,!0),
// As only EDGE doesn't trigger the input event after selecting an item via mouse, we need to differentiate here
(s||d&&"text"===e.type)&&e.removeEventListener("input",h)),
// Add class for identifying that this input is even already being polyfilled
e.className+=" "+o},L=function(e){
// In case of type=email and multiple attribute, we would need to grab the last piece
Expand Down

0 comments on commit 4841810

Please sign in to comment.