Skip to content

bug(mat-autocomplete): Autocomplete options are moving with dialog scrollbar #30416

@lopatnov

Description

@lopatnov

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

See: #30254, it was present in 18 version.

Description

Demo: https://github.com/lopatnov/autocomplete-issue

Reproduction

StackBlitz link: I don't use StackBlitz, don't know how to upload demo here.
Steps to reproduce:

  1. Open dialog with some elements, to have scroll in the dialog
  2. Open Autocomplete items
  3. Scroll down dialog scroll and you will see issue

Expected Behavior

Options of Autocomplete should stay below autocomplete, as it was opened. They don't need to move with dialog scrollbar.

Actual Behavior

When dialog scrollbar moves, then autocomplete options also moves.

Environment

  • Angular: 19.1.0
  • CDK/Material: 19.1.1
  • Browser(s): Chrome
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows

Activity

wagnermaciel

wagnermaciel commented on Feb 24, 2025

@wagnermaciel
Contributor

Hi @lopatnov, unfortunately I cannot download and run your repo because of potential security concerns. Could you try recreating the demo on stackblitz? Here is a starting point you can use:

https://stackblitz.com/run?file=.gitignore

added
needs: clarificationThe issue does not contain enough information for the team to determine if it is a real bug
and removed
needs triageThis issue needs to be triaged by the team
on Feb 24, 2025
lopatnov

lopatnov commented on Feb 27, 2025

@lopatnov
Author

I'll try to figure out how to do this today after work. Pay attention to this comment please: #30254 (comment) I showed the difference for mat-select and mat-autocomplete and why for mat-select it doesn't working and for mat-autocomplete this issue working. The difference is in backdrop, that for mat-select exists.

lopatnov

lopatnov commented on Feb 27, 2025

@lopatnov
Author

@wagnermaciel , I tried it now. It's first time I'm trying stackblitz. Try this link: https://stackblitz.com/~/github.com/lopatnov/autocomplete-issue. Does it working?

Image

Image

lopatnov

lopatnov commented on Feb 27, 2025

@lopatnov
Author

Detail process in image how to reproduce:

Image

wagnermaciel

wagnermaciel commented on Feb 27, 2025

@wagnermaciel
Contributor

Yeah, the stackblitz worked - thanks for putting that together!

A temporary workaround would be to close the autocomplete when you scroll the dialog content

For some reason I can't fork the stackblitz you shared but here is how you could accomplish this:

<mat-dialog-content (scroll)="trigger.closePanel()"> <!-- Close the panel on scroll -->
    <mat-form-field>
      <mat-label>Number</mat-label>
      <input
        type="text"
        placeholder="Pick one"
        aria-label="Number"
        matInput
        [formControl]="myControl"
        [matAutocomplete]="auto"
        #trigger="matAutocompleteTrigger" <!-- Get a ref to the autocomplete trigger -->
      />
added
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
and removed
needs: clarificationThe issue does not contain enough information for the team to determine if it is a real bug
on Feb 27, 2025
lopatnov

lopatnov commented on Feb 28, 2025

@lopatnov
Author

@wagnermaciel , Why is there a backdrop for mat-select, but not for mat-autocomplete? Why do I need to use a workaround for this? It's just a bug and I hope it will be fixed.

lopatnov

lopatnov commented on Feb 28, 2025

@lopatnov
Author

Also, try to move dialog window. In that way options will be on the same place and this is the same issue

lopatnov

lopatnov commented on Feb 28, 2025

@lopatnov
Author

Added second case, try to move dialog window when autocomplete was opened:

Image

wagnermaciel

wagnermaciel commented on Feb 28, 2025

@wagnermaciel
Contributor

Why is there a backdrop for mat-select, but not for mat-autocomplete?

I didn't author these components so I don't know why. If you'd like to read through the code, I'm sure you'll be able to uncover why these were written this way

It's just a bug and I hope it will be fixed.

The timeline for a fix heavily depends on how breaking a change it would be to land the fix. If someone can identify a fix that's backwards compatible that would be great, but changes to DOM structure are notoriously difficult to land because the fix would break people's existing applications. Unless more people start running into this issue, I'm not sure how likely it will that this gets prioritized.

lopatnov

lopatnov commented on Mar 1, 2025

@lopatnov
Author

@wagnermaciel The problem is in overlays. I suggested changing the overlay in mat-select and mat-autocomlete a few years ago, but I was told that they are significantly different from the existing ones and that the idea is to reuse the code as much as possible. But what's the point of reusing the code as much as possible if it is initially incorrect? Nobody makes options for such slect elements like in dialog boxes uses. Relative and absolute positioning and a blur event are used to make options disappear. There is no need to invent anything else there. And now I’m faced with the fact that for someone on the project this turns out to be a problem.
And if I add to the CDK such overlays that you don’t have yet and such selects that you don’t have, will you consider such changes or shouldn’t even try?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: cdk/dialogarea: material/autocomplete

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @lopatnov@wagnermaciel

        Issue actions

          bug(mat-autocomplete): Autocomplete options are moving with dialog scrollbar · Issue #30416 · angular/components