stop propagation if action observed

This commit is contained in:
Dan Percic 2023-03-20 15:29:25 +02:00
parent a1d11cd9eb
commit a60a9d828e
6 changed files with 19 additions and 9 deletions

View File

@ -9,9 +9,9 @@
[class.warn]="type === circleButtonTypes.warn"
[disabled]="disabled"
[id]="buttonId"
[stopPropagation]="action.observed"
[type]="isSubmit ? 'submit' : 'button'"
mat-icon-button
stopPropagation
>
<mat-icon [svgIcon]="icon"></mat-icon>
</button>

View File

@ -3,9 +3,9 @@
[disabled]="disabled"
[id]="buttonId"
[ngClass]="classes"
[stopPropagation]="action.observed"
[type]="submit ? 'submit' : 'button'"
mat-button
stopPropagation
>
<mat-icon *ngIf="icon" [svgIcon]="icon"></mat-icon>
<span>{{ label }}</span>

View File

@ -30,7 +30,7 @@ export abstract class BaseDialogComponent implements OnInit, OnDestroy {
readonly #subscriptions: Subscription = new Subscription();
#hasErrors = false;
protected constructor(protected readonly _dialogRef: MatDialogRef<BaseDialogComponent>, private readonly _isInEditMode?: boolean) {}
protected constructor(protected readonly _dialogRef: MatDialogRef<BaseDialogComponent>, private readonly _isInEditMode = false) {}
get valid(): boolean {
return !this.form || this.form.valid;
@ -63,7 +63,7 @@ export abstract class BaseDialogComponent implements OnInit, OnDestroy {
close() {
if (!this._isInEditMode || !this.changed) {
this._dialogRef.close();
return this._dialogRef.close();
}
this._openConfirmDialog().then(result => {

View File

@ -1,12 +1,17 @@
import { Directive, HostListener } from '@angular/core';
import { Directive, HostListener, Input } from '@angular/core';
@Directive({
selector: '[preventDefault]',
standalone: true,
})
export class PreventDefaultDirective {
@Input() preventDefault: boolean | string = true;
@HostListener('click', ['$event'])
onClick($event: Event) {
$event.preventDefault();
const stop = this.preventDefault === '' || this.preventDefault === 'true' || this.preventDefault === true;
if (stop) {
$event.preventDefault();
}
}
}

View File

@ -1,12 +1,17 @@
import { Directive, HostListener } from '@angular/core';
import { Directive, HostListener, Input } from '@angular/core';
@Directive({
selector: '[stopPropagation]',
standalone: true,
})
export class StopPropagationDirective {
@Input() stopPropagation: boolean | string = true;
@HostListener('click', ['$event'])
onClick($event: Event) {
$event.stopPropagation();
const stop = this.stopPropagation === '' || this.stopPropagation === 'true' || this.stopPropagation === true;
if (stop) {
$event.stopPropagation();
}
}
}

View File

@ -28,6 +28,6 @@ export class EmptyStateComponent implements OnInit {
@Output() readonly action = new EventEmitter();
ngOnInit(): void {
this.showButton = this.showButton && this.action.observers.length > 0;
this.showButton = this.showButton && this.action.observed;
}
}