angular / angular/components

bug(mat-text-column): Column-name based CSS ignored unless view encapsulation is disabled

未关闭
#24,893 3 条评论 2 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

area: material/table P4
主要语言
TypeScript
星标
25k
派生
6.8k
平均合并
1 天 8 小时
30 天内合并 PR
91

描述

### Is this a regression?

- [ ] Yes, this behavior used to work in the previous version

### The previous version in which this bug was not present was

_No response_

### Description

May not technically be a bug, and more of an undocumented quirk.

There are two aspects to mat-table column definitions that lead to an unexpected conclusion:

- For a column named `foo`, you can define a `.mat-column-foo` style which will get applied to it.
- A `mat-text-column` named `foo` is shorthand for an explicit matColumnDef with sensible defaults for a text-only field.

However, if you define said style, and try to apply it to a mat-text-column, it won't match.

I supppose that technically, the affected th/td elements are no longer generated by the parent view, but by mat-text-node itself - and thus, those are outside the scope of view-encapsulated styles defined there.

The fix may not be trivial, but it might still be worth documenting as a gotcha.

### Reproduction

See StackBlitz [here](https://stackblitz.com/edit/components-issue-e4h1lq?file=src/app/example-component.ts). By making the component non-encapsulated, the style applies to both columns. Otherwise, it only matches the explicitly defined one, not the text-column.

### Expected Behavior

Styles affect matColumnDefs and mat-text-columns the same way.

### Actual Behavior

...they don't!

### Environment

Angular CLI: 13.3.5
Node: 14.17.6
Package Manager: yarn 1.22.15
OS: win32 x64

Angular: 13.3.6

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从链接的 StackBlitz 复现开始,检查 src/app/example-component.ts,对比 view encapsulation 下显式定义的 matColumnDef 与 mat-text-column。确认样式不匹配,并确定预期结果是修复组件还是记录该行为;完成的标准是两种列类型获得等效样式,或记录该限制。

由索引模型根据 Issue 内容生成。

评估

技术栈
angular, typescript
领域
frontend
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
38/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。