メインコンテンツまでスキップ
Version: v6

ion-toggle

shadow

Toggles are switches that change the state of a single option. They can be switched on or off by pressing or swiping them. Toggles can also be checked programmatically by setting the checked property.

Basic Usage

On / Off Labels

Toggles can enable on/off labels by setting the enableOnOffLabels property. This is important for accessibility as it makes it easier to differentiate between a checked and unchecked toggle.

Theming

Colors

CSS Custom Properties

CSS custom properties can be combined with standard CSS to target different parts of a toggle. We can modify the width and height of the toggle directly to change the size of the track, while using the --handle-width and --handle-height custom properties to customize the handle size.

CSS Shadow Parts

We can further customize toggle by targeting specific shadow parts that are exposed. Any CSS property on these parts can be styled and they can also be combined with CSS custom properties.

Interfaces

ToggleChangeEventDetail

interface ToggleChangeEventDetail<T = any> {
value: T;
checked: boolean;
}

ToggleCustomEvent

必須ではありませんが、このコンポーネントから発行される Ionic イベントでより強く型付けを行うために、CustomEvent インターフェースの代わりにこのインターフェースを使用することが可能です。

interface ToggleCustomEvent<T = any> extends CustomEvent {
detail: ToggleChangeEventDetail<T>;
target: HTMLIonToggleElement;
}

Properties

checked

DescriptionIf true, the toggle is selected.
Attributechecked
Typeboolean
Defaultfalse

color

DescriptionThe color to use from your application's color palette. Default options are: "primary", "secondary", "tertiary", "success", "warning", "danger", "light", "medium", and "dark". For more information on colors, see theming.
Attributecolor
Type"danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string & Record<never, never> | undefined
Defaultundefined

disabled

DescriptionIf true, the user cannot interact with the toggle.
Attributedisabled
Typeboolean
Defaultfalse

enableOnOffLabels

DescriptionEnables the on/off accessibility switch labels within the toggle.
Attributeenable-on-off-labels
Typeboolean | undefined
Defaultundefined

mode

DescriptionThe mode determines which platform styles to use.
Attributemode
Type"ios" | "md"
Defaultundefined

name

DescriptionThe name of the control, which is submitted with the form data.
Attributename
Typestring
Defaultthis.inputId

value

DescriptionThe value of the toggle does not mean if it's checked or not, use the checked property for that.

The value of a toggle is analogous to the value of a <input type="checkbox">, it's only used when the toggle participates in a native <form>.
Attributevalue
Typenull | string | undefined
Default'on'

イベント

NameDescription
ionBlurEmitted when the toggle loses focus.
ionChangeEmitted when the value property has changed.
ionFocusEmitted when the toggle has focus.

メソッド

No public methods available for this component.

CSS Shadow Parts

NameDescription
handleThe toggle handle, or knob, used to change the checked state.
trackThe background track of the toggle.

CSSカスタムプロパティ

NameDescription
--backgroundBackground of the toggle
--background-checkedBackground of the toggle when checked
--border-radiusBorder radius of the toggle track
--handle-backgroundBackground of the toggle handle
--handle-background-checkedBackground of the toggle handle when checked
--handle-border-radiusBorder radius of the toggle handle
--handle-box-shadowBox shadow of the toggle handle
--handle-heightHeight of the toggle handle
--handle-max-heightMaximum height of the toggle handle
--handle-spacingHorizontal spacing around the toggle handle
--handle-transitionTransition of the toggle handle
--handle-widthWidth of the toggle handle

Slots

No slots available for this component.