Skip to content

Latest commit

 

History

History
134 lines (77 loc) · 4.75 KB

File metadata and controls

134 lines (77 loc) · 4.75 KB
title ion-radio

import Props from '@ionic-internal/component-api/v8/radio/props.md'; import Events from '@ionic-internal/component-api/v8/radio/events.md'; import Methods from '@ionic-internal/component-api/v8/radio/methods.md'; import Parts from '@ionic-internal/component-api/v8/radio/parts.md'; import CustomProps from '@ionic-internal/component-api/v8/radio/custom-props.mdx'; import Slots from '@ionic-internal/component-api/v8/radio/slots.md';

<title>ion-radio: Radio Component for iOS and Android</title>

import EncapsulationPill from '@components/page/api/EncapsulationPill';

Radios should be used inside of a radio group. Pressing a radio will check it and uncheck the previously selected radio, if there is one. They can also be checked programmatically by setting the value property of the parent radio group to the value of the radio.

When radios are inside of a radio group, only one radio will be checked at any time. If more than one item should be selected, checkboxes should be used instead. Radios can be disabled within a group to prevent interaction with them.

Basic Usage

import Basic from '@site/static/usage/v8/radio/basic/index.md';

Label Placement

Developers can use the labelPlacement property to control how the label is placed relative to the control. This property mirrors the flexbox flex-direction property.

import LabelPlacement from '@site/static/usage/v8/radio/label-placement/index.md';

Label Wrapping

Regardless of label placement, long text will not wrap by default. If the width of the radio is constrained, overflowing text will be truncated with an ellipsis. You can enable text wrapping by adding the ion-text-wrap class to a wrapper around the radio text or styling the label shadow part using the ::part() selector.

import LabelWrap from '@site/static/usage/v8/radio/label-wrap/index.md';

Object Value References

By default, the radio group uses strict equality (===) to determine if an option is selected. This can be overridden by providing a property name or a function to the compareWith property.

import UsingComparewith from '@site/static/usage/v8/radio/using-comparewith/index.md';

Alignment

Developers can use the alignment property to control how the label and control are aligned on the cross axis. This property mirrors the flexbox align-items property.

:::note Stacked radios can be aligned using the alignment property. This can be useful when the label and control need to be centered horizontally. :::

import Alignment from '@site/static/usage/v8/radio/alignment/index.md';

Justification

Developers can use the justify property to control how the label and control are packed on a line. This property mirrors the flexbox justify-content property.

import Justify from '@site/static/usage/v8/radio/justify/index.md';

:::note ion-item is only used in the demos to emphasize how justify works. It is not needed in order for justify to function correctly. :::

Deselecting Radios

By default, once a radio is selected it cannot be deselected; pressing it again will keep it selected. This behavior can be modified by using the allowEmptySelection property on the parent radio group, which enables the radios to be deselected.

import EmptySelection from '@site/static/usage/v8/radio/empty-selection/index.md';

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

Theming

Colors

import Colors from '@site/static/usage/v8/radio/theming/colors/index.md';

CSS Custom Properties

import CSSProps from '@site/static/usage/v8/radio/theming/css-properties/index.md';

CSS Shadow Parts

import CSSParts from '@site/static/usage/v8/radio/theming/css-shadow-parts/index.md';

Properties

Events

Methods

CSS Shadow Parts

CSS Custom Properties

Slots