mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Prevent close button 'stealing' focus from modal input fields
This commit is contained in:
		| @@ -27,6 +27,8 @@ export abstract class EditDialogComponent<T extends ObjectWithId> implements OnI | |||||||
|  |  | ||||||
|   networkActive = false |   networkActive = false | ||||||
|  |  | ||||||
|  |   closeEnabled = false | ||||||
|  |  | ||||||
|   error = null |   error = null | ||||||
|  |  | ||||||
|   abstract getForm(): FormGroup |   abstract getForm(): FormGroup | ||||||
| @@ -37,6 +39,11 @@ export abstract class EditDialogComponent<T extends ObjectWithId> implements OnI | |||||||
|     if (this.object != null) { |     if (this.object != null) { | ||||||
|       this.objectForm.patchValue(this.object) |       this.objectForm.patchValue(this.object) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     // we wait to enable the close button so it doesnt pull browser focus since its the first clickable element in the DOM | ||||||
|  |     setTimeout(() => { | ||||||
|  |       this.closeEnabled = true | ||||||
|  |     }); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   getCreateTitle() { |   getCreateTitle() { | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| <form [formGroup]="saveViewConfigForm" (ngSubmit)="save()"> | <form [formGroup]="saveViewConfigForm" (ngSubmit)="save()"> | ||||||
|   <div class="modal-header"> |   <div class="modal-header"> | ||||||
|     <h4 class="modal-title" id="modal-basic-title" i18n>Save current view</h4> |     <h4 class="modal-title" id="modal-basic-title" i18n>Save current view</h4> | ||||||
|     <button type="button" class="close" aria-label="Close" (click)="cancel()"> |     <button type="button" [disabled]="!closeEnabled" class="close" aria-label="Close" (click)="cancel()"> | ||||||
|       <span aria-hidden="true">×</span> |       <span aria-hidden="true">×</span> | ||||||
|     </button> |     </button> | ||||||
|   </div> |   </div> | ||||||
|   | |||||||
| @@ -20,6 +20,8 @@ export class SaveViewConfigDialogComponent implements OnInit { | |||||||
|   @Input() |   @Input() | ||||||
|   buttonsEnabled = true |   buttonsEnabled = true | ||||||
|  |  | ||||||
|  |   closeEnabled = false | ||||||
|  |  | ||||||
|   _defaultName = "" |   _defaultName = "" | ||||||
|  |  | ||||||
|   get defaultName() { |   get defaultName() { | ||||||
| @@ -31,7 +33,7 @@ export class SaveViewConfigDialogComponent implements OnInit { | |||||||
|     this._defaultName = value |     this._defaultName = value | ||||||
|     this.saveViewConfigForm.patchValue({name: value}) |     this.saveViewConfigForm.patchValue({name: value}) | ||||||
|   } |   } | ||||||
|    |  | ||||||
|   saveViewConfigForm = new FormGroup({ |   saveViewConfigForm = new FormGroup({ | ||||||
|     name: new FormControl(''), |     name: new FormControl(''), | ||||||
|     showInSideBar: new FormControl(false), |     showInSideBar: new FormControl(false), | ||||||
| @@ -39,6 +41,10 @@ export class SaveViewConfigDialogComponent implements OnInit { | |||||||
|   }) |   }) | ||||||
|  |  | ||||||
|   ngOnInit(): void { |   ngOnInit(): void { | ||||||
|  |     // wait to enable close button so it doesnt steal focus form input | ||||||
|  |     setTimeout(() => { | ||||||
|  |       this.closeEnabled = true | ||||||
|  |     }); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   save() { |   save() { | ||||||
|   | |||||||
| @@ -1,12 +1,11 @@ | |||||||
| <form [formGroup]="objectForm" (ngSubmit)="save()"> | <form [formGroup]="objectForm" (ngSubmit)="save()"> | ||||||
|   <div class="modal-header"> |   <div class="modal-header"> | ||||||
|     <h4 class="modal-title" id="modal-basic-title">{{getTitle()}}</h4> |     <h4 class="modal-title" id="modal-basic-title">{{getTitle()}}</h4> | ||||||
|     <button type="button" class="close" aria-label="Close" (click)="cancel()"> |     <button type="button" [disabled]="!closeEnabled" class="close" aria-label="Close" (click)="cancel()"> | ||||||
|       <span aria-hidden="true">×</span> |       <span aria-hidden="true">×</span> | ||||||
|     </button> |     </button> | ||||||
|   </div> |   </div> | ||||||
|   <div class="modal-body"> |   <div class="modal-body"> | ||||||
|  |  | ||||||
|     <app-input-text i18n-title title="Name" formControlName="name" [error]="error?.name"></app-input-text> |     <app-input-text i18n-title title="Name" formControlName="name" [error]="error?.name"></app-input-text> | ||||||
|     <app-input-select i18n-title title="Matching algorithm" [items]="getMatchingAlgorithms()" formControlName="matching_algorithm"></app-input-select> |     <app-input-select i18n-title title="Matching algorithm" [items]="getMatchingAlgorithms()" formControlName="matching_algorithm"></app-input-select> | ||||||
|     <app-input-text *ngIf="patternRequired" i18n-title title="Matching pattern" formControlName="match"></app-input-text> |     <app-input-text *ngIf="patternRequired" i18n-title title="Matching pattern" formControlName="match"></app-input-text> | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| <form [formGroup]="objectForm" (ngSubmit)="save()"> | <form [formGroup]="objectForm" (ngSubmit)="save()"> | ||||||
|     <div class="modal-header"> |     <div class="modal-header"> | ||||||
|       <h4 class="modal-title" id="modal-basic-title">{{getTitle()}}</h4> |       <h4 class="modal-title" id="modal-basic-title">{{getTitle()}}</h4> | ||||||
|       <button type="button" class="close" aria-label="Close" (click)="cancel()"> |       <button type="button" [disabled]="!closeEnabled" class="close" aria-label="Close" (click)="cancel()"> | ||||||
|         <span aria-hidden="true">×</span> |         <span aria-hidden="true">×</span> | ||||||
|       </button> |       </button> | ||||||
|     </div> |     </div> | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
|   <form [formGroup]="objectForm" (ngSubmit)="save()"> |   <form [formGroup]="objectForm" (ngSubmit)="save()"> | ||||||
|     <div class="modal-header"> |     <div class="modal-header"> | ||||||
|       <h4 class="modal-title" id="modal-basic-title">{{getTitle()}}</h4> |       <h4 class="modal-title" id="modal-basic-title">{{getTitle()}}</h4> | ||||||
|       <button type="button" class="close" aria-label="Close" (click)="cancel()"> |       <button type="button" [disabled]="!closeEnabled" class="close" aria-label="Close" (click)="cancel()"> | ||||||
|         <span aria-hidden="true">×</span> |         <span aria-hidden="true">×</span> | ||||||
|       </button> |       </button> | ||||||
|     </div> |     </div> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Michael Shamoon
					Michael Shamoon