Skip to content

bug(autocomplete): scroll locking #26484

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

Open
1 task
RobinKamps opened this issue Jan 24, 2023 · 6 comments
Open
1 task

bug(autocomplete): scroll locking #26484

RobinKamps opened this issue Jan 24, 2023 · 6 comments
Labels
area: material/autocomplete P4 A relatively minor issue that is not relevant to core functions

Comments

@RobinKamps
Copy link

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

autocomplete does not behave like other material compnents like menu or select - those lock the scrolling of the underlying div/html/body.

autocomplete

Reproduction

Steps to reproduce:

  1. https://material.angular.io/components/select/overview
  2. open autocomplete and scroll on body

Expected Behavior

scroll is locked

Actual Behavior

scrolling is enabled - inconvenient behavior between material components, resulting in multiple issues e.g. z-index or if a container for scrolling is used the autocomplete panel does not scroll.

Environment

  • Angular: 15.1.1
  • CDK/Material: 15.1.1
  • Browser(s): all
  • Operating System (e.g. Windows, macOS, Ubuntu): all
@RobinKamps RobinKamps added the needs triage This issue needs to be triaged by the team label Jan 24, 2023
@amysorto amysorto added P4 A relatively minor issue that is not relevant to core functions area: material/autocomplete and removed needs triage This issue needs to be triaged by the team labels May 19, 2023
@MardariG
Copy link

MardariG commented Jun 7, 2024

Is this under any considerations for fixing? This is also not working when having more than one autocompletes per page and using scroll blocking strategy. Focusing first autocomplete will work as expected, but if you focus first, and then focus second, the second one scroll strategy is broken. Oh, it may be a different issue after all. Just notice that everywhere on material demo page blocking scroll strategy is working, but not for autocomplete.

@danieldiazastudillo
Copy link

danieldiazastudillo commented Jun 18, 2024

Any way to bypass or patch this problem via CSS or using another API for the popover? (in case is using some specific API for that purpose). We are using Angular Material 17 and the problem persists (even in AM18).

This doesn't replicate if you use a mouse, it only triggers when using the mousepad.

@M0o4
Copy link

M0o4 commented Sep 2, 2024

Is it really hard to add a transparent backdrop?

@M0o4
Copy link

M0o4 commented Sep 2, 2024

Solution for 16.0.2

@Directive({
  selector: '[matAutocomplete][autocompleteBackdrop]',
})
export class MatAutocompleteBackdropDirective implements OnInit {
  constructor(private readonly matAutocompleteTrigger: MatAutocompleteTrigger) {}

  ngOnInit(): void {
    this.matAutocompleteTrigger['_getOverlayConfig'] = (): OverlayConfig => {
      return new OverlayConfig({
        positionStrategy: this.matAutocompleteTrigger['_getOverlayPosition'](),
        scrollStrategy: this.matAutocompleteTrigger['_scrollStrategy'](),
        width: this.matAutocompleteTrigger['_getPanelWidth'](),
        direction: this.matAutocompleteTrigger['_dir'] ?? undefined,
        panelClass: this.matAutocompleteTrigger['_defaults']?.overlayPanelClass,
        hasBackdrop: true,
        backdropClass: 'cdk-overlay-transparent-backdrop',
      });
    };
  }
}

@Hlanden
Copy link

Hlanden commented Oct 14, 2024

EDIT

I figured that my auto-complete dropdown works as expected.
The reason it looked strange in my app, is that the autocomplete dropdown is still visible while the input is out of the view.
Image

For me this behavior is a bit strange, but it is also apparent in the autocomplete example page.
Can someone point me in the correct direction? How can I close the autocomplete panel once the input is scrolled out of view?

Original Comment

I have the same issue in angular 18 in a dialog:

Repro Steps

  1. Create a dialog with content that requires scrolling to see the full content
  2. Add inputs with autocomplete
  3. Scroll down/up in the dialog.

Actual Result

The autocomplete suggestions are not sticking to its corresponding input (just like the video above)

Expected Result

Autocomplete suggestions sticks to the input, also while scrolling.

Debugging

I am quite new to angular and web-development in general.
Some of these concepts are still a bit hard to grasp.
However, I have tried several suggestions online:

  • Adding a div with cdkScrollable around mat-dialog-content: Same behavior
  • Adding cdkScrollable to mat-dialog-content: The dialog disappears

Environment

  • Angular: 18.0.0
  • Angular Material: 18.0.0
  • OS: Ubuntu 20.04
  • Browsers: Firefox, Chrome

@EM-LilianaIturribarria
Copy link

Hi team,
any news on this?
i saw this ticket was created in 2023...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: material/autocomplete P4 A relatively minor issue that is not relevant to core functions
Projects
None yet
Development

No branches or pull requests

7 participants