Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/api/checkbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ import LabelLink from '@site/static/usage/v8/checkbox/label-link/index.md';

<LabelLink />

## 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';

<HelperError />

## Theming

### CSS Custom Properties
Expand Down
8 changes: 8 additions & 0 deletions docs/api/modal.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ import SheetHandleBehaviorExample from '@site/static/usage/v8/modal/sheet/handle

<SheetHandleBehaviorExample />

### Scrolling content at all breakpoints

Sheet modals can be configured to allow scrolling content at all breakpoints, making them ideal for displaying content larger than the viewport. By setting the `expandToScroll` property to `false`, the content remains scrollable at every breakpoint. Otherwise, by default, scrolling is only enabled when the sheet modal is fully expanded.

import SheetScrollingContentExample from '@site/static/usage/v8/modal/sheet/expand-to-scroll/index.md';

<SheetScrollingContentExample />

## Styling

Modals are presented at the root of your application so they overlay your entire app. This behavior applies to both inline modals and modals presented from a controller. As a result, custom modal styles can not be scoped to a particular component as they will not apply to the modal. Instead, styles must be applied globally. For most developers, placing the custom styles in `global.css` is sufficient.
Expand Down
10 changes: 10 additions & 0 deletions docs/api/radio.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ import EmptySelection from '@site/static/usage/v8/radio/empty-selection/index.md

<EmptySelection />

## Helper & Error Text

Helper and error text can be used inside of a radio group 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-radio-group`. 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/radio/helper-error/index.md';

<HelperError />


## Theming

Expand Down
10 changes: 10 additions & 0 deletions docs/api/select.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,16 @@ import TypeaheadExample from '@site/static/usage/v8/select/typeahead/index.md';

<TypeaheadExample />

## Helper & Error Text

Helper and error text can be used inside of a select 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-select`. 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/select/helper-error/index.md';

<HelperError />

## Interfaces

### SelectChangeEventDetail
Expand Down
10 changes: 10 additions & 0 deletions docs/api/toggle.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ import Justify from '@site/static/usage/v8/toggle/justify/index.md';

<Justify />

## Helper & Error Text

Helper and error text can be used inside of a toggle 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-toggle`. 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/toggle/helper-error/index.md';

<HelperError />

## Theming

### Colors
Expand Down
1 change: 1 addition & 0 deletions docs/developing/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ Below are the config options that Ionic uses.
| `loadingEnter` | `AnimationBuilder` | Provides a custom enter animation for all `ion-loading`, overriding the default "animation". |
| `loadingLeave` | `AnimationBuilder` | Provides a custom leave animation for all `ion-loading`, overriding the default "animation". |
| `loadingSpinner` | `SpinnerTypes` | Overrides the default spinner for all `ion-loading` overlays. |
| `logLevel` | `'OFF' \| 'ERROR' \| 'WARN'` | Configures the logging level for Ionic Framework. If `'OFF'`, no errors or warnings are logged. If `'ERROR'`, only errors are logged. If `'WARN'`, errors and warnings are logged. |
| `menuIcon` | `string` | Overrides the default icon in all `<ion-menu-button>` components. |
| `menuType` | `string` | Overrides the default menu type for all `<ion-menu>` components. |
| `modalEnter` | `AnimationBuilder` | Provides a custom enter animation for all `ion-modal`, overriding the default "animation". |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
```html
<form [formGroup]="myForm" (ngSubmit)="onSubmit()">
<ion-checkbox
formControlName="agree"
helperText="Agree to the terms before continuing"
errorText="You must agree to the terms to continue"
>
I agree to the terms and conditions
</ion-checkbox>

<br />

<ion-button type="submit" size="small">Submit</ion-button>
</form>
```
Original file line number Diff line number Diff line change
@@ -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();
}
}
```
55 changes: 55 additions & 0 deletions static/usage/v8/checkbox/helper-error/demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Input</title>
<link rel="stylesheet" href="../../common.css" />
<script src="../../common.js"></script>
<script type="module" src="https://cdn.jsdelivr.net/npm/@ionic/core@8/dist/ionic/ionic.esm.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@ionic/core@8/css/ionic.bundle.css" />
</head>

<body>
<div class="container">
<form id="my-form">
<ion-checkbox
helper-text="Agree to the terms before continuing"
error-text="You must agree to the terms to continue"
>
I agree to the terms and conditions
</ion-checkbox>

<br />

<ion-button type="submit" size="small">Submit</ion-button>
</form>
</div>

<script>
const form = document.getElementById('my-form');
const agree = form.querySelector('ion-checkbox');

