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(timepicker): Multiple overlays and host already has a portal attached #30637

Closed
1 task
luthesebas opened this issue Mar 17, 2025 · 0 comments · Fixed by #30639
Closed
1 task

bug(timepicker): Multiple overlays and host already has a portal attached #30637

luthesebas opened this issue Mar 17, 2025 · 0 comments · Fixed by #30639
Assignees
Labels
area: material/timepicker P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@luthesebas
Copy link

luthesebas commented Mar 17, 2025

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

Clicking outside a Timepicker enclosed by a MatFormField causes an error and multiple Timepicker overlays.

ERROR Error: Host already has a portal attached
    at throwPortalAlreadyAttachedError (portal.mjs:17:9)
    at DomPortalOutlet.attach (portal.mjs:196:9)
    at OverlayRef.attach

Reproduction

Error "Host already has a portal attached"

StackBlitz link: https://stackblitz.com/edit/components-issue-starter-v6k1y4ci?file=src%2Fmain.ts
Steps to reproduce:

  1. Open StackBlitz link
  2. Click into the Timepicker input (overlay should open upwards)
  3. Click right below the Timepicker. Just right below the MatFormField where hints and errors (would) appear
  4. Look at the browser console output

Multiple overlays

Steps to reproduce:

  1. Head to https://material.angular.io/components/timepicker/examples
  2. Scroll so that a timepicker is at the bottom of the browser window, which should cause the timepicker overlay to open upwards.
  3. Click into the Timepicker input (overlay should open upwards)
  4. Click right below the Timepicker. Just right below the MatFormField where hints and errors (would) appear
  5. Now there should be two Timepicker overlays
  6. Repeat step 4 as often as you like to create N overlays

(no idea how to reproduce this behavior in StackBlitz/local)

Code for reproduction

@Component({
  selector: 'app-root',
  standalone: true,
  imports: [DemoMaterialModule],
  template: `
    <mat-form-field>
      <mat-label>Pick a time</mat-label>
      <input matInput [matTimepicker]="picker">
      <mat-timepicker-toggle matIconSuffix [for]="picker"/>
      <mat-timepicker #picker/>
    </mat-form-field>
  `,
  styles: `
    :host {
      display: flex;
      flex-direction: column;
      justify-content: flex-end;
      height: calc(100vh - 2rem);
    }
  `
})
export class App {}

Expected Behavior

  • No error
  • No multiple Timepicker overlays
  • The already existing overlay should be closed and not reopened

Actual Behavior

Environment

  • Angular: 19.2.0
  • CDK/Material: 19.2.1
  • Browser(s): Edge
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows
@luthesebas luthesebas added the needs triage This issue needs to be triaged by the team label Mar 17, 2025
@crisbeto crisbeto self-assigned this Mar 17, 2025
@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent area: material/timepicker and removed needs triage This issue needs to be triaged by the team labels Mar 17, 2025
crisbeto added a commit to crisbeto/material2 that referenced this issue Mar 17, 2025
Fixes that the timepicker was throwing an error if it gets closed and reopened before change detection has had a chance to run.

Fixes angular#30637.
crisbeto added a commit that referenced this issue Mar 17, 2025
Fixes that the timepicker was throwing an error if it gets closed and reopened before change detection has had a chance to run.

Fixes #30637.

(cherry picked from commit 43b0860)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: material/timepicker P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants