Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open datepicker from outside #95

Open
ilyakrasnov opened this issue May 17, 2017 · 2 comments
Open

Open datepicker from outside #95

ilyakrasnov opened this issue May 17, 2017 · 2 comments

Comments

@ilyakrasnov
Copy link

We use the component inside a div with and have an icon next to it. I'd like to open the datepicker by clicking on the icon. Is there a way to do it like this:

<md-icon id='date_icon' (click)="datepicker.onInputClick()">date_range</md-icon>
<material-datepicker #datepicker
                     [date]="initialDate"
                     formControlName="date"
></material-datepicker>

I tried it like this so far this way and also by accessing it from the parent component - does not work in both cases.

It would be great to have an API endpoint exposing the trigger method.

Thanks a lot!

@joshuaohana
Copy link

joshuaohana commented Jun 17, 2017

I'm trying the same thing.
I've tried all manner of playing with elementRefs to no avail

Example of stuff that doesn't work
const ref = this.datepicker.elementRef;
const input = ref.nativeElement.querySelector('input');
input.click();
this.datepicker.onInputClick();

@RiccardoGai
Copy link

@ilyakrasnov @joshuaohana i sorted out

<material-datepicker #datepicker [(date)]="date" (onSelect)="changeDate($event)" ></material-datepicker>
<button (click)='test($event, datepicker)'>test</button>

and on the .ts

 public test(event: Event, datepicker: any): void {
    event.stopPropagation()
    datepicker.showCalendar = !datepicker.showCalendar
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants