Closed
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
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:
- Open StackBlitz link
- Click into the
Timepicker
input (overlay should open upwards) - Click right below the
Timepicker
. Just right below theMatFormField
where hints and errors (would) appear - Look at the browser console output
Multiple overlays
Steps to reproduce:
- Head to https://material.angular.io/components/timepicker/examples
- Scroll so that a timepicker is at the bottom of the browser window, which should cause the timepicker overlay to open upwards.
- Click into the
Timepicker
input (overlay should open upwards) - Click right below the
Timepicker
. Just right below theMatFormField
where hints and errors (would) appear - Now there should be two
Timepicker
overlays - 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
- error "Host already has a portal attached"
- Multiple
Timepicker
overlays (at leat at https://material.angular.io/components/timepicker/examples) - The already existing overlay gets closed and reopened
Environment
- Angular: 19.2.0
- CDK/Material: 19.2.1
- Browser(s): Edge
- Operating System (e.g. Windows, macOS, Ubuntu): Windows