ion-range
The Range slider lets users select from a range of values by moving the slider knob. It can accept dual knobs, but by default one knob controls the value of the range.
Range Labels
Labels can be placed on either side of the range by adding the
slot="start" or slot="end" to the element. The element doesn't have to
be an ion-label, it can be added to any element to place it to the
left or right of the range.
Usage
- Angular
- Javascript
- React
- Stencil
- Vue
<ion-list>
<ion-item>
<ion-range color="danger" pin="true"></ion-range>
</ion-item>
<ion-item>
<ion-range min="-200" max="200" color="secondary">
<ion-label slot="start">-200</ion-label>
<ion-label slot="end">200</ion-label>
</ion-range>
</ion-item>
<ion-item>
<ion-range min="20" max="80" step="2">
<ion-icon size="small" slot="start" name="sunny"></ion-icon>
<ion-icon slot="end" name="sunny"></ion-icon>
</ion-range>
</ion-item>
<ion-item>
<ion-range min="1000" max="2000" step="100" snaps="true" color="secondary"></ion-range>
</ion-item>
<ion-item>
<ion-range min="1000" max="2000" step="100" snaps="true" ticks="false" color="secondary"></ion-range>
</ion-item>
<ion-item>
<ion-range dualKnobs="true" min="21" max="72" step="3" snaps="true"></ion-range>
</ion-item>
</ion-list>
<ion-list>
<ion-item>
<ion-range color="danger" pin="true"></ion-range>
</ion-item>
<ion-item>
<ion-range min="-200" max="200" color="secondary">
<ion-label slot="start">-200</ion-label>
<ion-label slot="end">200</ion-label>
</ion-range>
</ion-item>
<ion-item>
<ion-range min="20" max="80" step="2">
<ion-icon size="small" slot="start" name="sunny"></ion-icon>
<ion-icon slot="end" name="sunny"></ion-icon>
</ion-range>
</ion-item>
<ion-item>
<ion-range min="1000" max="2000" step="100" snaps="true" color="secondary"></ion-range>
</ion-item>
<ion-item>
<ion-range min="1000" max="2000" step="100" snaps="true" ticks="false" color="secondary"></ion-range>
</ion-item>
<ion-item>
<ion-range dual-knobs="true" min="21" max="72" step="3" snaps="true"></ion-range>
</ion-item>
</ion-list>
import React, { useState } from 'react';
import {
IonContent,
IonHeader,
IonPage,
IonTitle,
IonToolbar,
IonList,
IonItem,
IonRange,
IonLabel,
IonIcon,
IonItemDivider,
} from '@ionic/react';
import { sunny } from 'ionicons/icons';
import { RangeValue } from '@ionic/core';
export const RangeExamples: React.FC = () => {
const [value, setValue] = useState(0);
const [rangeValue, setRangeValue] = useState<{
lower: number;
upper: number;
}>({ lower: 0, upper: 0 });
return (
<IonPage>
<IonHeader>
<IonToolbar>
<IonTitle>IonRange Examples</IonTitle>
</IonToolbar>
</IonHeader>
<IonContent>
<IonList>
<IonItemDivider>Default</IonItemDivider>
<IonItem>
<IonRange pin={true} value={value} onIonChange={(e) => setValue(e.detail.value as number)} />
</IonItem>
<IonItem>
<IonLabel>Value: {value}</IonLabel>
</IonItem>
<IonItemDivider>Min & Max</IonItemDivider>
<IonItem>
<IonRange min={-200} max={200} color="secondary">
<IonLabel slot="start">-200</IonLabel>
<IonLabel slot="end">200</IonLabel>
</IonRange>
</IonItem>
<IonItemDivider>Icons</IonItemDivider>
<IonItem>
<IonRange min={20} max={80} step={2}>
<IonIcon size="small" slot="start" icon={sunny} />
<IonIcon slot="end" icon={sunny} />
</IonRange>
</IonItem>
<IonItemDivider>With Snaps & Ticks</IonItemDivider>
<IonItem>
<IonRange min={1000} max={2000} step={100} snaps={true} color="secondary" />
</IonItem>
<IonItemDivider>With Snaps & No Ticks</IonItemDivider>
<IonItem>
<IonRange min={1000} max={2000} step={100} snaps={true} ticks={false} color="secondary" />
</IonItem>
<IonItemDivider>Dual Knobs</IonItemDivider>
<IonItem>
<IonRange
dualKnobs={true}
min={0}
max={60}
step={3}
snaps={true}
onIonChange={(e) => setRangeValue(e.detail.value as any)}
/>
</IonItem>
<IonItem>
<IonLabel>
Value: lower: {rangeValue.lower} upper: {rangeValue.upper}
</IonLabel>
</IonItem>
</IonList>
</IonContent>
</IonPage>
);
};
import { Component, h } from '@stencil/core';
@Component({
tag: 'range-example',
styleUrl: 'range-example.css',
})
export class RangeExample {
render() {
return [
<ion-list>
<ion-item>
<ion-range color="danger" pin={true}></ion-range>
</ion-item>
<ion-item>
<ion-range min={-200} max={200} color="secondary">
<ion-label slot="start">-200</ion-label>
<ion-label slot="end">200</ion-label>
</ion-range>
</ion-item>
<ion-item>
<ion-range min={20} max={80} step={2}>
<ion-icon size="small" slot="start" name="sunny"></ion-icon>
<ion-icon slot="end" name="sunny"></ion-icon>
</ion-range>
</ion-item>
<ion-item>
<ion-range min={1000} max={2000} step={100} snaps={true} color="secondary"></ion-range>
</ion-item>
<ion-item>
<ion-range min={1000} max={2000} step={100} snaps={true} ticks={false} color="secondary"></ion-range>
</ion-item>
<ion-item>
<ion-range dualKnobs={true} min={21} max={72} step={3} snaps={true}></ion-range>
</ion-item>
</ion-list>,
];
}
}
<template>
<ion-list>
<ion-item>
<ion-range color="danger" pin="true"></ion-range>
</ion-item>
<ion-item>
<ion-range min="-200" max="200" color="secondary">
<ion-label slot="start">-200</ion-label>
<ion-label slot="end">200</ion-label>
</ion-range>
</ion-item>
<ion-item>
<ion-range min="20" max="80" step="2">
<ion-icon size="small" slot="start" name="sunny"></ion-icon>
<ion-icon slot="end" name="sunny"></ion-icon>
</ion-range>
</ion-item>
<ion-item>
<ion-range min="1000" max="2000" step="100" snaps="true" color="secondary"></ion-range>
</ion-item>
<ion-item>
<ion-range min="1000" max="2000" step="100" snaps="true" ticks="false" color="secondary"></ion-range>
</ion-item>
<ion-item>
<ion-range ref="rangeDualKnobs" dual-knobs="true" min="21" max="72" step="3" snaps="true"></ion-range>
</ion-item>
</ion-list>
</template>
<script>
import { IonItem, IonLabel, IonList, IonRange } from '@ionic/vue';
import { defineComponent } from 'vue';
export default defineComponent({
components: { IonItem, IonLabel, IonList, IonRange },
mounted() {
// Sets initial value for dual-knob ion-range
this.$refs.rangeDualKnobs.value = { lower: 24, upper: 42 };
},
});
</script>
Properties
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 | string | undefined |
| Default | undefined |
debounce
| Description | How long, in milliseconds, to wait to trigger the ionChange event after each change in the range value. This also impacts form bindings such as ngModel or v-model. |
| Attribute | debounce |
| Type | number |
| Default | 0 |
disabled
| Description | trueの場合、ユーザは範囲と対話することができません。 |
| Attribute | disabled |
| Type | boolean |
| Default | false |
dualKnobs
| Description | 2つのノブを表示します。 |
| Attribute | dual-knobs |
| Type | boolean |
| Default | false |
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 | '' |
pin
| Description | If true, a pin with integer value is shown when the knob is pressed. |
| Attribute | pin |
| Type | boolean |
| Default | false |
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 |
Events
| Name | Description |
|---|---|
ionBlur | レンジの焦点が合わなくなったときに発行されます。 |
ionChange | valueプロパティが変更されたときに発行されます。 |
ionFocus | レンジのフォーカスが合ったときに発行されます。 |
Methods
No public methods available for this component.
CSS Shadow Parts
| Name | Description |
|---|---|
bar | バーの非アクティブな部分。 |
bar-active | バーのアクティブな部分です。 |
knob | 範囲をドラッグする際に使 用するハンドル。 |
pin | ノブの上に表示されるカウンターです。 |
tick | 非アクティブなティックマークです。 |
tick-active | アクティブなティックマークです。 |
CSS Custom Properties
| 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 | Background of the range pin |
--pin-color | Color of the range pin |
Slots
| Name | Description |
|---|---|
end | コンテンツは、LTRでは範囲スライダーの右側に、RTLで は左側に配置されます。 |
start | コンテンツは、LTRでは範囲スライダーの左側に、RTLでは右側に配置されます。 |