Skip to content

Commit

Permalink
Add support for tab key
Browse files Browse the repository at this point in the history
- Fixes #8
- Adds a blur event to the input so that the calendar will hide when the tab key is used
- Change the calendar click to a mousedown event instead, since blur was firing before click causing the calendar to hide before the event finished
  • Loading branch information
joshsalverda committed Apr 8, 2015
1 parent 36d46cd commit e4d9816
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
19 changes: 10 additions & 9 deletions src/datepickr.js
Expand Up @@ -77,7 +77,6 @@ datepickr.init = function (element, instanceConfig) {
documentClick,
calendarClick,
buildCalendar,
getOpenEvent,
bind,
open,
close,
Expand Down Expand Up @@ -368,16 +367,16 @@ datepickr.init = function (element, instanceConfig) {
wrapperElement.appendChild(calendarContainer);
};

getOpenEvent = function () {
bind = function () {
var openEvent = 'click';

if (self.element.nodeName === 'INPUT') {
return 'focus';
openEvent = 'focus';
self.addEventListener(self.element, 'blur', close, false);
}
return 'click';
};

bind = function () {
self.addEventListener(self.element, getOpenEvent(), open, false);
self.addEventListener(calendarContainer, 'click', calendarClick, false);
self.addEventListener(self.element, openEvent, open, false);
self.addEventListener(calendarContainer, 'mousedown', calendarClick, false);
};

open = function () {
Expand All @@ -395,7 +394,9 @@ datepickr.init = function (element, instanceConfig) {
element;

self.removeEventListener(document, 'click', documentClick, false);
self.removeEventListener(self.element, getOpenEvent(), open, false);
self.removeEventListener(self.element, 'focus', open, false);
self.removeEventListener(self.element, 'blur', close, false);
self.removeEventListener(self.element, 'click', open, false);

parent = self.element.parentNode;
parent.removeChild(calendarContainer);
Expand Down
19 changes: 10 additions & 9 deletions src/datepickr.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e4d9816

Please sign in to comment.