ion-range
Rangeスライダは、スライダノブを動かして、ユーザーが値の範囲を選択できるようにするものです。デフォルトでは、1つのノブがレンジの値を制御します。この動作は dual knobs を使ってカスタマイズすることができます。
デフォルトでは、Rangeスライダーの最小値は0
、最大値は100
です。これは min
と max
プロパティで設定することができます。
Labels
ラベルは、範囲を説明するために使用されるべきです。それらは視覚的に使用することができ、また、ユーザーがRangeをフォーカスしてるときに、スクリーンリーダーによって読み上げられます。これにより、ユーザーは範囲の意図を理解しやすくなります。範囲にはラベルを割り当てるいくつかの方法があります:
label
プロパティ:プレーンテキストのラベルに使用する。label
スロット:カスタム HTML ラベルに使用する。aria-label
: スクリーンリーダー用のラベルとして使用されるが、ラベルは表示されない。
Label Placement
以下のデモでは、labelPlacement
プロパティを使用して、範囲に対するラベルの位置を変更しています。ここでは label
プロパティを使用しているが、labelPlacement
は label
スロットでも使用できます。
Label Slot
プレーンテキストのラベルは label
プロパティで渡すべきであるが、カスタムHTMLが必要な場合は、代わりに label
スロットで渡すことができます。
No Visible Label
もし表示するラベルが必要ない場合でも、開発者はaria-label
を与えるべきです。
Decorations
装飾的な要素は、範囲の start
または end
スロットに渡すことができます。これは、音量の小さいアイコンや大きいアイコンのようなアイコンを追加するのに便利です。これらの要素は装飾的なものなので、スクリーンリーダーのような支援技術によってアナウンスされるべきではありません。
ドキュメントの方向性が左から右に設定されている場合、start
位置にスロットされたコンテンツは範囲の左に表示され、end
位置にスロットされたコンテンツは範囲の右に表示されます。右から左(rtl)の方向性の場合、start
位置にスロットされたコンテンツは範囲の右側に表示され、end
位置にスロットされたコンテンツは範囲の左側に表示されます。
Dual Knobs
Dual knobs はユーザーが下限と上限の値を選択するために使用できる2つのknobsコントロールを導入しています。選択されると、Range は選択された上下限の値を含む RangeValue を持つ ionChange
イベントを発信します。
ピン
pin
属性は、ドラッグしたときにノブの上にレンジの値を表示します。これにより、ユーザはRange内の特定の値を選択することができます。
pinFormatter
関数を使用すると、開発者はユーザーに対してレンジの値のフォーマットをカスタマイズすることができます。
Snapping & Ticks
TicksはRange 上で利用可能な各値のインジケータを表示します。Ticksを使用するためには、開発者は snaps
と ticks
プロパティの両方を true
に設定する必要があります。
snapsを有効にし、knobをドラッグして放すと、Range knobは最も近い利用可能な値にスナップします。
イベントハンドリング
Using ionChange
ionChange
イベントはRange knobの値の変更を監視します。
Console
Console messages will appear here when logged from the example above.
ionKnobMoveStart
と ionKnobMoveEnd
を使う
マウスドラッグ、タッチジェスチャー、キーボード操作のいずれであっても、Range knobのドラッグが開始されると ionKnobMoveStart
イベントが発行されます。逆に、ionKnobMoveEnd
はRange knobがリリースされたときに発生します。両イベントは RangeValue
タイプで発生し、dualKnobs
プロパティと組み合わせて動作します。
Console
Console messages will appear here when logged from the example above.
テーマ
CSSカスタムプロパティ
Rangeには、アプリケーションのデザインに合わせてRangeコンポーネントの外観を素早くテーマ化してカスタマイズするためのCSS Variablesが含まれています。
CSS Shadow Parts
Rangeには CSS Shadow Parts があり、Rangeコンポーネント内の特定の要素ノードを完全にカスタマイズすることができます。CSS Shadow Partsは最も多くのカスタマイズ機能を提供し、Rangeコンポーネントで高度なスタイリングが必要な場合に推奨されるアプローチです。
レガシーな範囲構文からの移行
Ionic 7.0では、よりシンプルな範囲構文が導入されました。この新しい構文は、範囲を設定するために必要な定型文を減らし、アクセシビリティの問題を解決し、開発者のエクスペリエンスを向上させます。
開発者はこの移行を範囲ごとに実行できます。開発者は従来の構文を使い続けることもできますが、できるだけ早く移行することをお勧めします。
最新の構文の使い方
最新の構文を使用するには、ion-label
を削除し、label
プロパティを使用して ion-range
にラベルを渡します。ラベルの配置は labelPlacement
プロパティを使用して設定することができます。
ラベルにカスタム HTML が必要な場合は、代わりに label
スロットを使用して ion-range
内に直接渡すことができる。
- JavaScript
- Angular
- React
- Vue
<!-- Basic -->
<!-- Before -->
<ion-item>
<ion-label>Notifications</ion-label>
<ion-range></ion-range>
</ion-item>
<!-- After -->
<ion-item>
<ion-range label="Notifications"></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" label="Notifications"></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" label="Notifications"></ion-range>
</ion-item>
<!-- Custom HTML label -->
<!-- Before -->
<ion-item>
<ion-label>
<div class="custom-label">Notifications</div>
</ion-label>
<ion-range></ion-range>
</ion-item>
<!-- After -->
<ion-item>
<ion-range>
<div slot="label" class="custom-label">Notifications</div>
</ion-range>
</ion-item>
<!-- Basic -->
<!-- Before -->
<ion-item>
<ion-label>Notifications</ion-label>
<ion-range></ion-range>
</ion-item>
<!-- After -->
<ion-item>
<ion-range label="Notifications"></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 labelPlacement="fixed" label="Notifications"></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 labelPlacement="end" label="Notifications"></ion-range>
</ion-item>
<!-- Custom HTML label -->
<!-- Before -->
<ion-item>
<ion-label>
<div class="custom-label">Notifications</div>
</ion-label>
<ion-range></ion-range>
</ion-item>
<!-- After -->
<ion-item>
<ion-range>
<div slot="label" class="custom-label">Notifications</div>
</ion-range>
</ion-item>
{/* Basic */}
{/* Before */}
<IonItem>
<IonLabel>Notifications</IonLabel>
<IonRange></IonRange>
</IonItem>
{/* After */}
<IonItem>
<IonRange label="Notifications"></IonRange>
</IonItem>
{/* Fixed Labels */}
{/* Before */}
<IonItem>
<IonLabel position="fixed">Notifications</IonLabel>
<IonRange></IonRange>
</IonItem>
{/* After */}
<IonItem>
<IonRange labelPlacement="fixed" label="Notifications"></IonRange>
</IonItem>
{/* Range at the start of line, Label at the end of line */}
{/* Before */}
<IonItem>
<IonLabel slot="end">Notifications</IonLabel>
<IonRange></IonRange>
</IonItem>
{/* After */}
<IonItem>
<IonRange labelPlacement="end" label="Notifications"></IonRange>
</IonItem>
{/* Custom HTML label */}
{/* Before */}
<IonItem>
<IonLabel>
<div className="custom-label">Notifications</div>
</IonLabel>
<IonRange></IonRange>
</IonItem>
<!-- After -->
<IonItem>
<IonRange>
<div slot="label" className="custom-label">Notifications</div>
</IonRange>
</IonItem>
<!-- Basic -->
<!-- Before -->
<ion-item>
<ion-label>Notifications</ion-label>
<ion-range></ion-range>
</ion-item>
<!-- After -->
<ion-item>
<ion-range label="Notifications"></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" label="Notifications"></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" label="Notifications"></ion-range>
</ion-item>
<!-- Custom HTML label -->
<!-- Before -->
<ion-item>
<ion-label>
<div class="custom-label">Notifications</div>
</ion-label>
<ion-range></ion-range>
</ion-item>
<!-- After -->
<ion-item>
<ion-range>
<div slot="label" class="custom-label">Notifications</div>
</ion-range>
</ion-item>
Ionic の過去のバージョンでは、ion-range
が正しく機能するためには ion-item
が必要でした。Ionic 7.0 以降では、ion-range
は ion-item
内でアイテムを ion-list
に配置する場合にのみ使用します。また、ion-range
が正しく機能するためには、ion-item
は不要になりました。
レガシー構文の使用
Ionicは、アプリが最新の範囲構文を使用しているかどうかをヒューリスティックで検出します。場合によっては、レガシー構文を使い続けた方が望ましいこともあります。開発者は ion-range
の legacy
プロパティを true
に設定することで、そのインスタンスにレガシー構文を使用させることができます。
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 | The start position of the range active bar. This feature is only available with a single knob (dualKnobs="false"). Valid values are greater than or equal to the min value and less than or equal to the max value. |
Attribute | active-bar-start |
Type | number | undefined |
Default | undefined |
color
Description | The 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. |
Attribute | color |
Type | "danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string | undefined |
Default | undefined |
debounce
Description | How long, in milliseconds, to wait to trigger the ionInput event after each change in the range value. |
Attribute | debounce |
Type | number | undefined |
Default | undefined |
disabled
Description | true の場合、ユーザは範囲と対話することができません。 |
Attribute | disabled |
Type | boolean |
Default | false |
dualKnobs
Description | 2つのノブを表示します。 |
Attribute | dual-knobs |
Type | boolean |
Default | false |
label
Description | The text to display as the control's label. Use this over the label slot if you only need plain text. The label property will take priority over the label slot if both are used. |
Attribute | label |
Type | string | undefined |
Default | undefined |
labelPlacement
Description | Where to place the label relative to the range. "start" : The label will appear to the left of the range in LTR and to the right in RTL. "end" : The label will appear to the right of the range in LTR and to the left in RTL. "fixed" : The label has the same behavior as "start" except it also has a fixed width. Long text will be truncated with ellipses ("..."). "stacked" : The label will appear above the range regardless of the direction. |
Attribute | label-placement |
Type | "end" | "fixed" | "stacked" | "start" |
Default | 'start' |
max
Description | 範囲の最大整数値。 |
Attribute | max |
Type | number |
Default | 100 |
min
Description | 範囲の最小の整数値。 |
Attribute | min |
Type | number |
Default | 0 |
mode
Description | modeは、どのプラットフォームのスタイルを使用するかを決定します。 |
Attribute | mode |
Type | "ios" | "md" |
Default | undefined |
name
Description | フォームデータとともに送信されるコントロールの名前。 |
Attribute | name |
Type | string |
Default | this.rangeId |
pin
Description | If true , a pin with integer value is shown when the knob is pressed. |
Attribute | pin |
Type | boolean |
Default | false |
pinFormatter
Description | A callback used to format the pin text. By default the pin text is set to Math.round(value) .See https://ionicframework.com/docs/troubleshooting/runtime#accessing-this if you need to access this from within the callback. |
Attribute | pin-formatter |
Type | (value: number) => string | number |
Default | (value: number): number => Math.round(value) |
snaps
Description | If true , the knob snaps to tick marks evenly spaced based on the step property value. |
Attribute | snaps |
Type | boolean |
Default | false |
step
Description | 値の粒度を指定します。 |
Attribute | step |
Type | number |
Default | 1 |
ticks
Description | If true , tick marks are displayed based on the step value. Only applies when snaps is true . |
Attribute | ticks |
Type | boolean |
Default | true |
value
Description | 範囲の値です。 |
Attribute | value |
Type | number | { lower: number; upper: number; } |
Default | 0 |
イベント
Name | Description | Bubbles |
---|---|---|
ionBlur | レンジの焦点が合わなくなったときに発行されます。 | true |
ionChange | The ionChange event is fired for <ion-range> elements when the user modifies the element's value: - When the user releases the knob after dragging; - When the user moves the knob with keyboard arrowsThis event will not emit when programmatically setting the value property. | true |
ionFocus | レンジのフォーカスが合ったときに発行されます。 | true |
ionInput | The ionInput event is fired for <ion-range> elements when the value is modified. Unlike ionChange , ionInput is fired continuously while the user is dragging the knob. | true |
ionKnobMoveEnd | Emitted when the user finishes moving the range knob, whether through mouse drag, touch gesture, or keyboard interaction. | true |
ionKnobMoveStart | Emitted when the user starts moving the range knob, whether through mouse drag, touch gesture, or keyboard interaction. | true |
メソッド
No public methods available for this component.
CSS Shadow Parts
Name | Description |
---|---|
bar | バーの非アクティブな部分。 |
bar-active | バーのアクティブな部分です。 |
knob | 範囲をドラッグする際に使用するハンドル。 |
label | 範囲を表すラベルテキスト。 |
pin | ノブの上に表示されるカウンターです。 |
tick | 非アクティブなティックマークです。 |
tick-active | アクティブなティックマークです。 |
CSSカスタムプロパティ
- iOS
- MD
Name | Description |
---|---|
--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時のみ有効) |
Name | Description |
---|---|
--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
Name | Description |
---|---|
end | コンテンツは、LTRでは範囲スライダーの右側に、RTLでは左側に配置されます。 |
label | 範囲に関連付けるラベルテキスト。"labelPlacement "プロパティを使用して、ラベルが範囲に対してどの位置に配置されるかを制御します。 |
start | コンテンツは、LTRでは範囲スライダーの左側に、RTLでは右側に配置されます。 |