Document base dialog component

This commit is contained in:
Adina Țeudan 2021-12-08 11:40:48 +02:00
parent 1f5df2f730
commit 6e417a4b99

View File

@ -1,12 +1,23 @@
import { Directive, HostListener } from '@angular/core';
import { FormGroup } from '@angular/forms';
import { IqserEventTarget } from '../utils/types/events.type';
import { IqserEventTarget } from '../utils';
@Directive()
/**
* Extend this component when you want to submit the form after pressing enter.
*
* This could be done by adding properties (submit)="save()" on the form and type="submit" on the save button.
* However, some components (e.g. redaction-select, color picker) don't set focus on the input after choosing a value.
* Also, other components (e.g. dropdown select) trigger a different action on enter, instead of submit.
*
* Make sure to remove property type="submit" from the save button and the (submit)="save()" property from the form
* (otherwise the save request will be triggered twice).
* */
export abstract class BaseDialogComponent {
abstract form: FormGroup;
abstract get changed(): boolean;
abstract save(): void;
@HostListener('window:keydown.Enter', ['$event'])