form.addEventListener('submit', (event) => submit(event));
agree.addEventListener('ionChange', (event) => validateCheckbox(event));

const validateCheckbox = (event) => {
agree.classList.add('ion-touched');

if (!event.detail.checked) {
agree.classList.add('ion-invalid');
agree.classList.remove('ion-valid');
} else {
agree.classList.remove('ion-invalid');
agree.classList.add('ion-valid');
}
};

const submit = (event) => {
event.preventDefault();

validateCheckbox({ detail: { checked: agree.checked } });
};
</script>
</body>
</html>
24 changes: 24 additions & 0 deletions static/usage/v8/checkbox/helper-error/index.md
Original file line number Diff line number Diff line change
@@ -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';

<Playground
version="8"
code={{
javascript,
react,
vue,
angular: {
files: {
'src/app/example.component.html': angular_example_component_html,
'src/app/example.component.ts': angular_example_component_ts,
},
},
}}
src="usage/v8/checkbox/helper-error/demo.html"
/>
37 changes: 37 additions & 0 deletions static/usage/v8/checkbox/helper-error/javascript.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
```html
<form id="my-form">
<ion-checkbox helper-text="Agree to the terms before continuing" error-text="You must agree to the terms to continue">
I agree to the terms and conditions
</ion-checkbox>

<br />

<ion-button type="submit" size="small">Submit</ion-button>
</form>

<script>
const form = document.getElementById('my-form');
const agree = form.querySelector('ion-checkbox');

form.addEventListener('submit', (event) => submit(event));
agree.addEventListener('ionChange', (event) => validateCheckbox(event));

const validateCheckbox = (event) => {
agree.classList.add('ion-touched');

if (!event.detail.checked) {
agree.classList.add('ion-invalid');
agree.classList.remove('ion-valid');
} else {
agree.classList.remove('ion-invalid');
agree.classList.add('ion-valid');
}
};

const submit = (event) => {
event.preventDefault();

validateCheckbox({ detail: { checked: agree.checked } });
};
</script>
```
52 changes: 52 additions & 0 deletions static/usage/v8/checkbox/helper-error/react.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
```tsx
import React, { useRef, useState } from 'react';
import { IonCheckbox, IonButton, CheckboxCustomEvent } from '@ionic/react';

function Example() {
const [isTouched, setIsTouched] = useState<boolean>(false);
const [isValid, setIsValid] = useState<boolean | undefined>();

const agreeRef = useRef<HTMLIonCheckboxElement>(null);

const validateCheckbox = (event: CheckboxCustomEvent<{ checked: boolean }>) => {
setIsTouched(true);
setIsValid(event.detail.checked);
};

const submit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();

if (agreeRef.current) {
validateCheckbox({ detail: { checked: agreeRef.current.checked } } as CheckboxCustomEvent<{
checked: boolean;
}>);
}
};

return (
<>
<form onSubmit={submit}>
<IonCheckbox
ref={agreeRef}
className={`${isValid ? 'ion-valid' : ''} ${isValid === false ? 'ion-invalid' : ''} ${
isTouched ? 'ion-touched' : ''
}`}
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
</IonCheckbox>

<br />

<IonButton type="submit" size="small">
Submit
</IonButton>
</form>
</>
);
}

export default Example;
```
53 changes: 53 additions & 0 deletions static/usage/v8/checkbox/helper-error/vue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
```html
<template>
<form @submit.prevent="submit">
<ion-checkbox
v-model="agree"
helper-text="Agree to the terms before continuing"
error-text="You must agree to the terms to continue"
@ionChange="validateCheckbox"
:class="{ 'ion-valid': isValid, 'ion-invalid': isValid === false, 'ion-touched': isTouched }"
>
I agree to the terms and conditions
</ion-checkbox>

<br />

<ion-button type="submit" size="small">Submit</ion-button>
</form>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue';
import { IonCheckbox, IonButton, CheckboxCustomEvent } from '@ionic/vue';

export default defineComponent({
components: {
IonCheckbox,
IonButton,
},
setup() {
const agree = ref(false);
const isTouched = ref(false);
const isValid = ref<boolean | undefined>();

const validateCheckbox = (event: CheckboxCustomEvent<{ checked: boolean }>) => {
isTouched.value = true;
isValid.value = event.detail.checked;
};

const submit = () => {
validateCheckbox({ detail: { checked: agree.value } } as CheckboxCustomEvent<{ checked: boolean }>);
};

return {
agree,
isTouched,
isValid,
validateCheckbox,
submit,
};
},
});
</script>
```
Loading