Skip to content

Commit

Permalink
Fixed tabIndex conflict; Fixed register of multiple listeneres for wi…
Browse files Browse the repository at this point in the history
…ndow events
  • Loading branch information
AlexKrupko committed Jun 13, 2021
1 parent e8fa81e commit a5ae3b0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
13 changes: 9 additions & 4 deletions dist/js/DatePickerX.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
titleFormatMonth : 'MM yyyy',
titleFormatYear : 'yyyy'
},
openedDPX = null;
openedDPX = null,
globalEventsInitiated = false;

/**
* Creates and returns new DOM element
Expand Down Expand Up @@ -235,7 +236,7 @@
document.querySelectorAll('[href], input, select, textarea, button, iframe, object, embed, [tabindex], [contenteditable]')
).filter(function(item)
{
return focusableElements.indexOf(item) < 0;
return focusableElements.indexOf(item) < 0 && item.tabIndex >= 0;
}).forEach(function(item)
{
item.dataset.datepickerxDisabledTabIndex = item.tabIndex;
Expand Down Expand Up @@ -267,6 +268,8 @@
{
item.tabIndex = -1;
});

openedDPX = null;
}
}

Expand All @@ -285,7 +288,7 @@
};

input.addEventListener('click', openDatePicker);
window.addEventListener('keydown', function(event)
!globalEventsInitiated && window.addEventListener('keydown', function(event)
{
if (event.keyCode === 13) {
if (document.activeElement === input) {
Expand All @@ -306,7 +309,7 @@
}
}
});
window.addEventListener('click', closeDatePicker);
!globalEventsInitiated && window.addEventListener('click', closeDatePicker);
elements.container.addEventListener('click', function(e)
{
e.stopPropagation();
Expand Down Expand Up @@ -351,6 +354,8 @@
{
dpx.setValue(null) && closeDatePicker();
});

globalEventsInitiated = true;
}

/**
Expand Down
Loading

0 comments on commit a5ae3b0

Please sign in to comment.