angular / angular/components

bug(form-field): mat-label disappears when density < -1

Open
#26,579 19 comments 73 reactions 0 assignees View on GitHub
area: material/form-field P2
Dominant language
TypeScript
Stars
25k
Forks
6.8k
Avg merge
1d 8h
Merged PRs (30d)
91

Description

### 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

Hi,
There seems to be an issue where the mat-labels disappear when the density of form-field is set to lower than -1. I don't think this is as designed...

### Reproduction

Steps to reproduce:
1. Set the density option to anything lower than -1, ex: `@include mat.form-field-density(-2);`
2. Include a mat-form-field with the appearance set to "fill", with a mat-label

notice the labels do not appear. (Their css is set as "display:none;")

Demo: https://stackblitz.com/edit/angular-wvlwej
In the stackblitz, you can see that the labels appear fine when density is set at >= -1, but anything lower and the label is hidden.

![image](https://user-images.githubusercontent.com/8459019/217098883-527e1c7c-71a2-4cb2-8c3e-2dc2c6a1b964.png)

### Expected Behavior

The labels should be visible

### Actual Behavior

The labels are not visible

### Environment

- Angular: 15.1.3
- CDK/Material: 15.1.3
- Browser(s): Chrome Version 109.0.5414.120
- Operating System (e.g. Windows, macOS, Ubuntu): Windows

Contributor guide

Open the contributing guide

Research direction

Start with the linked StackBlitz reproduction and the mat.form-field-density(-2) configuration for a fill mat-form-field. Inspect the generated CSS for mat-label at densities below -1; done means labels remain visible, matching behavior at densities of -1 and above, with regression coverage for the reproduced case.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, sass
Domain
design, frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.