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

autocomplete: panel does not reposition on page scroll #7897

Closed
axtho opened this issue Oct 19, 2017 · 20 comments
Closed

autocomplete: panel does not reposition on page scroll #7897

axtho opened this issue Oct 19, 2017 · 20 comments
Assignees
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@axtho
Copy link

axtho commented Oct 19, 2017

Bug, feature request, or proposal:

Bug?

What is the expected behavior?

The overlay panel of autocomplete should reposition on mat-sidenav-container scolling underneath

What is the current behavior?

The panel stays put on it original position. Consider this code:

<form class="person-form"
      #personEditForm="ngForm"
      [formGroup]="form"
      (ngSubmit)="save(form.value)"
      (keyup)="onKey($event)"
      novalidate>

    <fieldset fxFlex="100">
        <legend i18n>Status &amp; Tags</legend>
        <mh-tags [source]="tagSource"
                 formControlName="status"
                 placeholder="Status"></mh-tags>
    </fieldset>
...

The component (mh-tags) HTML looks like this:

<mat-form-field floatPlaceholder="always">
  <mat-chip-list #chipList>
    <mat-icon matPrefix>label_outline</mat-icon>
    <mat-chip *ngFor="let tag of _value" (remove)="remove(tag)">
      {{tag.text}} <mat-icon matChipRemove>cancel</mat-icon>
    </mat-chip>
    <input [matChipInputFor]="chipList"
           [matChipInputAddOnBlur]="false"
           (matChipInputTokenEnd)="addNew($event)"
           [matAutocomplete]="auto"
           placeholder="{{placeholder}}"
           #chipInput>
  </mat-chip-list>
  <mat-autocomplete #auto="matAutocomplete" [displayWith]="displayFn" (optionSelected)="add($event)">
    <mat-option *ngFor="let tag of sourceFiltered()" [value]="tag">
      <span>{{ tag.text }}</span>
    </mat-option>
  </mat-autocomplete>
</mat-form-field>

Here is the layout for it.

EDIT
Produces this:
bildschirmfoto 2017-10-19 um 08 57 15

What are the steps to reproduce?

Could not reproduce on stackblitz because mat-sidenav-container seems not to be part of beta.12.
I am using the nightly builds.

What is the use-case or motivation for changing an existing behavior?

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Angular: 4.4.4
Typescript: 2.5.3
Material/cdk: nightlies
cli: 1.5.0-rc.1

Is there anything else we should know?

I know there has been a few issues (#4557, #5797, #4093) on this already, plus a couple of PRs (#4293, #4500, #4855, #5134) that must have fixed this.

However, in my case it sill remains. May it is because of the way the sticky sidenav works now?

I have tried to apply the cdkScrollable directive to almost every parent element of the autocomplete. No cigar.

@axtho axtho changed the title autocomplete: panel does reposition on page scroll autocomplete: panel does not reposition on page scroll Oct 19, 2017
@crisbeto crisbeto added the P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent label Nov 28, 2017
@johnbwoodruff
Copy link

Any update on this? I have this issue as well, opening it attaches correctly to the element, but when I scroll down it doesn't reposition, it simply stays at the same position on the page. I can't use the autocomplete for what I need without this working properly.

@lucacicala
Copy link

Having the same problem using

"@angular/material": "^5.2.4",

any update on this?

@axtho
Copy link
Author

axtho commented Apr 16, 2018

No, in fact it has not been touched since the issue was opened. Maybe @crisbeto can give us a little info on the way ahead. It is quite annoying.

@flannanbrody
Copy link

I'm having the same issue....but doesn't make sense that on the examples page it works fine
https://material.angular.io/components/autocomplete/overview

example...https://stackblitz.com/edit/angular-hifphm?file=app/autocomplete-auto-active-first-option-example.html

@flannanbrody
Copy link

Is there any know workarounds?

@rohullah-ayoub
Copy link

rohullah-ayoub commented Apr 18, 2018

I am having the same issue with this. Have not found any workarounds.

@vijaychhajer
Copy link

Any updates on this. Do we have any fix for it.

@imkiran
Copy link

imkiran commented Jun 29, 2018

Is this implemented?

@noggin182
Copy link

The example page works fine, however if you open it in stackblitz and wrap it in a scrollable div you can see the same problem: https://stackblitz.com/edit/angular-sc6bfp

@ferakiii
Copy link

ferakiii commented Jul 9, 2018

I've got the exact same problem @noggin182, did you find a workaround?

@noggin182
Copy link

Not yet @ferakiii, I have to get a fix in place this sprint for the project I am working on though so in the likely case that this isn't resolved before then I will be putting a work around in place. If it's something generic and useable by others I'll paste it here

@bastienlemaitre
Copy link

Any news ?

@ghost
Copy link

ghost commented Jul 30, 2018

any update on this issue?

@IlyaSolovyov
Copy link

Looking forward to a workaround, at the very least.

@crisbeto
Copy link
Member

The autocomplete (and all other overlay-based components) will only react to scrolling on the body/html elements, because doing so on absolutely all other elements would be terrible for performance. If your content is inside a different scrollable container, you can add the cdkScrollable attribute to let the CDK know that it should reposition when that element is scrolled.

@zonr
Copy link

zonr commented Aug 9, 2018

I'd like to expand @crisbeto's approach (which he also mentioned earlier in this comment) with @noggin182 example:

https://stackblitz.com/edit/angular-sc6bfp-ft5zvw

Here's the diff:

--- angular-sc6bfp/src/app/autocomplete-overview-example.html
+++ angular-sc6bfp-ft5zvw/src/app/autocomplete-overview-example.html
@@ -1,4 +1,4 @@
-<div style="height:400px; overflow:scroll">
+<div style="height:400px; overflow:scroll" cdkScrollable>
   
 <form class="example-form">
   <mat-form-field class="example-full-width">
diff -ru angular-sc6bfp/src/main.ts angular-sc6bfp-ft5zvw/src/main.ts
--- angular-sc6bfp/src/main.ts
+++ angular-sc6bfp-ft5zvw/src/main.ts
@@ -1,5 +1,6 @@
 import './polyfills';
 
+import {ScrollDispatchModule} from '@angular/cdk/scrolling';
 import {CdkTableModule} from '@angular/cdk/table';
 import {CdkTreeModule} from '@angular/cdk/tree';
 import {HttpClientModule} from '@angular/common/http';
@@ -86,6 +87,7 @@
     MatToolbarModule,
     MatTooltipModule,
     MatTreeModule,
+    ScrollDispatchModule,
   ]
 })
 export class DemoMaterialModule {}

@crisbeto
Copy link
Member

Closing this issue since the autocomplete is working as expected.

@kostas-kapasakis
Copy link

https://stackblitz.com/edit/angular-sc6bfp-ft5zvw?file=app%2Fautocomplete-overview-example.html

The issue is still there if you want bigger mat-option content.For example if we set the map-option height style , for example style="height:97px" by navigating with down arrow key the scrolling doesnt work properly

@Natanael1234
Copy link

Still happening in 5.2.5.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 10, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

No branches or pull requests