Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(material/form-field): hiding a label after it has been shown leaves a blank space #29401

Closed
1 task
GeorgianStan opened this issue Jul 9, 2024 · 1 comment · Fixed by #29461
Closed
1 task
Labels
area: material/form-field P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@GeorgianStan
Copy link
Contributor

GeorgianStan commented Jul 9, 2024

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

input-label-bug

When the mat-label tag is removed from a mat-form-field a white gap remains visible.

<mat-form-field appearance="outline">
  @if (hasLabel$ | async){
    <mat-label>My input</mat-label>
  }
  <input matInput type="text" [(ngModel)]="name" />
</mat-form-field>
export class App {
  hasLabel$ = new BehaviorSubject(true);
  name = '';

  ngOnInit() {
    setTimeout(() => {
      this.hasLabel$.next(false);
    }, 3000);
  }
}

Reproduction

StackBlitz link

Expected Behavior

If hasLabel$ has a default value of false hasLabel$ = new BehaviorSubject(false); and mat-label is hidden from the start, it works as it should, but I would expect it to work as well if the label is removed later.

Actual Behavior

The blank space remains visible.

Environment

  • Angular: 18
  • CDK/Material: 18
@GeorgianStan GeorgianStan added the needs triage This issue needs to be triaged by the team label Jul 9, 2024
@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent area: material/form-field and removed needs triage This issue needs to be triaged by the team labels Jul 10, 2024
jullierme added a commit to jullierme/components that referenced this issue Jul 19, 2024
shown leaves a blank space

There is a method _shouldLabelFloat that determines if the label
should float. A check was added `_hasFloatingLabel` to see if a
floating label exists before deciding whether the label should
float. Examples were added at the end of the input-demo file,
where you can see inputs without labels (both fixed and dynamic).
Removing the solution also allows you to simulate the described
error. Unit tests were added to validate the solution.

Fixes angular#29401
crisbeto pushed a commit that referenced this issue Jul 22, 2024
shown leaves a blank space

There is a method _shouldLabelFloat that determines if the label
should float. A check was added `_hasFloatingLabel` to see if a
floating label exists before deciding whether the label should
float. Examples were added at the end of the input-demo file,
where you can see inputs without labels (both fixed and dynamic).
Removing the solution also allows you to simulate the described
error. Unit tests were added to validate the solution.

Fixes #29401

(cherry picked from commit 13aef8c)
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Aug 22, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: material/form-field P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
2 participants