Skip to main content
Version: v7 (beta)

ion-range

shadow

Rangeスライダは、スライダノブを動かして、ユーザーが値の範囲を選択できるようにするものです。デフォルトでは、1つのノブがレンジの値を制御します。この動作は dual knobs を使ってカスタマイズすることができます。

デフォルトでは、Rangeスライダーの最小値は0、最大値は100です。これは minmax プロパティで設定することができます。

基本的な使い方

Label Placement

Decorations

Decorative elements can be passed into the start or end slots of the range. This is useful for adding icons such as low volume or high volume icons. Since these elements are decorative, they should not be announced by assistive technology such as screen readers.

If the directionality of the document is set to left to right, the contents slotted to the start position will display to the left of the range, where as contents slotted to the end position will display to the right of the range. In right to left (rtl) directionality, the contents slotted to the start position will display to the right of the range, where as contents slotted to the end position will display to the left of the range.

Dual Knobs

Dual knobs はユーザーが下限と上限の値を選択するために使用できる2つのknobsコントロールを導入しています。選択されると、Range は選択された上下限の値を含む RangeValue を持つ ionChange イベントを発信します。

ピン

pin 属性は、ドラッグしたときにノブの上にレンジの値を表示します。これにより、ユーザはRange内の特定の値を選択することができます。

pinFormatter 関数を使用すると、開発者はユーザーに対してレンジの値のフォーマットをカスタマイズすることができます。

Snapping & Ticks

TicksはRange 上で利用可能な各値のインジケータを表示します。Ticksを使用するためには、開発者は snapsticks プロパティの両方を true に設定する必要があります。

snapsを有効にし、knobをドラッグして放すと、Range knobは最も近い利用可能な値にスナップします。

イベントハンドリング

Using ionChange

ionChange イベントはRange knobの値の変更を監視します。

ionKnobMoveStartionKnobMoveEnd を使う

マウスドラッグ、タッチジェスチャー、キーボード操作のいずれであっても、Range knobのドラッグが開始されると ionKnobMoveStart イベントが発行されます。逆に、ionKnobMoveEndはRange knobがリリースされたときに発生します。両イベントは RangeValue タイプで発生し、dualKnobs プロパティと組み合わせて動作します。

テーマ

CSSカスタムプロパティ

Rangeには、アプリケーションのデザインに合わせてRangeコンポーネントの外観を素早くテーマ化してカスタマイズするためのCSS Variablesが含まれています。

CSS Shadow Parts

Rangeには CSS Shadow Parts があり、Rangeコンポーネント内の特定の要素ノードを完全にカスタマイズすることができます。CSS Shadow Partsは最も多くのカスタマイズ機能を提供し、Rangeコンポーネントで高度なスタイリングが必要な場合に推奨されるアプローチです。

Migrating from Legacy Range Syntax

A simpler range syntax was introduced in Ionic 7.0. This new syntax reduces the boilerplate required to setup an range, resolves accessibility issues, and improves the developer experience.

Developers can perform this migration one range at a time. While developers can continue using the legacy syntax, we recommend migrating as soon as possible.

最新の構文の使い方

Using the modern syntax involves removing the ion-label and passing the label directly inside of ion-range using slot="label". The placement of the label can be configured using the labelPlacement property on ion-range.

<!-- Basic -->

<!-- Before -->
<ion-item>
<ion-label>Notifications</ion-label>
<ion-range></ion-range>
</ion-item>

<!-- After -->
<ion-item>
<ion-range>
<div slot="label">Notifications</div>
</ion-range>
</ion-item>

<!-- Fixed Labels -->

<!-- Before -->
<ion-item>
<ion-label position="fixed">Notifications</ion-label>
<ion-range></ion-range>
</ion-item>

<!-- After -->
<ion-item>
<ion-range label-placement="fixed">
<div slot="label">Notifications</div>
</ion-range>
</ion-item>

<!-- Range at the start of line, Label at the end of line -->

<!-- Before -->
<ion-item>
<ion-label slot="end">Notifications</ion-label>
<ion-range></ion-range>
</ion-item>

<!-- After -->
<ion-item>
<ion-range label-placement="end">
<div slot="label">Notifications</div>
</ion-range>
</ion-item>
note

In past versions of Ionic, ion-item was required for ion-range to function properly. Starting in Ionic 7.0, ion-range should only be used in an ion-item when the item is placed in an ion-list. Additionally, ion-item is no longer required for ion-range to function properly.

Using the Legacy Syntax

Ionic uses heuristics to detect if an app is using the modern range syntax. In some instances, it may be preferable to continue using the legacy syntax. Developers can set the legacy property on ion-range to true to force that instance of the range to use the legacy syntax.

Interfaces

RangeChangeEventDetail

