material icon indicating copy to clipboard operation
material copied to clipboard

md-datepicker to support md-prevent-menu-close

Open AaronV opened this issue 11 years ago • 8 comments

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

AaronV avatar Nov 17 '15 19:11 AaronV

@rschmukler thoughts?

jelbourn avatar Jan 05 '16 23:01 jelbourn

+1

PapyElGringo avatar Jan 12 '16 10:01 PapyElGringo

A menu item is selected but not interactive. Will not change.

ThomasBurleson avatar Jan 15 '16 00:01 ThomasBurleson

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 ?

pmoelgaard avatar Mar 26 '16 09:03 pmoelgaard

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

Drakun83 avatar Oct 26 '16 17:10 Drakun83

+1 @Drakun83 your link is dead : can you restore it ?

bpiselli avatar Feb 14 '17 00:02 bpiselli

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

alejandroSuch avatar Feb 27 '17 08:02 alejandroSuch

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>

nandopacheco avatar Oct 27 '17 01:10 nandopacheco