0

This is html file:

<mat-form-field>
  <input matInput [matDatepicker]="picker" placeholder="Choose a date">
  <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
  <mat-datepicker #picker></mat-datepicker>
</mat-form-field>

and datepicker is calling by clicking to icon (mat-datepicker-toggle). -> enter image description here

but I want that datepicker will be called by clicking to input without icon like this enter image description here

Here is example angular datepicker -> https://stackblitz.com/angular/xvjleypolka?file=src%2Fapp%2Fdatepicker-overview-example.html If you have another way to integrate datepicker to input in angular welcome

1

3 Answers 3

2

Use like bellow:

<mat-form-field>
  <input matInput [matDatepicker]="picker" placeholder="Choose a date" 
  (click)="picker.open()">
  <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
  <mat-datepicker #picker></mat-datepicker>
</mat-form-field>

Working DEMO

Sign up to request clarification or add additional context in comments.

Comments

1

You can just add (focus)="picker.open()"

Try like this:

<mat-form-field>
  <input matInput [matDatepicker]="picker" placeholder="Choose a date"  (focus)="picker.open()">
  <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
  <mat-datepicker #picker></mat-datepicker>
</mat-form-field>

Working Demo

2 Comments

I guess i can also add (click)="picker.open()" ?
Using (click)="picker.open()" would actually be better, in my opinion. This way it will open the DatePicker every time you click on the input. Otherwise, if the input field is already focused, the DatePicker will not open on click.
1

MatDatePicker have open method to open it manually.

So just use it on focus of an input (focus)="picker.open()"

<mat-form-field>
  <input matInput (focus)="picker.open()" [matDatepicker]="picker" placeholder="Choose a date">
  <mat-datepicker-toggle matSuffix [for]="picker"></mat-datepicker-toggle>
  <mat-datepicker #picker></mat-datepicker>
</mat-form-field>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.