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.
scrollBottom. nativeElement. scrollHeight; angular scroll to bottom of page.
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.
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.
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.
Try adding "autoFocus: false" to your code:
openDialog(): void {
let dialogRef = this.dialog.open(FileBrowserComponent, {
height: '600px',
width: '700px',
autoFocus: false,
});
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With