ion-range
Range スライダーでは、ノブを動かして指定範囲内の値を選べます。デフォルトでは 1 つのノブで値を操作します。この動作は dual knobs を使って変更できます。
デフォルトでは、Rangeスライダーの最小値は0、最大値は100です。これは min と max プロパティで設定することができます。
Labels
ラベルは、範囲を説明するために使用されるべきです。それらは視覚的に使用することができ、また、ユーザーがRangeをフォーカスしてるときに、スクリーンリーダーによって読み上げられます。これにより、ユーザーは範囲の意図を理解しやすくなります。範囲にはラベルを割り当てるいくつかの方法があります:
labelプロパティ:プレーンテキストのラベルに使用する。labelslot:カスタム HTML ラベルに使用する。aria-label: スクリーンリーダー用のラベルとして使用されるが、ラベルは表示されない。
Label Placement
以下のデモでは、labelPlacement プロパティを使用して、範囲に対するラベルの位置を変更しています。ここでは label プロパティを使用しているが、labelPlacement は label slot でも使用できます。
Label Slot
プレーンテキストのラベルは label プロパティで渡すべきであるが、カスタムHTMLが必要な場合は、代わりに label slot で渡すことができます。
No Visible Label
ラベルを画面に表示する必要がない場合も、スクリーンリーダーで Range を識別できるように aria-label を指定してください。
Decorations
Range の start または end slot には装飾用の要素を配置できます。たとえば、小音量や大音量を示すアイコンを追加できます。装飾用の要素はスクリーンリーダーなどの支援技術で読み上げられないようにしてください。
文書の書字方向が左から右の場合、start slot のコンテンツは range の左側、end slot のコンテンツは右側に表示されます。右から左(rtl)の場合は、start slot が右側、end slot が左側になります。
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の値の変更を監視します。
ConsoleConsole messages will appear here when logged from the example above.ionKnobMoveStart と ionKnobMoveEnd を使う
マウスドラッグ、タッチジェスチャー、キーボード操作のいずれであっても、Range knobのドラッグが開始されると ionKnobMoveStart イベントが発行されます。逆に、ionKnobMoveEndはRange knobがリリースされたときに発生します。両イベントは RangeValue タイプで発生し、dualKnobs プロパティと組み合わせて動作します。
ConsoleConsole messages will appear here when logged from the example above.テーマ
CSS Custom Properties
Rangeには、アプリケーションのデザインに合わせてRangeコンポーネントの外観を素早くテーマ化してカスタマイズするためのCSS Variablesが含まれています。
CSS Shadow Parts
Rangeには CSS Shadow Parts があり、Rangeコンポーネント内の特定の要素ノードを完全にカスタマイズすることができます。CSS Shadow Partsは最も多くのカスタマイズ機能を提供し、Rangeコンポーネントで高度なスタイリングが必要な場合に推奨されるアプローチです。
dualKnobs を有効にすると、各ノブに個別のスタイルを適用できる Shadow Parts が追加されます。ノブを識別する固定のパーツ(A と B)と、位置に応じて変わるパーツ(lower と upper)の 2 種類があります。ノブが交差しても A と B はそれぞれ同じノブを指します。一方、lower と upper は現在の値の大小に対応し、ノブが交差すると自動で入れ替わります。これにより、特定のノブにも、範囲内の相対的な位置にもスタイルを適用できます。
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 };
Properties
activeBarStart
| Description | Rangeアクティブバーの開始位置です。この機能は、ノブが1つの場合のみ有効です(dualKnobs="false")。有効な値は、min値以上、max値以下です。 |
| Attribute | active-bar-start |
| Type | number | undefined |
| Default | undefined |
color
| Description | アプリケーションのカラーパレットから使用する色を指定します。デフォルトのオプションは以下の通りです。 "primary", "secondary", "tertiary", "success", "warning", "danger", "light", "medium", と "dark" です.色に関する詳しい情報は theming を参照してください。 |
| Attribute | color |
| Type | "danger" | "dark" | "light" | "medium" | "primary" | "secondary" | "success" | "tertiary" | "warning" | string | undefined |
| Default | undefined |
debounce
| Description | Rangeの値が変化するたびに ionInput イベントをトリガーするまでの待ち時間(ミリ秒単位)。 |
| Attribute | debounce |
| Type | number | undefined |
| Default | undefined |
disabled
| Description | trueの場合、ユーザは範囲と対話することができません。 |
| Attribute | disabled |
| Type | boolean |
| Default | false |
dualKnobs
| Description | If true, the range shows two knobs and value is an object with lower and upper properties. If false, the range shows one knob and value is a number. |
| Attribute | dual-knobs |
| Type | boolean |
| Default | false |
label
| Description | コントロールのラベルとして表示するテキスト。プレーンテキストのみが必要な場合は label スロットよりもこちらを使用する。両方を使用する場合は、label プロパティが label スロットよりも優先される。 |
| Attribute | label |
| Type | string | undefined |
| Default | undefined |
labelPlacement
| Description | 範囲に対するラベルの位置。start":ラベルはLTRでは範囲の左側、RTLでは右側に表示される。end":ラベルはLTRでは範囲の右側、RTLでは左側に表示される。fixed":ラベルの幅が固定される以外は "start" と同じ動作をします。長いテキストは省略記号("...")で切り捨てられます。積み上げ":ラベルは方向に関係なく範囲の上に表示されます。 |
| Attribute | label-placement |
| Type | "end" | "fixed" | "stacked" | "start" |
| Default | 'start' |
max
| Description | 範囲の最大整数値。 |
| Attribute | max |
| Type | number |
| Default | 100 |
min
| Description | 範囲の最小の整数値。 This is a virtual property that is set once during initialization and will not update if you change its value after the initial render. |
| Attribute | min |
| Type | number |
| Default | 0 |
mode
| Description | modeは、どのプラットフォームのスタイルを使用するかを決定します。 This is a virtual property that is set once during initialization and will not update if you change its value after the initial render. |
| Attribute | mode |
| Type | "ios" | "md" |
| Default | undefined |
name
| Description | フォームデータとともに送信されるコントロールの名前。 |
| Attribute | name |
| Type | string |
| Default | this.rangeId |
pin
| Description | trueの場合、ノブを押したときに整数値のピンが表示されます。 |
| Attribute | pin |
| Type | boolean |
| Default | false |
pinFormatter
| Description | ピンのテキストをフォーマットするためのコールバック。デフォルトでは、ピンのテキストは Math.round(value) に設定されます。 コールバック内から this にアクセスする必要がある場合は https://ionicframework.com/docs/troubleshooting/runtime#accessing-this を参照してください。 |
| Attribute | undefined |
| Type | (value: number) => string | number |
| Default | (value: number): number => Math.round(value) |
snaps
| Description | trueの場合、ノブはステッププロパティの値に基づいて等間隔に配置されたティックマークにスナップします。 |
| Attribute | snaps |
| Type | boolean |
| Default | false |
step
| Description | 値の粒度を指定します。 |
| Attribute | step |
| Type | number |
| Default | 1 |
ticks
| Description | trueの場合、ステップの値に基づいてティックマークを表示します。snaps が true の場合のみ適用される。 |
| Attribute | ticks |
| Type | boolean |
| Default | true |
value
| Description | 範囲の値です。 |
| Attribute | value |
| Type | number | { lower: number; upper: number; } |
| Default | 0 |
Events
| Name | Description | Bubbles |
|---|---|---|
ionBlur | Rangeの焦点が合わなくなったときに発行されます。 | true |
ionChange | ionChange イベントは <ion-range> 要素に対して、ユーザがその要素の値を変更したときに発生します。 ・ユーザがドラッグした後にノブを離したとき ・ユーザがキーボードの矢印でノブを移動したとき このイベントはプログラムでvalueプロパティを設定したときには発生しません。 | true |
ionFocus | Rangeのフォーカスが合ったときに発行されます。 | true |
ionInput | ionInputイベントは、<ion-range>要素に対して、値が変更されたときに発生するイベントです。ionChangeとは異なり、ionInputはユーザがノブをドラッグしている間、継続して発生します。 | true |
ionKnobMoveEnd | マウスドラッグ、タッチジェスチャー、キーボード操作など、ユーザーが範囲ノブの移動を終了したときに発行されます。 | true |
ionKnobMoveStart | マウスドラッグ、タッチジェスチャー、キーボード操作など、ユーザーがRangeノブの移動を開始したときに発行されます。 | true |
Methods
No public methods available for this component.
CSS Shadow Parts
| Name | Description |
|---|---|
activated | Added to the knob-handle, knob, and pin when the knob is active. Only one set has this part at a time when dualKnobs is true. |
bar | バーの非アクティブな部分。 |
bar-active | バーのアクティブな部分です。 |
focused | Added to the knob-handle, knob, and pin that currently has focus. Only one set has this part at a time when dualKnobs is true. |
hover | Added to the knob-handle, knob, and pin when the knob has hover. Only one set has this part at a time when dualKnobs is true. |
knob | The visual knob element on the range track. |
knob-a | The visual knob for the static A identity when dualKnobs is true. This identity does not change, even if the knobs cross and swap which one represents the lower or upper value. |
knob-b | The visual knob for the static B identity when dualKnobs is true. This identity does not change, even if the knobs cross and swap which one represents the lower or upper value. |
knob-handle | The container that wraps the knob and handles drag interactions. |
knob-handle-a | The container for the knob with the static A identity when dualKnobs is true. This identity does not change, even if the knobs cross and swap which one represents the lower or upper value. |
knob-handle-b | The container for the knob with the static B identity when dualKnobs is true. This identity does not change, even if the knobs cross and swap which one represents the lower or upper value. |
knob-handle-lower | The container for the knob whose current value is lower when dualKnobs is true. The lower and upper parts swap which knob handle they refer to when the knobs cross. |
knob-handle-upper | The container for the knob whose current value is upper when dualKnobs is true. The lower and upper parts swap which knob handle they refer to when the knobs cross. |
knob-lower | The visual knob whose current value is lower when dualKnobs is true. The lower and upper parts swap which knob they refer to when the knobs cross. |
knob-upper | The visual knob whose current value is upper when dualKnobs is true. The lower and upper parts swap which knob they refer to when the knobs cross. |
label | 範囲を表すラベルテキスト。 |
pin | The value indicator displayed above a knob. |
pin-a | The value indicator above the knob with the static A identity when dualKnobs is true. This identity does not change, even if the knobs cross and swap which one represents the lower or upper value. |
pin-b | The value indicator above the knob with the static B identity when dualKnobs is true. This identity does not change, even if the knobs cross and swap which one represents the lower or upper value. |
pin-lower | The value indicator above the knob whose current value is lower when dualKnobs is true. The lower and upper parts swap which pin they refer to when the knobs cross. |
pin-upper | The value indicator above the knob whose current value is upper when dualKnobs is true. The lower and upper parts swap which pin they refer to when the knobs cross. |
pressed | Added to the knob-handle, knob, and pin that is currently being pressed to drag. Only one set has this part at a time when dualKnobs is true. |
tick | 非アクティブなティックマークです。 |
tick-active | アクティブなティックマークです。 |
CSS Custom Properties
- iOS
- MD
| Name | Description |
|---|---|
--bar-background | Rangeバーの背景 |
--bar-background-active | アクティブRangeバーの背景 |
--bar-border-radius | Rangeバーのボーダー半径 |
--bar-height | Rangeバーの高さ |
--height | Rangeの高さ |
--knob-background | Rangeノブの背景 |
--knob-border-radius | Rangeツマミのボーダー半径 |
--knob-box-shadow | Rangeノブのボックスシャドウ |
--knob-size | Rangeツマミの大きさ |
--pin-background | Rangeピンの背景(MD mode時のみ有効) |
--pin-color | Rangeピンの色(MD mode時のみ有効) |
| Name | Description |
|---|---|
--bar-background | Rangeバーの背景 |
--bar-background-active | アクティブRangeバーの背景 |
--bar-border-radius | Rangeバーのボーダー半径 |
--bar-height | Rangeバーの高さ |
--height | Rangeの高さ |
--knob-background | Rangeノブの背景 |
--knob-border-radius | Rangeツマミのボーダー半径 |
--knob-box-shadow | Rangeノブのボックスシャドウ |
--knob-size | Rangeツマミの大きさ |
--pin-background | Rangeピンの背景(MD mode時のみ有効) |
--pin-color | Rangeピンの色(MD mode時のみ有効) |
Slots
| Name | Description |
|---|---|
end | コンテンツは、LTRでは範囲スライダーの右側に、RTLでは左側に配置されます。 |
label | 範囲に関連付けるラベルテキスト。"labelPlacement"プロパティを使用して、ラベルが範囲に対してどの位置に配置されるかを制御します。 |
start | コンテンツは、LTRでは範囲スライダーの左側に、RTLでは右側に配置されます。 |