interface RangeChangeEventDetail {
value: RangeValue;
}

RangeKnobMoveStartEventDetail

interface RangeKnobMoveStartEventDetail {
value: RangeValue;
}

RangeKnobMoveEndEventDetail

interface RangeKnobMoveEndEventDetail {
value: RangeValue;
}

RangeCustomEvent

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

interface RangeCustomEvent extends CustomEvent {
detail: RangeChangeEventDetail;
target: HTMLIonRangeElement;
}

Types

RangeValue

type RangeValue = number | { lower: number, upper: number };

プロパティ

activeBarStart

Descriptionレンジアクティブバーの開始位置です。この機能は、ノブが1つの場合のみ有効です(dualKnobs="false")。有効な値は、min値以上、max値以下です。
Attributeactive-bar-start
Typenumber | undefined
Defaultundefined

color

Descriptionアプリケーションのカラーパレットから使用する色を指定します。デフォルトのオプションは以下の通りです。 "primary", "secondary", "tertiary", "success", "warning", "danger", "light", "medium", と "dark" です.色に関する詳しい情報は theming を参照してください。
Attributecolor
Type"danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string & Record<never, never> | undefined
Defaultundefined

debounce

Description範囲の値が変化するたびに ionChange イベントを起動するまでの待ち時間をミリ秒単位で指定します。これは ngModelv-model のようなフォームバインディングにも影響します。
Attributedebounce
Typenumber
Default0

disabled

Descriptiontrueの場合、ユーザは範囲と対話することができません。
Attributedisabled
Typeboolean
Defaultfalse

dualKnobs

Description2つのノブを表示します。
Attributedual-knobs
Typeboolean
Defaultfalse

max

Description範囲の最大整数値。
Attributemax
Typenumber
Default100

min

Description範囲の最小の整数値。
Attributemin
Typenumber
Default0

mode

Descriptionmodeは、どのプラットフォームのスタイルを使用するかを決定します。
Attributemode
Type"ios" | "md"
Defaultundefined

name

Descriptionフォームデータとともに送信されるコントロールの名前。
Attributename
Typestring
Default''

pin

Descriptiontrueの場合、ノブを押したときに整数値のピンが表示されます。
Attributepin
Typeboolean
Defaultfalse

pinFormatter

Descriptionピンのテキストをフォーマットするために使用されるコールバックです。デフォルトでは、ピンのテキストは Math.round(value) に設定されます。
Attributeundefined
Type(value: number) => string | number
Default(value: number): number => Math.round(value)

snaps

Descriptiontrueの場合、ノブはステッププロパティの値に基づいて等間隔に配置されたティックマークにスナップします。
Attributesnaps
Typeboolean
Defaultfalse

step

Description値の粒度を指定します。
Attributestep
Typenumber
Default1

ticks

Descriptiontrueの場合、ステップの値に基づいてティックマークを表示します。snapstrue` の場合のみ適用される。
Attributeticks
Typeboolean
Defaulttrue

value

Description範囲の値です。
Attributevalue
Typenumber | { lower: number; upper: number; }
Default0

イベント

NameDescription
ionBlurレンジの焦点が合わなくなったときに発します。
ionChangevalueプロパティが変更されたときに発行されます。
ionFocusレンジのフォーカスが合ったときに発します。
ionKnobMoveEndマウスドラッグ、タッチジェスチャー、キーボード操作など、ユーザーが範囲ノブの移動を終了したときに発行されます。
ionKnobMoveStartマウスドラッグ、タッチジェスチャー、キーボード操作など、ユーザーがレンジノブの移動を開始したときに発行されます。

メソッド

No public methods available for this component.

CSS Shadow Parts

NameDescription
barバーの非アクティブな部分。
bar-activeバーのアクティブな部分です。
knob範囲をドラッグする際に使用するハンドル。
pinノブの上に表示されるカウンターです。
tick非アクティブなティックマークです。
tick-activeアクティブなティックマークです。

CSSカスタムプロパティ

NameDescription
--bar-backgroundレンジバーの背景
--bar-background-activeアクティブレンジバーの背景
--bar-border-radiusレンジバーのボーダー半径
--bar-heightレンジバーの高さ
--heightレンジの高さ
--knob-backgroundレンジノブの背景
--knob-border-radiusレンジツマミのボーダー半径
--knob-box-shadowレンジノブのボックスシャドウ
--knob-sizeレンジツマミの大きさ
--pin-backgroundレンジピンの背景(MD mode時のみ有効)
--pin-colorレンジピンの色(MD mode時のみ有効)

Slots

NameDescription
endコンテンツは、LTRでは範囲スライダーの右側に、RTLでは左側に配置されます。
startコンテンツは、LTRでは範囲スライダーの左側に、RTLでは右側に配置されます。