md-datepicker to support md-prevent-menu-close
I'd like to put a datepicker inside a menu, however the menu closes in an awkward way when clicking to open the datepicker.
http://codepen.io/anon/pen/zvbORm?editors=101
@rschmukler thoughts?
+1
A menu item is selected but not interactive. Will not change.
I need this, but can understand why it's been closed, so not disputing that, just wondering if anyone has come up with a solution ?
I came up with a workaround that is a little rough but it works for me. Here is my answer that I submitted on StackOverflow: http://stackoverflow.com/questions/35404147/md-date-picker-with-md-menu
+1 @Drakun83 your link is dead : can you restore it ?
Hi there!
Today I got to the same problem, and I created a class-restricted directive to solve this problem.
This is my directive's code:
const TRUE = 'true';
const PREVENT_CLOSE = 'md-prevent-menu-close';
class CalendarBtnFixDirective {
constructor() {
this.restrict = 'C';
this.require = '^^mdDatepicker'
}
link(scope, element, attrs, datePickerCtrl) {
const nativeElement = element[0];
const preventMenuClose = datePickerCtrl.$attrs.mdPreventMenuClose;
if ([TRUE, PREVENT_CLOSE].indexOf(preventMenuClose) !== -1) {
nativeElement.setAttribute(PREVENT_CLOSE, PREVENT_CLOSE);
}
}
}
export const MdCalendarFixModule = angular
.module('md.calendar.fix.module', [])
.directive('mdDatepickerTriangleButton', () => new CalendarBtnFixDirective())
.name;
Now in your md-datepicker you can use the md-prevent-menu-close attribute
My solution!
angular.module('app')
.directive('dontCloseMenu', function ($parse, $rootScope) {
return {
restrict: 'AC',
link: function(scope, element, attrs) {
element.find('button').attr('md-prevent-menu-close', 'md-prevent-menu-close');
}
}
});
<md-datepicker ng-model="myDate" md-placeholder="Start Date" md-is-open="isOpen" dont-close-menu ></md-datepicker>