angular / angular/components

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

オープン
#24,893 コメント 3 件 リアクション 2 件 担当者 0 名 GitHub で見る
area: material/table P4
主要言語
TypeScript
スター
25k
フォーク
6.8k
平均マージ
1日 8時間
マージ済み PR(30日)
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

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

リンクされた StackBlitz の再現から始め、src/app/example-component.ts を調査し、view encapsulation 下で明示的に定義された matColumnDef と mat-text-column を比較します。スタイルの不一致を確認し、意図された結果がコンポーネントの修正なのか、動作の文書化なのかを判断します。完了とは、2 つの列タイプが同等のスタイルを受け取るか、制限が文書化されていることを意味します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
angular, typescript
領域
frontend
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
38/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。