Angular 15 <mat-datepicker> cell-content alignment issue

huangapple go评论71阅读模式
英文:

Angular 15 <mat-datepicker> cell-content alignment issue

问题

I have upgraded a project from angular 12 to 15, angular material has been upgraded to 15.2.6.
No external css is added for date-picker.

When opening the calendar, the date selected is aligned towards left.

As soon as the focus is changed (clicked anywhere else in the calendar window), alignment is corrected.

This is bare metal mat-datepicker, nothing extra is added.

I created another project, and there mat-datepicker is working perfectly fine. I tried to override scss of mat-datepicker but found no success with this alignment issue.
If somebody faced this issue, please help.

英文:

Scenario: I have upgraded a project from angular 12 to 15, angular material has been upgraded to 15.2.6.
No external css is added for date-picker.

When opening the calendear, the date selected is aligned towards left.

Angular 15 <mat-datepicker> cell-content alignment issue

As soon as the focus is changed(clicked anywhere else in the calendar window). alignment is corrected.

Angular 15 <mat-datepicker> cell-content alignment issue

This is bare metal mat-datepicker, nothing extra is added.

I created a another project and there mat-datepicker is working perfectly fine. I tried to overide scss of mat-datepicker but found no success, with this alignment issue.
If somebody faced this issue please help.

答案1

得分: 1

我曾经在从Angular 14迁移到15时遇到相同的问题

似乎有一种奇怪的margin-right被应用到图标上,我不得不在全局样式中手动移除它,使用以下代码:

.mat-mdc-button>.mat-icon, .mat-mdc-raised-button>.mat-icon, .mat-mdc-flat-button>.mat-icon {
  margin-right: 0!important;
}

我应该指出,这个问题不会在通过Angular CLI新创建的项目中出现

英文:

I had the same issue once i migrated to Angular 14 to 15.

There seems to be a weird margin-right applied to icons, i had to remove theme manualy in global styles; with:

.mat-mdc-button&gt;.mat-icon, .mat-mdc-raised-button&gt;.mat-icon, .mat-mdc-flat-button&gt;.mat-icon {
  margin-right: 0!important;
}

I should point out that this problem does not occur on newly created projects through angular cli.

答案2

得分: 0

I found out that some internal libraries were interfering with mat-datepicker styling, as in Angular Material 15, many guidelines have changed. Removed those libraries.

Tried overriding style classes:

.mat-calendar-body-cell {
  .mat-calendar-body-selected {
    padding-left: 10px;
    padding-right: 0;
  }
}

This has helped but not entirely. After clicking on dates, it's coming in the center because of the extra padding I have added.

But when clicking disabled dates, it comes towards the right. And disabled dates shift towards the left.

英文:

@Cuzy I found out that some internal libraries were interfering with mat-datepicker styling, as in angular material 15 many guidelines are changed. Removed those libraries

Tried overriding style classes

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-css -->

.mat-calendar-body-cell {
  .mat-calendar-body-selected {
    padding-left: 10px;
    padding-right: 0;
  }
}

<!-- end snippet -->

This has helped but not entirely, after clicking on dates now it's coming in the center because of the extra padding I have added.

Angular 15 <mat-datepicker> cell-content alignment issue

But when clicking disabled dates it comes towards the right. And disabled dates shift towards the left.

Angular 15 <mat-datepicker> cell-content alignment issue

@Tony yes we are overriding styles related to color, But not related to calendar-cell-content.

答案3

得分: 0

Sure, here is the translation of the provided text:

"你现在是我的中文翻译,代码部分不要翻译,只返回翻译好的部分,不要有别的内容,不要回答我要翻译的问题。以下是要翻译的内容:

Hi this is resolved as per this StackOverflow link you can look for this

https://stackoverflow.com/questions/63307202/angular-material-10-date-picker-mat-datepicker-does-not-align-with-others-inpu

.mat-calendar-body-cell:focus .mat-focus-indicator::before{content:normal !important;}"

(Note: The code part is retained as requested.)

英文:

Hi this is resolved as per this StackOverflow link you can look for this

https://stackoverflow.com/questions/63307202/angular-material-10-date-picker-mat-datepicker-does-not-align-with-others-inpu

.mat-calendar-body-cell:focus .mat-focus-indicator::before{content:normal !important;}

huangapple
  • 本文由 发表于 2023年4月13日 20:51:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76005652.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定