From 5af31577cc3dd09d07a68df918e4e4dcf7374504 Mon Sep 17 00:00:00 2001 From: Maria Hutt Date: Thu, 6 Mar 2025 12:11:28 -0800 Subject: [PATCH 01/10] docs(checkbox): add helperText and errorText section --- docs/api/checkbox.md | 10 ++++ .../angular/example_component_html.md | 11 ++++ .../angular/example_component_ts.md | 29 ++++++++++ .../usage/v8/checkbox/helper-error/demo.html | 58 +++++++++++++++++++ .../usage/v8/checkbox/helper-error/index.md | 24 ++++++++ .../v8/checkbox/helper-error/javascript.md | 37 ++++++++++++ .../usage/v8/checkbox/helper-error/react.md | 52 +++++++++++++++++ static/usage/v8/checkbox/helper-error/vue.md | 53 +++++++++++++++++ 8 files changed, 274 insertions(+) create mode 100644 static/usage/v8/checkbox/helper-error/angular/example_component_html.md create mode 100644 static/usage/v8/checkbox/helper-error/angular/example_component_ts.md create mode 100644 static/usage/v8/checkbox/helper-error/demo.html create mode 100644 static/usage/v8/checkbox/helper-error/index.md create mode 100644 static/usage/v8/checkbox/helper-error/javascript.md create mode 100644 static/usage/v8/checkbox/helper-error/react.md create mode 100644 static/usage/v8/checkbox/helper-error/vue.md diff --git a/docs/api/checkbox.md b/docs/api/checkbox.md index 900f827e237..a7b733f201d 100644 --- a/docs/api/checkbox.md +++ b/docs/api/checkbox.md @@ -74,6 +74,16 @@ import LabelLink from '@site/static/usage/v8/checkbox/label-link/index.md'; +## Helper & Error Text + +Helper and error text can be used inside of a checkbox with the `helperText` and `errorText` property. The error text will not be displayed unless the `ion-invalid` and `ion-touched` classes are added to the `ion-checkbox`. This ensures errors are not shown before the user has a chance to enter data. + +In Angular, this is done automatically through form validation. In JavaScript, React and Vue, the class needs to be manually added based on your own validation. + +import HelperError from '@site/static/usage/v8/checkbox/helper-error/index.md'; + + + ## Theming ### CSS Custom Properties diff --git a/static/usage/v8/checkbox/helper-error/angular/example_component_html.md b/static/usage/v8/checkbox/helper-error/angular/example_component_html.md new file mode 100644 index 00000000000..fc7a66dffbf --- /dev/null +++ b/static/usage/v8/checkbox/helper-error/angular/example_component_html.md @@ -0,0 +1,11 @@ +```html +
+ + I agree to the terms and conditions + + +
+ + Submit +
+``` diff --git a/static/usage/v8/checkbox/helper-error/angular/example_component_ts.md b/static/usage/v8/checkbox/helper-error/angular/example_component_ts.md new file mode 100644 index 00000000000..d8611d00de6 --- /dev/null +++ b/static/usage/v8/checkbox/helper-error/angular/example_component_ts.md @@ -0,0 +1,29 @@ +```ts +import { Component } from '@angular/core'; +import { FormBuilder, FormGroup, Validators, ReactiveFormsModule } from '@angular/forms'; +import { IonCheckbox, IonButton } from '@ionic/angular/standalone'; + +@Component({ + selector: 'app-example', + standalone: true, + imports: [IonCheckbox, IonButton, ReactiveFormsModule], + templateUrl: './example.component.html', + styleUrl: './example.component.css', +}) +export class ExampleComponent { + myForm: FormGroup; + + constructor(private fb: FormBuilder) { + this.myForm = this.fb.group({ + agree: [false, Validators.requiredTrue], + }); + } + + onSubmit() { + // Mark the control as touched to trigger the error message. + // This is needed if the user submits the form without interacting + // with the checkbox. + this.myForm.get('agree')!.markAsTouched(); + } +} +``` diff --git a/static/usage/v8/checkbox/helper-error/demo.html b/static/usage/v8/checkbox/helper-error/demo.html new file mode 100644 index 00000000000..d3fbbd826bd --- /dev/null +++ b/static/usage/v8/checkbox/helper-error/demo.html @@ -0,0 +1,58 @@ + + + + + + Input + + + + + + + +
+
+ + I agree to the terms and conditions + + +
+ + Submit +
+
+ + + + diff --git a/static/usage/v8/checkbox/helper-error/index.md b/static/usage/v8/checkbox/helper-error/index.md new file mode 100644 index 00000000000..8a49f53d9c8 --- /dev/null +++ b/static/usage/v8/checkbox/helper-error/index.md @@ -0,0 +1,24 @@ +import Playground from '@site/src/components/global/Playground'; + +import javascript from './javascript.md'; +import react from './react.md'; +import vue from './vue.md'; + +import angular_example_component_html from './angular/example_component_html.md'; +import angular_example_component_ts from './angular/example_component_ts.md'; + + diff --git a/static/usage/v8/checkbox/helper-error/javascript.md b/static/usage/v8/checkbox/helper-error/javascript.md new file mode 100644 index 00000000000..a32c9c71641 --- /dev/null +++ b/static/usage/v8/checkbox/helper-error/javascript.md @@ -0,0 +1,37 @@ +```html +
+ + I agree to the terms and conditions + + +
+ + Submit +
+ + +``` diff --git a/static/usage/v8/checkbox/helper-error/react.md b/static/usage/v8/checkbox/helper-error/react.md new file mode 100644 index 00000000000..ef695b4666d --- /dev/null +++ b/static/usage/v8/checkbox/helper-error/react.md @@ -0,0 +1,52 @@ +```tsx +import React, { useRef, useState } from 'react'; +import { IonCheckbox, IonButton, CheckboxCustomEvent } from '@ionic/react'; + +function Example() { + const [isTouched, setIsTouched] = useState(false); + const [isValid, setIsValid] = useState(); + + const agreeRef = useRef(null); + + const validateCheckbox = (event: CheckboxCustomEvent<{ checked: boolean }>) => { + setIsTouched(true); + setIsValid(event.detail.checked); + }; + + const submit = (event: React.FormEvent) => { + event.preventDefault(); + + if (agreeRef.current) { + validateCheckbox({ detail: { checked: agreeRef.current.checked } } as CheckboxCustomEvent<{ + checked: boolean; + }>); + } + }; + + return ( + <> +
+ validateCheckbox(event)} + > + I agree to the terms and conditions + + +
+ + + Submit + +
+ + ); +} + +export default Example; +``` diff --git a/static/usage/v8/checkbox/helper-error/vue.md b/static/usage/v8/checkbox/helper-error/vue.md new file mode 100644 index 00000000000..c379c512d21 --- /dev/null +++ b/static/usage/v8/checkbox/helper-error/vue.md @@ -0,0 +1,53 @@ +```html + + + +``` From 85e39d505e1222cc94880a8afa358091b6c9d712 Mon Sep 17 00:00:00 2001 From: Maria Hutt Date: Thu, 6 Mar 2025 12:15:06 -0800 Subject: [PATCH 02/10] fix(checkbox): clean up demo --- static/usage/v8/checkbox/helper-error/demo.html | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/static/usage/v8/checkbox/helper-error/demo.html b/static/usage/v8/checkbox/helper-error/demo.html index d3fbbd826bd..bdb5e212367 100644 --- a/static/usage/v8/checkbox/helper-error/demo.html +++ b/static/usage/v8/checkbox/helper-error/demo.html @@ -6,14 +6,8 @@ Input - - + + From 2adff211d6f99342c314f440c5159fa46c84bada Mon Sep 17 00:00:00 2001 From: Maria Hutt Date: Thu, 6 Mar 2025 12:16:01 -0800 Subject: [PATCH 03/10] chore(checkbox): use dev build --- static/code/stackblitz/v8/angular/package.json | 4 ++-- static/code/stackblitz/v8/html/package.json | 2 +- static/code/stackblitz/v8/react/package.json | 4 ++-- static/code/stackblitz/v8/vue/package.json | 4 ++-- static/usage/v8/checkbox/helper-error/demo.html | 10 ++++++++-- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/static/code/stackblitz/v8/angular/package.json b/static/code/stackblitz/v8/angular/package.json index b0c78d7f466..08a4bd122c7 100644 --- a/static/code/stackblitz/v8/angular/package.json +++ b/static/code/stackblitz/v8/angular/package.json @@ -15,8 +15,8 @@ "@angular/platform-browser": "^19.0.0", "@angular/platform-browser-dynamic": "^19.0.0", "@angular/router": "^19.0.0", - "@ionic/angular": "^8.0.0", - "@ionic/core": "^8.0.0", + "@ionic/angular": "8.4.4-dev.11741206641.18dd4e91", + "@ionic/core": "8.4.4-dev.11741206641.18dd4e91", "ionicons": "7.4.0", "rxjs": "^7.8.1", "tslib": "^2.5.0", diff --git a/static/code/stackblitz/v8/html/package.json b/static/code/stackblitz/v8/html/package.json index 422f9a91f55..0766d03b13a 100644 --- a/static/code/stackblitz/v8/html/package.json +++ b/static/code/stackblitz/v8/html/package.json @@ -1,6 +1,6 @@ { "dependencies": { - "@ionic/core": "8.4.1", + "@ionic/core": "8.4.4-dev.11741206641.18dd4e91", "ionicons": "7.4.0" } } diff --git a/static/code/stackblitz/v8/react/package.json b/static/code/stackblitz/v8/react/package.json index c0803683c63..25bba4cb620 100644 --- a/static/code/stackblitz/v8/react/package.json +++ b/static/code/stackblitz/v8/react/package.json @@ -3,8 +3,8 @@ "version": "0.1.0", "private": true, "dependencies": { - "@ionic/react": "8.4.1", - "@ionic/react-router": "8.4.1", + "@ionic/react": "8.4.4-dev.11741206641.18dd4e91", + "@ionic/react-router": "8.4.4-dev.11741206641.18dd4e91", "@types/node": "^22.0.0", "@types/react": "^18.0.9", "@types/react-dom": "^18.0.4", diff --git a/static/code/stackblitz/v8/vue/package.json b/static/code/stackblitz/v8/vue/package.json index b9394bad9da..e77133a9a70 100644 --- a/static/code/stackblitz/v8/vue/package.json +++ b/static/code/stackblitz/v8/vue/package.json @@ -8,8 +8,8 @@ "preview": "vite preview" }, "dependencies": { - "@ionic/vue": "8.4.1", - "@ionic/vue-router": "8.4.1", + "@ionic/vue": "8.4.4-dev.11741206641.18dd4e91", + "@ionic/vue-router": "8.4.4-dev.11741206641.18dd4e91", "vue": "^3.2.25", "vue-router": "4.5.0" }, diff --git a/static/usage/v8/checkbox/helper-error/demo.html b/static/usage/v8/checkbox/helper-error/demo.html index bdb5e212367..d3fbbd826bd 100644 --- a/static/usage/v8/checkbox/helper-error/demo.html +++ b/static/usage/v8/checkbox/helper-error/demo.html @@ -6,8 +6,14 @@ Input - - + + From f863e2684124d123af8e228840657721ace3f34a Mon Sep 17 00:00:00 2001 From: Maria Hutt Date: Tue, 11 Mar 2025 08:27:52 -0700 Subject: [PATCH 04/10] Update static/usage/v8/checkbox/helper-error/react.md Co-authored-by: Brandy Smith --- static/usage/v8/checkbox/helper-error/react.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/static/usage/v8/checkbox/helper-error/react.md b/static/usage/v8/checkbox/helper-error/react.md index ef695b4666d..7c861fce639 100644 --- a/static/usage/v8/checkbox/helper-error/react.md +++ b/static/usage/v8/checkbox/helper-error/react.md @@ -31,8 +31,8 @@ function Example() { className={`${isValid ? 'ion-valid' : ''} ${isValid === false ? 'ion-invalid' : ''} ${ isTouched ? 'ion-touched' : '' }`} - helperText="This needs to be checked" - errorText="This field is required" + helperText="Agree to the terms before continuing" + errorText="You must agree to the terms to continue" onIonChange={(event) => validateCheckbox(event)} > I agree to the terms and conditions From 5e0c99bf0dc09efcd35985bf96c5fb6f4f266156 Mon Sep 17 00:00:00 2001 From: Maria Hutt Date: Tue, 11 Mar 2025 08:28:03 -0700 Subject: [PATCH 05/10] Update static/usage/v8/checkbox/helper-error/angular/example_component_html.md Co-authored-by: Brandy Smith --- .../v8/checkbox/helper-error/angular/example_component_html.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/usage/v8/checkbox/helper-error/angular/example_component_html.md b/static/usage/v8/checkbox/helper-error/angular/example_component_html.md index fc7a66dffbf..3875731c7e3 100644 --- a/static/usage/v8/checkbox/helper-error/angular/example_component_html.md +++ b/static/usage/v8/checkbox/helper-error/angular/example_component_html.md @@ -1,6 +1,6 @@ ```html
- + I agree to the terms and conditions From 53e9e14b67c55f065fc29160adab2488881c8794 Mon Sep 17 00:00:00 2001 From: Maria Hutt Date: Tue, 11 Mar 2025 08:28:14 -0700 Subject: [PATCH 06/10] Update static/usage/v8/checkbox/helper-error/demo.html Co-authored-by: Brandy Smith --- static/usage/v8/checkbox/helper-error/demo.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/usage/v8/checkbox/helper-error/demo.html b/static/usage/v8/checkbox/helper-error/demo.html index d3fbbd826bd..23d41942ae7 100644 --- a/static/usage/v8/checkbox/helper-error/demo.html +++ b/static/usage/v8/checkbox/helper-error/demo.html @@ -19,7 +19,7 @@
- + I agree to the terms and conditions From 35a7a7822b3921899ee54df0152fe097ae323913 Mon Sep 17 00:00:00 2001 From: Maria Hutt Date: Tue, 11 Mar 2025 08:28:24 -0700 Subject: [PATCH 07/10] Update static/usage/v8/checkbox/helper-error/javascript.md Co-authored-by: Brandy Smith --- static/usage/v8/checkbox/helper-error/javascript.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/usage/v8/checkbox/helper-error/javascript.md b/static/usage/v8/checkbox/helper-error/javascript.md index a32c9c71641..0f7d8901ae2 100644 --- a/static/usage/v8/checkbox/helper-error/javascript.md +++ b/static/usage/v8/checkbox/helper-error/javascript.md @@ -1,6 +1,6 @@ ```html - + I agree to the terms and conditions From 4a03051b70fc3d97e8deb1b42f3fe2df9f099c52 Mon Sep 17 00:00:00 2001 From: Maria Hutt Date: Tue, 11 Mar 2025 08:28:32 -0700 Subject: [PATCH 08/10] Update static/usage/v8/checkbox/helper-error/vue.md Co-authored-by: Brandy Smith --- static/usage/v8/checkbox/helper-error/vue.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/static/usage/v8/checkbox/helper-error/vue.md b/static/usage/v8/checkbox/helper-error/vue.md index c379c512d21..c16488da230 100644 --- a/static/usage/v8/checkbox/helper-error/vue.md +++ b/static/usage/v8/checkbox/helper-error/vue.md @@ -3,8 +3,8 @@ From b2d6cffc6bd98e625b00473aad8469e05086756c Mon Sep 17 00:00:00 2001 From: Maria Hutt Date: Tue, 11 Mar 2025 09:12:25 -0700 Subject: [PATCH 09/10] chore(checkbox): run lint --- .../checkbox/helper-error/angular/example_component_html.md | 6 +++++- static/usage/v8/checkbox/helper-error/demo.html | 5 ++++- static/usage/v8/checkbox/helper-error/vue.md | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/static/usage/v8/checkbox/helper-error/angular/example_component_html.md b/static/usage/v8/checkbox/helper-error/angular/example_component_html.md index 3875731c7e3..7153841ac36 100644 --- a/static/usage/v8/checkbox/helper-error/angular/example_component_html.md +++ b/static/usage/v8/checkbox/helper-error/angular/example_component_html.md @@ -1,6 +1,10 @@ ```html - + I agree to the terms and conditions diff --git a/static/usage/v8/checkbox/helper-error/demo.html b/static/usage/v8/checkbox/helper-error/demo.html index 23d41942ae7..71c96781366 100644 --- a/static/usage/v8/checkbox/helper-error/demo.html +++ b/static/usage/v8/checkbox/helper-error/demo.html @@ -19,7 +19,10 @@
- + I agree to the terms and conditions diff --git a/static/usage/v8/checkbox/helper-error/vue.md b/static/usage/v8/checkbox/helper-error/vue.md index c16488da230..46b554c9553 100644 --- a/static/usage/v8/checkbox/helper-error/vue.md +++ b/static/usage/v8/checkbox/helper-error/vue.md @@ -3,7 +3,7 @@ Date: Tue, 11 Mar 2025 11:52:03 -0700 Subject: [PATCH 10/10] chore(checkbox): remove dev build --- static/code/stackblitz/v8/angular/package.json | 4 ++-- static/code/stackblitz/v8/html/package.json | 2 +- static/code/stackblitz/v8/react/package.json | 4 ++-- static/code/stackblitz/v8/vue/package.json | 4 ++-- static/usage/v8/checkbox/helper-error/demo.html | 10 ++-------- 5 files changed, 9 insertions(+), 15 deletions(-) diff --git a/static/code/stackblitz/v8/angular/package.json b/static/code/stackblitz/v8/angular/package.json index 08a4bd122c7..b0c78d7f466 100644 --- a/static/code/stackblitz/v8/angular/package.json +++ b/static/code/stackblitz/v8/angular/package.json @@ -15,8 +15,8 @@ "@angular/platform-browser": "^19.0.0", "@angular/platform-browser-dynamic": "^19.0.0", "@angular/router": "^19.0.0", - "@ionic/angular": "8.4.4-dev.11741206641.18dd4e91", - "@ionic/core": "8.4.4-dev.11741206641.18dd4e91", + "@ionic/angular": "^8.0.0", + "@ionic/core": "^8.0.0", "ionicons": "7.4.0", "rxjs": "^7.8.1", "tslib": "^2.5.0", diff --git a/static/code/stackblitz/v8/html/package.json b/static/code/stackblitz/v8/html/package.json index 0766d03b13a..422f9a91f55 100644 --- a/static/code/stackblitz/v8/html/package.json +++ b/static/code/stackblitz/v8/html/package.json @@ -1,6 +1,6 @@ { "dependencies": { - "@ionic/core": "8.4.4-dev.11741206641.18dd4e91", + "@ionic/core": "8.4.1", "ionicons": "7.4.0" } } diff --git a/static/code/stackblitz/v8/react/package.json b/static/code/stackblitz/v8/react/package.json index 25bba4cb620..c0803683c63 100644 --- a/static/code/stackblitz/v8/react/package.json +++ b/static/code/stackblitz/v8/react/package.json @@ -3,8 +3,8 @@ "version": "0.1.0", "private": true, "dependencies": { - "@ionic/react": "8.4.4-dev.11741206641.18dd4e91", - "@ionic/react-router": "8.4.4-dev.11741206641.18dd4e91", + "@ionic/react": "8.4.1", + "@ionic/react-router": "8.4.1", "@types/node": "^22.0.0", "@types/react": "^18.0.9", "@types/react-dom": "^18.0.4", diff --git a/static/code/stackblitz/v8/vue/package.json b/static/code/stackblitz/v8/vue/package.json index e77133a9a70..b9394bad9da 100644 --- a/static/code/stackblitz/v8/vue/package.json +++ b/static/code/stackblitz/v8/vue/package.json @@ -8,8 +8,8 @@ "preview": "vite preview" }, "dependencies": { - "@ionic/vue": "8.4.4-dev.11741206641.18dd4e91", - "@ionic/vue-router": "8.4.4-dev.11741206641.18dd4e91", + "@ionic/vue": "8.4.1", + "@ionic/vue-router": "8.4.1", "vue": "^3.2.25", "vue-router": "4.5.0" }, diff --git a/static/usage/v8/checkbox/helper-error/demo.html b/static/usage/v8/checkbox/helper-error/demo.html index 71c96781366..f16fd9b8503 100644 --- a/static/usage/v8/checkbox/helper-error/demo.html +++ b/static/usage/v8/checkbox/helper-error/demo.html @@ -6,14 +6,8 @@ Input - - + +