Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
fix(datepicker): solve refocusing problems
Browse files Browse the repository at this point in the history
* Fixes the datepicker not being able to refocus on the calendar icon, because the SVG element inside didn't propagate the focus event.
* Fixes the datepicker sometimes not refocusing on the element that triggered it.

Fixes #8960.

Closes #9080
  • Loading branch information
crisbeto authored and ThomasBurleson committed Jul 20, 2016
1 parent 3709f9b commit 0356bed
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
13 changes: 13 additions & 0 deletions src/components/datepicker/datePicker.scss
Expand Up @@ -33,6 +33,19 @@ md-datepicker {
box-sizing: border-box;
background: none;
vertical-align: middle;
position: relative;

// Captures any of the click events. This is necessary, because the button has a SVG
// icon which doesn't propagate the focus event, causing inconsistent behaviour.
&:before {
top: 0;
left: 0;
bottom: 0;
right: 0;
position: absolute;
content: '';
speak: none;
}
}

// The input into which the user can type the date.
Expand Down
19 changes: 10 additions & 9 deletions src/components/datepicker/js/datepickerDirective.js
Expand Up @@ -682,28 +682,29 @@
if (this.isCalendarOpen) {
var self = this;

self.detachCalendarPane();
self.ngModelCtrl.$setTouched();

self.documentElement.off('click touchstart', self.bodyClickHandler);
window.removeEventListener('resize', self.windowResizeHandler);

self.calendarPaneOpenedFrom.focus();
self.calendarPaneOpenedFrom = null;

if (self.openOnFocus) {
// Ensures that all focus events have fired before detaching
// Ensures that all focus events have fired before resetting
// the calendar. Prevents the calendar from reopening immediately
// in IE when md-open-on-focus is set. Also it needs to trigger
// a digest, in order to prevent issues where the calendar wasn't
// showing up on the next open.
this.$mdUtil.nextTick(detach);
self.$mdUtil.nextTick(reset);
} else {
detach();
reset();
}
}

function detach() {
self.detachCalendarPane();
function reset(){
self.isCalendarOpen = self.isOpen = false;
self.ngModelCtrl.$setTouched();

self.documentElement.off('click touchstart', self.bodyClickHandler);
window.removeEventListener('resize', self.windowResizeHandler);
}
};

Expand Down

0 comments on commit 0356bed

Please sign in to comment.