-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Open
Labels
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentAn issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: cdk/overlay
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
Not sure, possibly 19
Description
Recently block scroll strategy stopped working for out custom overlays used in material dialogs.
close
and reposition
strategies are working.
Seems to be related to OverlayPositionBuilder
or flexibleConnectedTo
.
Code:
function getAvailablePosition(): ConnectedPosition[] {
return [
{
offsetY: 4,
originX: 'start',
originY: 'bottom',
overlayX: 'start',
overlayY: 'top',
},
{
offsetY: 4,
originX: 'end',
originY: 'bottom',
overlayX: 'end',
overlayY: 'top',
},
{
offsetY: -4,
originX: 'start',
originY: 'top',
overlayX: 'start',
overlayY: 'bottom',
},
{
offsetY: -4,
originX: 'end',
originY: 'top',
overlayX: 'end',
overlayY: 'bottom',
},
];
}
@Directive({
host: {
'(click)': 'toggle()',
},
selector: '[customDropdown]',
})
export class CustomDropdown {
dropdownTemplateRef = input<TemplateRef<any> | undefined>();
elementRef = inject(ElementRef);
overlay = inject(Overlay);
overlayPositionBuilder = inject(OverlayPositionBuilder);
viewContainerRef = inject(ViewContainerRef);
viewportRuler = inject(ViewportRuler);
isOpen = false;
overlayRef?: OverlayRef;
getOverlayConfig(): OverlayConfig {
const positionStrategy = this.overlayPositionBuilder
.flexibleConnectedTo(this.elementRef)
.withPositions(getAvailablePosition());
const scrollStrategy = this.overlay.scrollStrategies.block();
return {
hasBackdrop: false,
positionStrategy,
scrollStrategy,
};
}
hide(): void {
if (this.overlayRef?.hasAttached()) {
this.isOpen = false;
this.overlayRef?.detach();
}
}
show(): void {
const templateRef = this.dropdownTemplateRef();
if (!templateRef) {
return;
}
this.overlayRef = this.overlay.create(this.getOverlayConfig());
this.overlayRef.attach(
new TemplatePortal(templateRef, this.viewContainerRef)
);
this.isOpen = true;
}
toggle() {
if (!this.isOpen) this.show();
else this.hide();
}
}
Reproduction
StackBlitz link: https://stackblitz.com/edit/stackblitz-starters-usvtgdmf?file=src%2Fmain.ts
Steps to reproduce:
- Open dialog
- Toggle dropdown
- Scroll
Expected Behavior
Dialog isn't scrollable when overlay is opened
Actual Behavior
Dialog is scrollable when overlay is opened
Environment
- Angular: 20.0.4
- CDK/Material: 20.0.4
- Browser(s): Chrome 138.0.7204.101
- Operating System (e.g. Windows, macOS, Ubuntu): MacOS
Metadata
Metadata
Assignees
Labels
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentAn issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: cdk/overlay