diff --git a/packages/dgt-components/demo/demo.component.ts b/packages/dgt-components/demo/demo.component.ts index 9eb99ad2..3ad065c8 100644 --- a/packages/dgt-components/demo/demo.component.ts +++ b/packages/dgt-components/demo/demo.component.ts @@ -43,12 +43,18 @@ const emailValidator: FormValidator<{ email: string }> = async (context, event) }; +export type DemoFormModel = { + email: string, + textareaField: string, + select: string, +}; + export class DemoComponent extends RxLitElement { // eslint-disable-next-line max-len - private formMachine: StateMachine, FormStateSchema<{ email: string, textareaField: string }>, FormEvent, FormState<{ email: string, textareaField: string }>>; + private formMachine: StateMachine, FormStateSchema, FormEvent, FormState>; // eslint-disable-next-line max-len - private formActor: Interpreter, FormStateSchema<{ email: string, textareaField: string }>, FormEvent, FormState<{ email: string, textareaField: string }>>; + private formActor: Interpreter, FormStateSchema, FormEvent, FormState>; private translator: Translator; @@ -56,17 +62,20 @@ export class DemoComponent extends RxLitElement { super(); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment - this.formMachine = createMachine, FormEvent, FormState<{ email: string, textareaField: string }>>(formMachine<{ email: string, textareaField: string }>(emailValidator)).withContext({ - data: { email: '', textareaField: '' }, - original: { email: '', textareaField: '' }, + this.formMachine = createMachine, FormEvent, FormState>(formMachine(emailValidator)).withContext({ + data: { email: '', textareaField: '', select: 'first' }, + original: { email: '', textareaField: '', select: 'first' }, }); // eslint-disable-next-line no-console,@typescript-eslint/no-unsafe-assignment - this.formActor = interpret(this.formMachine, { devTools: true }).onTransition((s) => console.log(s.value)); + this.formActor = interpret(this.formMachine, { devTools: true }).onTransition((s) => { + console.log(s.value); + console.log('data', s.context.data) + }); this.formActor.start(); define('checkbox-component', CheckboxComponent); - define('form-element', hydrate(FormElementComponent)(this.formActor)); + define('form-element', FormElementComponent); // create single translator setTranslatorFactory(new MemoryTranslatorFactory); @@ -114,12 +123,25 @@ export class DemoComponent extends RxLitElement {

form element component

- + - + + + + +
+ +
diff --git a/packages/dgt-components/lib/components/forms/form-element.component.ts b/packages/dgt-components/lib/components/forms/form-element.component.ts index ec0f1105..bb88a14e 100644 --- a/packages/dgt-components/lib/components/forms/form-element.component.ts +++ b/packages/dgt-components/lib/components/forms/form-element.component.ts @@ -19,7 +19,7 @@ export class FormElementComponent extends RxLitElement { * All input elements slotted in the form element. */ @internalProperty() - inputs: (HTMLInputElement | HTMLTextAreaElement)[]; + inputs: (HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement)[] = []; /** * The slot element which contains the input field. @@ -177,8 +177,9 @@ export class FormElementComponent extends RxLitElement { } this.inputs = slot.assignedNodes({ flatten: true })?.filter( - (element) => element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement, - ).map((element) => element as HTMLInputElement | HTMLTextAreaElement); + (element) => element instanceof HTMLInputElement || element instanceof HTMLTextAreaElement + || element instanceof HTMLSelectElement, + ).map((element) => element as HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement); this.inputs?.forEach((element) => { diff --git a/packages/dgt-components/package.json b/packages/dgt-components/package.json index 16cc688a..3a7a6de4 100644 --- a/packages/dgt-components/package.json +++ b/packages/dgt-components/package.json @@ -93,10 +93,10 @@ ], "coverageThreshold": { "global": { - "branches": 76.19, + "branches": 76.33, "functions": 74.01, - "lines": 88.11, - "statements": 88.5 + "lines": 88.97, + "statements": 89.22 } }, "coveragePathIgnorePatterns": [ @@ -107,4 +107,4 @@ "/demo/" ] } -} +} \ No newline at end of file