Skip to content

Commit

Permalink
Add shared type for form field control interface
Browse files Browse the repository at this point in the history
  • Loading branch information
RasmusKjeldgaard committed Jan 31, 2025
1 parent a0c9879 commit 8cd47c3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 4 deletions.
5 changes: 3 additions & 2 deletions libs/designsystem/form-field/src/input/input.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Output,
SimpleChanges,
} from '@angular/core';
import { FormFieldControl } from '@kirbydesign/designsystem/types';
import { DateInputDirective } from '../directives/date/date-input.directive';

export enum InputSize {
Expand All @@ -24,7 +25,7 @@ export enum InputSize {
hostDirectives: [
{
directive: DateInputDirective,
// eslint-disable-next-line @angular-eslint/no-inputs-metadata-property

inputs: ['prefillYear', 'useNativeDatePicker'],
},
],
Expand All @@ -34,7 +35,7 @@ export enum InputSize {
styleUrls: ['./input.component.scss'],
template: '',
})
export class InputComponent implements OnChanges, OnInit {
export class InputComponent implements OnChanges, OnInit, FormFieldControl {
kirbyChange = new EventEmitter<string>();
private _hasError: boolean = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Output,
SimpleChanges,
} from '@angular/core';
import { FormFieldControl } from '@kirbydesign/designsystem/types';

@Component({
imports: [CommonModule],
Expand All @@ -19,7 +20,7 @@ import {
styleUrls: ['./textarea.component.scss'],
templateUrl: './textarea.component.html',
})
export class TextareaComponent implements OnChanges {
export class TextareaComponent implements OnChanges, FormFieldControl {
kirbyChange = new EventEmitter<string>();
private _hasError: boolean = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { Component, HostListener, Input } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { ListItemTemplateDirective } from '@kirbydesign/designsystem/list';
import { FormFieldControl } from '@kirbydesign/designsystem/types';

import { RadioComponent } from '../radio.component';

Expand All @@ -31,7 +32,9 @@ import { RadioComponent } from '../radio.component';
changeDetection: ChangeDetectionStrategy.OnPush,
standalone: false,
})
export class RadioGroupComponent implements AfterContentInit, ControlValueAccessor {
export class RadioGroupComponent
implements AfterContentInit, ControlValueAccessor, FormFieldControl
{
constructor(private changeDetectionRef: ChangeDetectorRef) {}

// #region public properties
Expand Down
6 changes: 6 additions & 0 deletions libs/designsystem/types/src/form-field-control.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { EventEmitter } from '@angular/core';

export interface FormFieldControl {
hasError: boolean;
hasErrorChange: EventEmitter<boolean>;
}
1 change: 1 addition & 0 deletions libs/designsystem/types/src/public_api.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './window-ref';
export * from './event-listener-dispose-fn';
export * from './unobserve-fn';
export * from './form-field-control';

0 comments on commit 8cd47c3

Please sign in to comment.