diff --git a/projects/composition/src/app/api-data/cps-button.json b/projects/composition/src/app/api-data/cps-button.json index 90853e0e..ccfd635f 100644 --- a/projects/composition/src/app/api-data/cps-button.json +++ b/projects/composition/src/app/api-data/cps-button.json @@ -37,6 +37,14 @@ "default": "solid", "description": "Type of the button in terms of appearance, it can be 'solid' or 'outlined' or 'borderless'." }, + { + "name": "nativeType", + "optional": false, + "readonly": false, + "type": "'button' | 'submit' | 'reset'", + "default": "button", + "description": "Native HTML button type attribute, it can be 'button', 'submit' or 'reset'." + }, { "name": "label", "optional": false, diff --git a/projects/composition/src/app/pages/button-page/button-page.component.html b/projects/composition/src/app/pages/button-page/button-page.component.html index 6a5c9a3a..df51c30e 100644 --- a/projects/composition/src/app/pages/button-page/button-page.component.html +++ b/projects/composition/src/app/pages/button-page/button-page.component.html @@ -321,6 +321,38 @@ + +
+ +
+ + + +
+
+ {{ nativeSubmitMessage }} +
+
+
+ (this.isLoading = false), 2000); } + onNativePlainClick() { + this.nativeSubmitMessage = 'Plain button clicked (no form action).'; + } + + onNativeSubmit(event: Event) { + event.preventDefault(); + if (this.nativeForm.invalid) { + this.nativeSubmitMessage = 'Form is invalid.'; + return; + } + this.nativeSubmitMessage = `Form submitted with name: "${this.nativeForm.value.name}"`; + } + + onNativeReset() { + this.nativeForm.reset(); + this.nativeSubmitMessage = ''; + } + readonly examples = buttonExamples; } diff --git a/projects/composition/src/app/pages/button-page/button-page.examples.ts b/projects/composition/src/app/pages/button-page/button-page.examples.ts index aea25ab9..23aa0bf2 100644 --- a/projects/composition/src/app/pages/button-page/button-page.examples.ts +++ b/projects/composition/src/app/pages/button-page/button-page.examples.ts @@ -92,6 +92,65 @@ export const buttonExamples: Record = { ` }, + nativeTypes: { + html: ` +
+ +
+ + + +
+ @if (nativeSubmitMessage) { +
{{ nativeSubmitMessage }}
+ } +
`, + ts: ` +private readonly fb = inject(FormBuilder); + +componentData = ComponentData; +isLoading = false; + +nativeForm = this.fb.nonNullable.group({ + name: ['', Validators.required] +}); + +nativeSubmitMessage = ''; + +onNativePlainClick() { + this.nativeSubmitMessage = 'Plain button clicked (no form action).'; +} + +onNativeSubmit(event: Event) { + event.preventDefault(); + if (this.nativeForm.invalid) { + this.nativeSubmitMessage = 'Form is invalid.'; + return; + } + this.nativeSubmitMessage = "Form submitted with name: " + this.nativeForm.value.name; +} + +onNativeReset() { + this.nativeForm.reset(); + this.nativeSubmitMessage = ''; +}` + }, + misc: { html: ` diff --git a/projects/cps-ui-kit/src/lib/components/cps-button/cps-button.component.html b/projects/cps-ui-kit/src/lib/components/cps-button/cps-button.component.html index 671273a7..bbfb0140 100644 --- a/projects/cps-ui-kit/src/lib/components/cps-button/cps-button.component.html +++ b/projects/cps-ui-kit/src/lib/components/cps-button/cps-button.component.html @@ -1,6 +1,6 @@