mat-dialog 在 Angular Material 15 中意外地改变了 CSS。

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

mat-dialog changes css unexpectedly in Angular Material 15

问题

自 Angular Material 15 起,mat-dialog 的内容具有一些奇怪的 CSS 样式:

.mat-mdc-dialog-container .mdc-dialog__content {
    color: var(--mdc-dialog-supporting-text-color, black);
}

.mat-mdc-dialog-container .mdc-dialog__content {
    font-family: var(--mdc-dialog-supporting-text-font, "Arial");
    line-height: var(--mdc-dialog-supporting-text-line-height, 14px);
    font-size: var(--mdc-dialog-supporting-text-size, 14px);
    font-weight: var(--mdc-dialog-supporting-text-weight, 500);
    letter-spacing: var(--mdc-dialog-supporting-text-tracking, 1px);
}

这些 CSS 样式会导致每个基本文本的显示方式与应用程序的其余部分完全不同。对我来说不清楚这种行为是设计意图,还是一个 bug,或者是我在应用程序中做错了什么?

英文:

Since Angular Material 15, the content of the mat-dialog has some weird css:

.mat-mdc-dialog-container .mdc-dialog__content {
    color: var(--mdc-dialog-supporting-text-color, black);
}

.mat-mdc-dialog-container .mdc-dialog__content {
    font-family: var(--mdc-dialog-supporting-text-font, "Arial");
    line-height: var(--mdc-dialog-supporting-text-line-height, 14px);
    font-size: var(--mdc-dialog-supporting-text-size, 14px);
    font-weight: var(--mdc-dialog-supporting-text-weight, 500);
    letter-spacing: var(--mdc-dialog-supporting-text-tracking, 1px);
}

This css will cause every basic text to be displayed totally different than in the rest of the application.
For me it is not clear if this behaviour is by design, a bug or I do something wrong in my application?

答案1

得分: 0

以下是翻译好的部分:

这是我目前使用的解决方法,以防止对话框覆盖默认样式:

.mat-mdc-dialog-container .mdc-dialog__content {
  color: inherit !important;
}

.mat-mdc-dialog-container .mdc-dialog__content {
  line-height: inherit !important;
  font-size: inherit !important;
  font-weight: inherit !important;
  letter-spacing: inherit !important;
}
英文:

This is the workaround I currently use, to prevent the dialog from overwriting the default styles:

.mat-mdc-dialog-container .mdc-dialog__content {
  color: inherit !important;
}

.mat-mdc-dialog-container .mdc-dialog__content {
  line-height: inherit !important;
  font-size: inherit !important;
  font-weight: inherit !important;
  letter-spacing: inherit !important;
}

答案2

得分: 0

你正在使用自定义主题吗?在我的情况下,主题定义中缺少了typography属性:

$theme: mat.define-light-theme((
  color: (
    primary: $primary-palette,
    accent: $accent-palette,
    warn: $warn-palette,
    //border: $border-palette
  ),
  typography: mat.define-typography-config(), // 这一行
  density: 0,
));

添加了这个属性后,带有--mdc前缀的CSS变量可用,对话框组件在我的应用中看起来很好。对我来说,它还修复了一些其他模块,比如Mat-Button。

英文:

Are you using a custom theme? In my case the missing typography property in my theme definition was missing:

$theme: mat.define-light-theme((
  color: (
    primary: $primary-palette,
    accent: $accent-palette,
    warn: $warn-palette,
    //border: $border-palette
  ),
  typography: mat.define-typography-config(), // This line
  density: 0,
));

After adding the property the css variables with the --mdc prefixes are available and the application the dialog component looks good to me. For me it fixed some other modules like the Mat-Button as well.

huangapple
  • 本文由 发表于 2023年4月19日 23:22:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76056254.html
匿名

发表评论

匿名网友

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

确定