Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular 6 mat-dialog scroll down to bottom automatically

Tags:

angular

I have an issue with scroll down automatically when open the mat-dialog. I have 2 buttons that cause the the problem (I assume) but I didn't figure out what to do to resolve the issue.

The component.ts code :

 openDialog(): void {
let dialogRef = this.dialog.open(FileBrowserComponent, { 
       height: '600px',
       width: '700px',
});

The dialog html code :

<div class="container">

<div class="img" *ngFor="let element of fileElements">
    <img src="{{assetsFullUrl(element.name)}}" alt="{{element.name}}" (dblclick)="selectedImage===true">
</div>

</div>

<vaadin-upload target="http://localhost:3000/assets/upload" method="POST" 
accept="image/*"></vaadin-upload>

<div class="buttons">
<button mat-raised-button color='primary' type="button" (click)="add()">Save</button>
<button mat-raised-button color='basic' type="button" (click)="cancel()">Cancel</button>
</div>

Thanks for your help.

like image 414
Ho Do Avatar asked Oct 28 '18 08:10

Ho Do


People also ask

How do you scroll automatically to the bottom of the page in angular?

scrollBottom. nativeElement. scrollHeight; angular scroll to bottom of page.

What is scrollStrategy?

The scrollStrategy configuration option determines how the overlay will react to scrolling outside the overlay element. There are four scroll strategies available as part of the library. NoopScrollStrategy is the default option. This strategy does nothing.

How do you use MatDialogRef?

The MatDialogRef provides a handle on the opened dialog. It can be used to close the dialog and to receive notifications when the dialog has been closed. Any notification Observables will complete when the dialog closes. dialogRef.

What is CDK Global Scrollblock?

cdk-global-scrollblock css class. This class is added to the html tag when the block strategy is used. It is used to block the scroll of the content behind the dialog, especially on mobile devices (iOS) - that's why position: fixed; is used.


2 Answers

Try adding "autoFocus: false" to your code:

openDialog(): void { let dialogRef = this.dialog.open(FileBrowserComponent, { height: '600px', width: '700px', autoFocus: false, });

like image 162
van_Skyr Avatar answered Sep 28 '22 13:09

van_Skyr


According to the documentation, the first tabable element will be focused. You can assign tabindex="-1" to prevent the buttons from getting focused

<button mat-raised-button tabindex="-1">Not Tabbable</button>
like image 33
baao Avatar answered Sep 28 '22 13:09

baao