ion-range
슬라이더의 노브(knob)를 움직여 값의 범위에서 하나를 선택하게 해 주는 Range 슬라이더 컴포넌트예요. 기본적으로는 노브 하나가 범위 값을 제어하며, 이중 노브를 사용해 이 동작을 커스터마이즈할 수도 있습니다.
출처: 문서
본문
Encapsulation: shadow
Range 슬라이더는 사용자가 슬라이더 노브를 움직여 값의 범위 중에서 하나를 선택할 수 있게 해 주는 컴포넌트예요. 기본적으로 노브 하나가 범위 값을 제어합니다. 이 동작은 이중 노브를 사용해 커스터마이즈할 수 있어요.
기본적으로 Range 슬라이더의 최솟값은 0, 최댓값은 100입니다. 이 값은 min과 max 프로퍼티로 설정할 수 있어요.
Labels
라벨은 범위(range)를 설명하는 데 사용해야 해요. 라벨은 시각적으로도 사용할 수 있고, 사용자가 범위에 포커스를 맞추면 스크린 리더가 읽어주기도 합니다. 이 덕분에 사용자가 범위의 목적을 쉽게 이해할 수 있어요. Range에는 라벨을 지정하는 여러 가지 방법이 있습니다:
label프로퍼티: 일반 텍스트 라벨용label슬롯: 커스텀 HTML 라벨용aria-label: 스크린 리더용 라벨을 제공하지만 시각적인 라벨은 추가하지 않음
Label Placement
아래 데모는 labelPlacement 프로퍼티를 사용해 범위에 대한 라벨의 위치를 바꾸는 방법을 보여줘요. 여기서는 label 프로퍼티를 사용했지만, labelPlacement는 label 슬롯과도 함께 사용할 수 있습니다.
JavaScript
<ion-range label-placement="start" label="Label at the Start"></ion-range>
<br />
<ion-range label-placement="end" label="Label at the End"></ion-range>
<br />
<ion-range label-placement="fixed" label="Fixed Width Label"></ion-range>
<br />
<ion-range label-placement="stacked" label="Stacked Label"></ion-range>
Angular
src/app/example.component.html
<ion-range labelPlacement="start" label="Label at the Start"></ion-range>
<br />
<ion-range labelPlacement="end" label="Label at the End"></ion-range>
<br />
<ion-range labelPlacement="fixed" label="Fixed Width Label"></ion-range>
<br />
<ion-range labelPlacement="stacked" label="Stacked Label"></ion-range>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonRange } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonRange],
})
export class ExampleComponent {}
React
import React from 'react';
import { IonRange } from '@ionic/react';
function Example() {
return (
<>
<IonRange labelPlacement="start" label="Label at the Start"></IonRange>
<br />
<IonRange labelPlacement="end" label="Label at the End"></IonRange>
<br />
<IonRange labelPlacement="fixed" label="Fixed Width Label"></IonRange>
<br />
<IonRange labelPlacement="stacked" label="Stacked Label"></IonRange>
</>
);
}
export default Example;
Vue
<template>
<ion-range label-placement="start" label="Label at the Start"></ion-range>
<br />
<ion-range label-placement="end" label="Label at the End"></ion-range>
<br />
<ion-range label-placement="fixed" label="Fixed Width Label"></ion-range>
<br />
<ion-range label-placement="stacked" label="Stacked Label"></ion-range>
</template>
<script setup lang="ts">
import { IonRange } from '@ionic/vue';
</script>
Label Slot
일반 텍스트 라벨은 label 프로퍼티로 전달해야 하지만, 커스텀 HTML이 필요하다면 대신 label 슬롯으로 전달할 수 있어요.
JavaScript
<ion-range>
<div slot="label">Label with <ion-text color="primary">custom HTML</ion-text></div>
</ion-range>
Angular
src/app/example.component.html
<ion-range>
<div slot="label">Label with <ion-text color="primary">custom HTML</ion-text></div>
</ion-range>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonRange, IonText } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonRange, IonText],
})
export class ExampleComponent {}
React
import React from 'react';
import { IonRange, IonText } from '@ionic/react';
function Example() {
return (
<IonRange>
<div slot="label">
Label with <IonText color="primary">custom HTML</IonText>
</div>
</IonRange>
);
}
export default Example;
Vue
<template>
<ion-range>
<div slot="label">Label with <ion-text color="primary">custom HTML</ion-text></div>
</ion-range>
</template>
<script setup lang="ts">
import { IonRange, IonText } from '@ionic/vue';
</script>
No Visible Label
시각적인 라벨이 필요 없더라도, 스크린 리더가 범위에 접근할 수 있도록 aria-label은 제공해야 해요.
JavaScript
<ion-range aria-label="Volume"></ion-range>
Angular
src/app/example.component.html
<ion-range aria-label="Volume"></ion-range>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonRange } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonRange],
})
export class ExampleComponent {}
React
import React from 'react';
import { IonRange } from '@ionic/react';
function Example() {
return <IonRange aria-label="Volume"></IonRange>;
}
export default Example;
Vue
<template>
<ion-range aria-label="Volume"></ion-range>
</template>
<script setup lang="ts">
import { IonRange } from '@ionic/vue';
</script>
Decorations
장식(decorative) 요소는 range의 start 또는 end 슬롯으로 전달할 수 있어요. 작은 볼륨이나 큰 볼륨 아이콘 같은 아이콘을 추가할 때 유용합니다. 이 요소들은 장식용이므로 스크린 리더 같은 보조 기술이 읽어서는 안 됩니다.
문서의 방향성(directionality)이 왼쪽에서 오른쪽(LTR)이면, start 위치로 슬롯된 콘텐츠는 range의 왼쪽에 표시되고 end 위치로 슬롯된 콘텐츠는 range의 오른쪽에 표시됩니다. 오른쪽에서 왼쪽(RTL) 방향성에서는 start 위치로 슬롯된 콘텐츠가 range의 오른쪽에, end 위치로 슬롯된 콘텐츠는 왼쪽에 표시돼요.
JavaScript
index.html
<ion-range aria-label="Temperature">
<ion-icon slot="start" name="snow-outline"></ion-icon>
<ion-icon slot="end" name="sunny-outline"></ion-icon>
</ion-range>
index.ts
import { defineCustomElements } from '@ionic/core/loader';
import { addIcons } from 'ionicons';
import { snowOutline, sunnyOutline } from 'ionicons/icons';
/* Core CSS required for Ionic components to work properly */
import '@ionic/core/css/core.css';
/* Basic CSS for apps built with Ionic */
import '@ionic/core/css/normalize.css';
import '@ionic/core/css/structure.css';
import '@ionic/core/css/typography.css';
/* Optional CSS utils that can be commented out */
import '@ionic/core/css/padding.css';
import '@ionic/core/css/float-elements.css';
import '@ionic/core/css/text-alignment.css';
import '@ionic/core/css/text-transformation.css';
import '@ionic/core/css/flex-utils.css';
import '@ionic/core/css/display.css';
/**
* Ionic Dark Palette
* -----------------------------------------------------
* For more information, please see:
* https://ionicframework.com/docs/theming/dark-mode
*/
// import '@ionic/core/css/palettes/dark.always.css';
// import '@ionic/core/css/palettes/dark.class.css';
import '@ionic/core/css/palettes/dark.system.css';
/* Theme variables */
import './theme/variables.css';
/**
* On Ionicons 7.2+ these icons
* get mapped to a kebab-case key.
* Alternatively, developers can do:
* addIcons({ 'snow-outline': snowOutline, 'sunny-outline': sunnyOutline });
*/
addIcons({ snowOutline, sunnyOutline });
defineCustomElements();
Angular
src/app/example.component.html
<ion-range aria-label="Temperature">
<ion-icon slot="start" name="snow-outline"></ion-icon>
<ion-icon slot="end" name="sunny-outline"></ion-icon>
</ion-range>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonIcon, IonRange } from '@ionic/angular';
import { addIcons } from 'ionicons';
import { snowOutline, sunnyOutline } from 'ionicons/icons';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonIcon, IonRange],
})
export class ExampleComponent {
constructor() {
/**
* Any icons you want to use in your application
* can be registered in app.component.ts and then
* referenced by name anywhere in your application.
*/
addIcons({ snowOutline, sunnyOutline });
}
}
React
import React from 'react';
import { IonRange, IonIcon } from '@ionic/react';
import { snowOutline, sunnyOutline } from 'ionicons/icons';
function Example() {
return (
<IonRange aria-label="Temperature">
<IonIcon slot="start" icon={snowOutline}></IonIcon>
<IonIcon slot="end" icon={sunnyOutline}></IonIcon>
</IonRange>
);
}
export default Example;
Vue
<template>
<ion-range aria-label="Temperature">
<ion-icon slot="start" :icon="snowOutline"></ion-icon>
<ion-icon slot="end" :icon="sunnyOutline"></ion-icon>
</ion-range>
</template>
<script setup lang="ts">
import { IonRange, IonIcon } from '@ionic/vue';
import { snowOutline, sunnyOutline } from 'ionicons/icons';
</script>
Dual Knobs
이중 노브는 사용자가 하한과 상한 경계에서 값을 선택할 수 있게 해 주는 두 개의 노브 컨트롤을 도입해요. 선택하면 Range는 선택된 상한·하한 값을 담은 RangeValue와 함께 ionChange 이벤트를 발생시킵니다.
JavaScript
<ion-range aria-label="Dual Knobs Range" dual-knobs="true"></ion-range>
<script>
const range = document.querySelector('ion-range');
range.value = {
lower: 20,
upper: 80,
};
</script>
Angular
src/app/example.component.html
<ion-range aria-label="Dual Knobs Range" [dualKnobs]="true" [value]="{ lower: 20, upper: 80 }"></ion-range>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonRange } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonRange],
})
export class ExampleComponent {}
React
import React from 'react';
import { IonRange } from '@ionic/react';
function Example() {
return (
<IonRange
aria-label="Dual Knobs Range"
dualKnobs={true}
value={{
lower: 20,
upper: 80,
}}
></IonRange>
);
}
export default Example;
Vue
<template>
<ion-range aria-label="Dual Knobs Range" :dual-knobs="true" :value="{ lower: 20, upper: 80 }"></ion-range>
</template>
<script setup lang="ts">
import { IonContent, IonRange } from '@ionic/vue';
</script>
Pins
pin 속성은 드래그할 때 Range의 값을 노브 위에 표시해 줘요. 이 덕분에 사용자가 Range 안에서 특정 값을 선택할 수 있습니다.
pinFormatter 함수를 사용하면 개발자가 사용자에게 표시할 범위 값을 커스터마이즈할 수 있어요.
JavaScript
<ion-range aria-label="Range with pin" pin="true"></ion-range>
<script>
const range = document.querySelector('ion-range');
range.pinFormatter = (value) => {
return `${value}%`;
};
</script>
Angular
src/app/example.component.html
<ion-range aria-label="Range with pin" [pin]="true" [pinFormatter]="pinFormatter"></ion-range>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonRange } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonRange],
})
export class ExampleComponent {
pinFormatter(value: number) {
return `${value}%`;
}
}
React
import React from 'react';
import { IonRange } from '@ionic/react';
function Example() {
return <IonRange aria-label="Range with pin" pin={true} pinFormatter={(value: number) => `${value}%`}></IonRange>;
}
export default Example;
Vue
<template>
<ion-range aria-label="Range with pin" :pin="true" :pin-formatter="pinFormatter"></ion-range>
</template>
<script setup lang="ts">
import { IonRange } from '@ionic/vue';
</script>
Snapping & Ticks
틱(tick)은 Range에서 사용할 수 있는 각 값의 표시를 보여줘요. 틱을 사용하려면 개발자가 snaps와 ticks 프로퍼티를 모두 true로 설정해야 합니다.
스냅핑(enabling snapping)을 활성화하면 Range 노브가 드래그되고 놓일 때 가장 가까운 사용 가능한 값에 스냅됩니다.
JavaScript
<ion-range aria-label="Range with ticks" ticks="true" snaps="true" min="0" max="10"></ion-range>
Angular
src/app/example.component.html
<ion-range aria-label="Range with ticks" [ticks]="true" [snaps]="true" [min]="0" [max]="10"></ion-range>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonRange } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonRange],
})
export class ExampleComponent {}
React
import React from 'react';
import { IonRange } from '@ionic/react';
function Example() {
return <IonRange aria-label="Range with ticks" ticks={true} snaps={true} min={0} max={10}></IonRange>;
}
export default Example;
Vue
<template>
<ion-range aria-label="Range with ticks" :ticks="true" :snaps="true" :min="0" :max="10"></ion-range>
</template>
<script setup lang="ts">
import { IonRange } from '@ionic/vue';
</script>
Event Handling
Using ionChange
ionChange 이벤트는 Range 노브 값이 변경될 때 발생합니다.
JavaScript
<ion-range aria-label="Range with ionChange"></ion-range>
<script>
const range = document.querySelector('ion-range');
range.addEventListener('ionChange', ({ detail }) => {
console.log('ionChange emitted value: ' + detail.value);
});
</script>
Angular
src/app/example.component.html
<ion-range aria-label="Range with ionChange" (ionChange)="onIonChange($event)"></ion-range>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonRange, RangeCustomEvent } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonRange],
})
export class ExampleComponent {
onIonChange(event: RangeCustomEvent) {
console.log('ionChange emitted value:', event.detail.value);
}
}
React
import React from 'react';
import { IonRange } from '@ionic/react';
function Example() {
return (
<IonRange
aria-label="Range with ionChange"
onIonChange={({ detail }) => console.log('ionChange emitted value: ' + detail.value)}
></IonRange>
);
}
export default Example;
Vue
<template>
<ion-range aria-label="Range with ionChange" @ionChange="onIonChange"></ion-range>
</template>
<script setup lang="ts">
import { IonRange } from '@ionic/vue';
const onIonChange = ({ detail }) => {
console.log('ionChange emitted value: ' + detail.value);
};
</script>
Console
Console messages will appear here when logged from the example above.
Using ionKnobMoveStart and ionKnobMoveEnd
ionKnobMoveStart 이벤트는 Range 노브가 마우스 드래그, 터치 제스처 또는 키보드 상호작용을 통해 드래그를 시작할 때 발생해요. 반대로 ionKnobMoveEnd는 Range 노브가 놓일 때 발생합니다. 두 이벤트 모두 RangeValue 타입으로 발생하며, dualKnobs 프로퍼티와 함께 동작해요.
JavaScript
<ion-range aria-label="Range with knob events"></ion-range>
<script>
const range = document.querySelector('ion-range');
range.addEventListener('ionKnobMoveStart', ({ detail }) => {
console.log('ionKnobMoveStart:', detail.value);
});
range.addEventListener('ionKnobMoveEnd', ({ detail }) => {
console.log('ionKnobMoveEnd:', detail.value);
});
</script>
Angular
src/app/example.component.html
<ion-range
aria-label="Range with knob events"
(ionKnobMoveStart)="onIonKnobMoveStart($event)"
(ionKnobMoveEnd)="onIonKnobMoveEnd($event)"
></ion-range>
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonRange, RangeCustomEvent } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonRange],
})
export class ExampleComponent {
onIonKnobMoveStart(event: RangeCustomEvent) {
console.log('ionKnobMoveStart:', event.detail.value);
}
onIonKnobMoveEnd(event: RangeCustomEvent) {
console.log('ionKnobMoveEnd:', event.detail.value);
}
}
React
import React from 'react';
import { IonRange } from '@ionic/react';
function Example() {
return (
<IonRange
aria-label="Range with knob events"
onIonKnobMoveStart={({ detail }) => console.log('ionKnobMoveStart:', detail.value)}
onIonKnobMoveEnd={({ detail }) => console.log('ionKnobMoveEnd:', detail.value)}
></IonRange>
);
}
export default Example;
Vue
<template>
<ion-range
aria-label="Range with knob events"
@ionKnobMoveStart="onIonKnobMoveStart"
@ionKnobMoveEnd="onIonKnobMoveEnd"
></ion-range>
</template>
<script setup lang="ts">
import { IonRange } from '@ionic/vue';
const onIonKnobMoveStart = ({ detail }) => {
console.log('ionKnobMoveStart:', detail.value);
};
const onIonKnobMoveEnd = ({ detail }) => {
console.log('ionKnobMoveEnd:', detail.value);
};
</script>
Console
Console messages will appear here when logged from the example above.
Theming
CSS Custom Properties
Range에는 애플리케이션의 디자인에 맞춰 Range 컴포넌트의 모양을 빠르게 테마링하고 커스터마이즈할 수 있는 CSS Variables가 포함되어 있어요.
JavaScript
<ion-range aria-label="Custom range" value="50" pin="true"></ion-range>
<style>
ion-range {
--bar-background: #a2d2ff;
--bar-background-active: #bde0fe;
--bar-height: 8px;
--bar-border-radius: 8px;
--knob-background: #ffc8dd;
--knob-size: 40px;
--pin-background: #ffafcc;
--pin-color: #fff;
}
</style>
Angular
src/app/example.component.html
<ion-range aria-label="Custom range" [value]="50" [pin]="true"></ion-range>
src/app/example.component.css
ion-range {
--bar-background: #a2d2ff;
--bar-background-active: #bde0fe;
--bar-height: 8px;
--bar-border-radius: 8px;
--knob-background: #ffc8dd;
--knob-size: 40px;
--pin-background: #ffafcc;
--pin-color: #fff;
}
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonRange } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonRange],
})
export class ExampleComponent {}
React
src/main.css
ion-range {
--bar-background: #a2d2ff;
--bar-background-active: #bde0fe;
--bar-height: 8px;
--bar-border-radius: 8px;
--knob-background: #ffc8dd;
--knob-size: 40px;
--pin-background: #ffafcc;
--pin-color: #fff;
}
src/main.tsx
import React from 'react';
import { IonRange } from '@ionic/react';
import './main.css';
function Example() {
return <IonRange aria-label="Custom range" value={50} pin={true}></IonRange>;
}
export default Example;
Vue
<style>
ion-range {
--bar-background: #a2d2ff;
--bar-background-active: #bde0fe;
--bar-height: 8px;
--bar-border-radius: 8px;
--knob-background: #ffc8dd;
--knob-size: 40px;
--pin-background: #ffafcc;
--pin-color: #fff;
}
</style>
<template>
<ion-range aria-label="Custom range" :value="50" :pin="true"></ion-range>
</template>
<script setup lang="ts">
import { IonRange } from '@ionic/vue';
</script>
CSS Shadow Parts
Range에는 Range 컴포넌트 안의 특정 요소 노드를 완전히 커스터마이즈할 수 있게 해 주는 CSS Shadow Parts가 포함되어 있어요. CSS Shadow Parts는 가장 많은 커스터마이즈 기능을 제공하며, Range 컴포넌트로 고급 스타일링이 필요할 때 권장되는 방식입니다.
dualKnobs가 활성화되면 각 노브를 독립적으로 스타일링할 수 있도록 추가 Shadow Parts가 노출됩니다. 이들은 정적 정체성 파트(A와 B)와 동적 위치 파트(lower와 upper)의 두 형태로 제공돼요. A와 B 파트는 노브가 서로 교차하더라도 항상 같은 물리적 노브를 가리킵니다. 반대로 lower와 upper 파트는 현재 값의 위치를 반영하며, 노브가 교차하면 자동으로 서로 바뀝니다. 이를 통해 일관된 정체성으로 또는 범위 내 상대 값으로 스타일링할 수 있어요.
JavaScript
<h2>Single Knob</h2>
<ion-range
id="range-single"
aria-label="Custom range"
min="0"
max="10"
value="5"
pin="true"
ticks="true"
snaps="true"
></ion-range>
<h2>Dual Knobs (A/B)</h2>
<ion-range
id="range-a-b"
aria-label="Custom dual knob range with A/B styling"
min="0"
max="10"
dual-knobs="true"
pin="true"
></ion-range>
<h2>Dual Knobs (Lower/Upper)</h2>
<ion-range
id="range-lower-upper"
aria-label="Custom dual knob range with lower/upper styling"
min="0"
max="10"
dual-knobs="true"
pin="true"
></ion-range>
<style>
/* Shared styles for all ranges */
ion-range {
--knob-size: 34px;
}
ion-range::part(knob) {
background: #fff;
box-sizing: border-box;
}
/* Hide the Material Design indicator */
ion-range::part(knob)::before {
display: none;
}
ion-range::part(pin) {
color: #fff;
border-radius: 50%;
}
ion-range::part(tick),
ion-range::part(tick-active) {
height: 8px;
top: 17px;
}
/* Single Knob Range */
#range-single::part(bar),
#range-single::part(tick) {
background: #bed4ff;
}
#range-single::part(bar-active),
#range-single::part(tick-active) {
background: #40a2fd;
}
#range-single::part(knob) {
border: 4px solid #40a2fd;
}
#range-single::part(knob pressed) {
background: #bed4ff;
}
#range-single::part(pin),
#range-single::part(pin)::before {
background: #40a2fd;
}
/* Dual Knobs (A/B) Range */
#range-a-b::part(bar-active) {
background: #1ea9ca;
}
#range-a-b::part(knob-a) {
border: 4px solid #0f8fd6;
}
#range-a-b::part(knob-a pressed) {
background: #cfeefe;
}
#range-a-b::part(pin-a),
#range-a-b::part(pin-a)::before {
background: #0f8fd6;
}
#range-a-b::part(knob-b) {
border: 4px solid #2dc2bd;
}
#range-a-b::part(knob-b pressed) {
background: #d4f5f3;
}
#range-a-b::part(pin-b),
#range-a-b::part(pin-b)::before {
background: #2dc2bd;
}
/* Dual Knobs (Lower/Upper) Range */
#range-lower-upper::part(bar-active) {
background: linear-gradient(to right, #0059ff 0%, #b77bff 100%);
}
#range-lower-upper::part(knob-lower) {
border: 4px solid #0059ff;
}
#range-lower-upper::part(knob-lower pressed) {
background: #bed4ff;
}
#range-lower-upper::part(pin-lower),
#range-lower-upper::part(pin-lower)::before {
background: #0059ff;
}
#range-lower-upper::part(knob-upper) {
border: 4px solid #b77bff;
}
#range-lower-upper::part(knob-upper pressed) {
background: #f1e5ff;
}
#range-lower-upper::part(pin-upper),
#range-lower-upper::part(pin-upper)::before {
background: #b77bff;
}
</style>
<script>
const ranges = document.querySelectorAll('ion-range[dual-knobs]');
ranges.forEach((range) => {
range.value = {
lower: 3,
upper: 7,
};
});
</script>
Angular
src/app/example.component.html
<h2>Single Knob</h2>
<ion-range
id="range-single"
aria-label="Custom range"
[min]="0"
[max]="10"
[value]="5"
[pin]="true"
[ticks]="true"
[snaps]="true"
></ion-range>
<h2>Dual Knobs (A/B)</h2>
<ion-range
id="range-a-b"
aria-label="Custom dual knob range with A/B styling"
[min]="0"
[max]="10"
[value]="{lower: 3, upper: 7}"
[dualKnobs]="true"
[pin]="true"
></ion-range>
<h2>Dual Knobs (Lower/Upper)</h2>
<ion-range
id="range-lower-upper"
aria-label="Custom dual knob range with lower/upper styling"
[min]="0"
[max]="10"
[value]="{lower: 3, upper: 7}"
[dualKnobs]="true"
[pin]="true"
></ion-range>
src/app/example.component.css
/* Shared styles for all ranges */
ion-range {
--knob-size: 34px;
}
ion-range::part(knob) {
background: #fff;
box-sizing: border-box;
}
/* Hide the Material Design indicator */
ion-range::part(knob)::before {
display: none;
}
ion-range::part(pin) {
color: #fff;
border-radius: 50%;
}
ion-range::part(tick),
ion-range::part(tick-active) {
height: 8px;
top: 17px;
}
/* Single Knob Range */
#range-single::part(bar),
#range-single::part(tick) {
background: #bed4ff;
}
#range-single::part(bar-active),
#range-single::part(tick-active) {
background: #40a2fd;
}
#range-single::part(knob) {
border: 4px solid #40a2fd;
}
#range-single::part(knob pressed) {
background: #bed4ff;
}
#range-single::part(pin),
#range-single::part(pin)::before {
background: #40a2fd;
}
/* Dual Knobs (A/B) Range */
#range-a-b::part(bar-active) {
background: #1ea9ca;
}
#range-a-b::part(knob-a) {
border: 4px solid #0f8fd6;
}
#range-a-b::part(knob-a pressed) {
background: #cfeefe;
}
#range-a-b::part(pin-a),
#range-a-b::part(pin-a)::before {
background: #0f8fd6;
}
#range-a-b::part(knob-b) {
border: 4px solid #2dc2bd;
}
#range-a-b::part(knob-b pressed) {
background: #d4f5f3;
}
#range-a-b::part(pin-b),
#range-a-b::part(pin-b)::before {
background: #2dc2bd;
}
/* Dual Knobs (Lower/Upper) Range */
#range-lower-upper::part(bar-active) {
background: linear-gradient(to right, #0059ff 0%, #b77bff 100%);
}
#range-lower-upper::part(knob-lower) {
border: 4px solid #0059ff;
}
#range-lower-upper::part(knob-lower pressed) {
background: #bed4ff;
}
#range-lower-upper::part(pin-lower),
#range-lower-upper::part(pin-lower)::before {
background: #0059ff;
}
#range-lower-upper::part(knob-upper) {
border: 4px solid #b77bff;
}
#range-lower-upper::part(knob-upper pressed) {
background: #f1e5ff;
}
#range-lower-upper::part(pin-upper),
#range-lower-upper::part(pin-upper)::before {
background: #b77bff;
}
src/app/example.component.ts
import { Component } from '@angular/core';
import { IonRange } from '@ionic/angular';
@Component({
selector: 'app-example',
templateUrl: 'example.component.html',
styleUrls: ['example.component.css'],
imports: [IonRange],
})
export class ExampleComponent {}
React
src/main.css
/* Shared styles for all ranges */
ion-range {
--knob-size: 34px;
}
ion-range::part(knob) {
background: #fff;
box-sizing: border-box;
}
/* Hide the Material Design indicator */
ion-range::part(knob)::before {
display: none;
}
ion-range::part(pin) {
color: #fff;
border-radius: 50%;
}
ion-range::part(tick),
ion-range::part(tick-active) {
height: 8px;
top: 17px;
}
/* Single Knob Range */
#range-single::part(bar),
#range-single::part(tick) {
background: #bed4ff;
}
#range-single::part(bar-active),
#range-single::part(tick-active) {
background: #40a2fd;
}
#range-single::part(knob) {
border: 4px solid #40a2fd;
}
#range-single::part(knob pressed) {
background: #bed4ff;
}
#range-single::part(pin),
#range-single::part(pin)::before {
background: #40a2fd;
}
/* Dual Knobs (A/B) Range */
#range-a-b::part(bar-active) {
background: #1ea9ca;
}
#range-a-b::part(knob-a) {
border: 4px solid #0f8fd6;
}
#range-a-b::part(knob-a pressed) {
background: #cfeefe;
}
#range-a-b::part(pin-a),
#range-a-b::part(pin-a)::before {
background: #0f8fd6;
}
#range-a-b::part(knob-b) {
border: 4px solid #2dc2bd;
}
#range-a-b::part(knob-b pressed) {
background: #d4f5f3;
}
#range-a-b::part(pin-b),
#range-a-b::part(pin-b)::before {
background: #2dc2bd;
}
/* Dual Knobs (Lower/Upper) Range */
#range-lower-upper::part(bar-active) {
background: linear-gradient(to right, #0059ff 0%, #b77bff 100%);
}
#range-lower-upper::part(knob-lower) {
border: 4px solid #0059ff;
}
#range-lower-upper::part(knob-lower pressed) {
background: #bed4ff;
}
#range-lower-upper::part(pin-lower),
#range-lower-upper::part(pin-lower)::before {
background: #0059ff;
}
#range-lower-upper::part(knob-upper) {
border: 4px solid #b77bff;
}
#range-lower-upper::part(knob-upper pressed) {
background: #f1e5ff;
}
#range-lower-upper::part(pin-upper),
#range-lower-upper::part(pin-upper)::before {
background: #b77bff;
}
src/main.tsx
import React from 'react';
import { IonRange } from '@ionic/react';
import './main.css';
function Example() {
return (
<>
<h2>Single Knob</h2>
<IonRange
id="range-single"
aria-label="Custom range"
min={0}
max={10}
value={5}
pin={true}
ticks={true}
snaps={true}
></IonRange>
<h2>Dual Knobs (A/B)</h2>
<IonRange
id="range-a-b"
aria-label="Custom dual knob range with A/B styling"
min={0}
max={10}
value={{ lower: 3, upper: 7 }}
dualKnobs={true}
pin={true}
></IonRange>
<h2>Dual Knobs (Lower/Upper)</h2>
<IonRange
id="range-lower-upper"
aria-label="Custom dual knob range with lower/upper styling"
min={0}
max={10}
value={{ lower: 3, upper: 7 }}
dualKnobs={true}
pin={true}
></IonRange>
</>
);
}
export default Example;
Vue
<style>
/* Shared styles for all ranges */
ion-range {
--knob-size: 34px;
}
ion-range::part(knob) {
background: #fff;
box-sizing: border-box;
}
/* Hide the Material Design indicator */
ion-range::part(knob)::before {
display: none;
}
ion-range::part(pin) {
color: #fff;
border-radius: 50%;
}
ion-range::part(tick),
ion-range::part(tick-active) {
height: 8px;
top: 17px;
}
/* Single Knob Range */
#range-single::part(bar),
#range-single::part(tick) {
background: #bed4ff;
}
#range-single::part(bar-active),
#range-single::part(tick-active) {
background: #40a2fd;
}
#range-single::part(knob) {
border: 4px solid #40a2fd;
}
#range-single::part(knob pressed) {
background: #bed4ff;
}
#range-single::part(pin),
#range-single::part(pin)::before {
background: #40a2fd;
}
/* Dual Knobs (A/B) Range */
#range-a-b::part(bar-active) {
background: #1ea9ca;
}
#range-a-b::part(knob-a) {
border: 4px solid #0f8fd6;
}
#range-a-b::part(knob-a pressed) {
background: #cfeefe;
}
#range-a-b::part(pin-a),
#range-a-b::part(pin-a)::before {
background: #0f8fd6;
}
#range-a-b::part(knob-b) {
border: 4px solid #2dc2bd;
}
#range-a-b::part(knob-b pressed) {
background: #d4f5f3;
}
#range-a-b::part(pin-b),
#range-a-b::part(pin-b)::before {
background: #2dc2bd;
}
/* Dual Knobs (Lower/Upper) Range */
#range-lower-upper::part(bar-active) {
background: linear-gradient(to right, #0059ff 0%, #b77bff 100%);
}
#range-lower-upper::part(knob-lower) {
border: 4px solid #0059ff;
}
#range-lower-upper::part(knob-lower pressed) {
background: #bed4ff;
}
#range-lower-upper::part(pin-lower),
#range-lower-upper::part(pin-lower)::before {
background: #0059ff;
}
#range-lower-upper::part(knob-upper) {
border: 4px solid #b77bff;
}
#range-lower-upper::part(knob-upper pressed) {
background: #f1e5ff;
}
#range-lower-upper::part(pin-upper),
#range-lower-upper::part(pin-upper)::before {
background: #b77bff;
}
</style>
<template>
<h2>Single Knob</h2>
<ion-range
id="range-single"
aria-label="Custom range"
:min="0"
:max="10"
:value="5"
:pin="true"
:ticks="true"
:snaps="true"
></ion-range>
<h2>Dual Knobs (A/B)</h2>
<ion-range
id="range-a-b"
aria-label="Custom dual knob range with A/B styling"
:min="0"
:max="10"
:value="{lower: 3, upper: 7}"
:dual-knobs="true"
:pin="true"
></ion-range>
<h2>Dual Knobs (Lower/Upper)</h2>
<ion-range
id="range-lower-upper"
aria-label="Custom dual knob range with lower/upper styling"
:min="0"
:max="10"
:value="{lower: 3, upper: 7}"
:dual-knobs="true"
:pin="true"
></ion-range>
</template>
<script setup lang="ts">
import { IonRange } from '@ionic/vue';
</script>
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: 범위 활성 바(active bar)의 시작 위치예요. 이 기능은 단일 노브(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: 범위 값이 변경될 때마다 ionInput 이벤트를 발생시키기까지 기다리는 시간(밀리초)이에요.
Attribute: debounce
Type: number | undefined
Default: undefined
disabled
Description: true로 설정하면 사용자가 range와 상호작용할 수 없어요.
Attribute: disabled
Type: boolean
Default: false
dualKnobs
Description: true로 설정하면 range에 노브 두 개가 표시되고, value는 lower와 upper 프로퍼티를 가진 객체가 됩니다. false로 설정하면 range에 노브 하나가 표시되고 value는 숫자예요.
Attribute: dual-knobs
Type: boolean
Default: false
label
Description: 컨트롤의 라벨로 표시할 텍스트예요. 일반 텍스트만 필요하다면 label 슬롯보다 이 프로퍼티를 사용하세요. 둘 다 사용하면 label 프로퍼티가 label 슬롯보다 우선해요.
Attribute: label
Type: string | undefined
Default: undefined
labelPlacement
Description: range를 기준으로 라벨을 놓을 위치예요. "start": LTR에서는 라벨이 range의 왼쪽에, RTL에서는 오른쪽에 나타납니다. "end": LTR에서는 라벨이 range의 오른쪽에, RTL에서는 왼쪽에 나타나요. "fixed": "start"와 같은 동작을 하지만 고정된 폭을 가집니다. 긴 텍스트는 줄임표("...")로 잘립니다. "stacked": 방향과 관계없이 라벨이 range 위에 나타나요.
Attribute: label-placement
Type: "end" | "fixed" | "stacked" | "start"
Default: 'start'
max
Description: range의 최대 정수 값이에요.
Attribute: max
Type: number
Default: 100
min
Description: range의 최소 정수 값이에요. 이 값은 초기화 중에 한 번 설정되며 초기 렌더 후 값을 변경해도 업데이트되지 않는 가상 프로퍼티예요.
Attribute: min
Type: number
Default: 0
mode
Description: 모드는 어떤 플랫폼 스타일을 사용할지 결정해요. 이 값은 초기화 중에 한 번 설정되며 초기 렌더 후 값을 변경해도 업데이트되지 않는 가상 프로퍼티예요.
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로 설정하면 노브가 step 프로퍼티 값을 기준으로 균등하게 간격이 떨어진 틱 표시에 스냅돼요.
Attribute: snaps
Type: boolean
Default: false
step
Description: 값의 세분성(granularity)을 지정해요.
Attribute: step
Type: number
Default: 1
ticks
Description: true로 설정하면 step 값을 기준으로 틱 표시가 나타나요. snaps가 true일 때만 적용됩니다.
Attribute: ticks
Type: boolean
Default: true
value
Description: range의 값이에요.
Attribute: value
Type: number | { lower: number; upper: number; }
Default: 0
Events
| Name | Description | Bubbles |
|---|---|---|
ionBlur |
range가 포커스를 잃을 때 발생해요. | true |
ionChange |
사용자가 요소의 값을 수정할 때 <ion-range> 요소에서 ionChange 이벤트가 발생합니다: - 사용자가 노브를 드래그한 후 놓을 때; - 사용자가 키보드 화살표로 노브를 움직일 때. value 프로퍼티를 프로그래밍 방식으로 설정할 때는 이 이벤트가 발생하지 않아요. |
true |
ionFocus |
range가 포커스를 가질 때 발생해요. | true |
ionInput |
값이 수정될 때 <ion-range> 요소에서 ionInput 이벤트가 발생해요. ionChange와 달리, ionInput은 사용자가 노브를 드래그하는 동안 계속해서 발생합니다. |
true |
ionKnobMoveEnd |
사용자가 마우스 드래그, 터치 제스처 또는 키보드 상호작용을 통해 range 노브 이동을 끝낼 때 발생해요. | true |
ionKnobMoveStart |
사용자가 마우스 드래그, 터치 제스처 또는 키보드 상호작용을 통해 range 노브 이동을 시작할 때 발생해요. | true |
Methods
이 컴포넌트에는 공개 메서드가 없어요.
CSS Shadow Parts
| Name | Description |
|---|---|
activated |
노브가 활성화될 때 knob-handle, knob, pin에 추가돼요. dualKnobs가 true일 때 한 번에 한 세트만 이 파트를 가집니다. |
bar |
바의 비활성 부분이에요. |
bar-active |
바의 활성 부분이에요. |
focused |
현재 포커스를 가진 knob-handle, knob, pin에 추가돼요. dualKnobs가 true일 때 한 번에 한 세트만 이 파트를 가집니다. |
hover |
노브에 호버(hover)가 있을 때 knob-handle, knob, pin에 추가돼요. dualKnobs가 true일 때 한 번에 한 세트만 이 파트를 가집니다. |
knob |
range 트랙 위의 시각적 노브 요소예요. |
knob-a |
dualKnobs가 true일 때 정적 A 정체성의 시각적 노브예요. 이 정체성은 노브가 교차해 어느 것이 lower나 upper 값을 나타내는지 서로 바뀌더라도 변하지 않습니다. |
knob-b |
dualKnobs가 true일 때 정적 B 정체성의 시각적 노브예요. 이 정체성은 노브가 교차해 어느 것이 lower나 upper 값을 나타내는지 서로 바뀌더라도 변하지 않습니다. |
knob-handle |
노브를 감싸고 드래그 상호작용을 처리하는 컨테이너예요. |
knob-handle-a |
dualKnobs가 true일 때 정적 A 정체성을 가진 노브의 컨테이너예요. 이 정체성은 노브가 교차해 어느 것이 lower나 upper 값을 나타내는지 서로 바뀌더라도 변하지 않습니다. |
knob-handle-b |
dualKnobs가 true일 때 정적 B 정체성을 가진 노브의 컨테이너예요. 이 정체성은 노브가 교차해 어느 것이 lower나 upper 값을 나타내는지 서로 바뀌더라도 변하지 않습니다. |
knob-handle-lower |
dualKnobs가 true일 때 현재 값이 lower인 노브의 컨테이너예요. 노브가 교차하면 lower와 upper 파트가 가리키는 knob handle이 서로 바뀝니다. |
knob-handle-upper |
dualKnobs가 true일 때 현재 값이 upper인 노브의 컨테이너예요. 노브가 교차하면 lower와 upper 파트가 가리키는 knob handle이 서로 바뀝니다. |
knob-lower |
dualKnobs가 true일 때 현재 값이 lower인 시각적 노브예요. 노브가 교차하면 lower와 upper 파트가 가리키는 노브가 서로 바뀝니다. |
knob-upper |
dualKnobs가 true일 때 현재 값이 upper인 시각적 노브예요. 노브가 교차하면 lower와 upper 파트가 가리키는 노브가 서로 바뀝니다. |
label |
range를 설명하는 라벨 텍스트예요. |
pin |
노브 위에 표시되는 값 표시기예요. |
pin-a |
dualKnobs가 true일 때 정적 A 정체성을 가진 노브 위의 값 표시기예요. 이 정체성은 노브가 교차해 어느 것이 lower나 upper 값을 나타내는지 서로 바뀌더라도 변하지 않습니다. |
pin-b |
dualKnobs가 true일 때 정적 B 정체성을 가진 노브 위의 값 표시기예요. 이 정체성은 노브가 교차해 어느 것이 lower나 upper 값을 나타내는지 서로 바뀌더라도 변하지 않습니다. |
pin-lower |
dualKnobs가 true일 때 현재 값이 lower인 노브 위의 값 표시기예요. 노브가 교차하면 lower와 upper 파트가 가리키는 핀이 서로 바뀝니다. |
pin-upper |
dualKnobs가 true일 때 현재 값이 upper인 노브 위의 값 표시기예요. 노브가 교차하면 lower와 upper 파트가 가리키는 핀이 서로 바뀝니다. |
pressed |
드래그하기 위해 현재 눌려 있는 knob-handle, knob, pin에 추가돼요. dualKnobs가 true일 때 한 번에 한 세트만 이 파트를 가집니다. |
tick |
비활성 틱 표시예요. |
tick-active |
활성 틱 표시예요. |
CSS Custom Properties
iOS
| Name | Description |
|---|---|
--bar-background |
range 바의 배경색(Background of the range bar) |
--bar-background-active |
활성 range 바의 배경색(Background of the active range bar) |
--bar-border-radius |
range 바의 테두리 반경(Border radius of the range bar) |
--bar-height |
range 바의 높이(Height of the range bar) |
--height |
range의 높이(Height of the range) |
--knob-background |
range 노브의 배경색(Background of the range knob) |
--knob-border-radius |
range 노브의 테두리 반경(Border radius of the range knob) |
--knob-box-shadow |
range 노브의 박스 섀도(Box shadow of the range knob) |
--knob-size |
range 노브의 크기(Size of the range knob) |
--pin-background |
range 핀의 배경색(MD 모드에서만 사용 가능)(Background of the range pin (only available in MD mode)) |
--pin-color |
range 핀의 색상(MD 모드에서만 사용 가능)(Color of the range pin (only available in MD mode)) |
MD
| Name | Description |
|---|---|
--bar-background |
range 바의 배경색(Background of the range bar) |
--bar-background-active |
활성 range 바의 배경색(Background of the active range bar) |
--bar-border-radius |
range 바의 테두리 반경(Border radius of the range bar) |
--bar-height |
range 바의 높이(Height of the range bar) |
--height |
range의 높이(Height of the range) |
--knob-background |
range 노브의 배경색(Background of the range knob) |
--knob-border-radius |
range 노브의 테두리 반경(Border radius of the range knob) |
--knob-box-shadow |
range 노브의 박스 섀도(Box shadow of the range knob) |
--knob-size |
range 노브의 크기(Size of the range knob) |
--pin-background |
range 핀의 배경색(MD 모드에서만 사용 가능)(Background of the range pin (only available in MD mode)) |
--pin-color |
range 핀의 색상(MD 모드에서만 사용 가능)(Color of the range pin (only available in MD mode)) |
Slots
| Name | Description |
|---|---|
end |
LTR에서 range 슬라이더의 오른쪽에, RTL에서는 왼쪽에 콘텐츠가 배치돼요. |
label |
range와 연결할 라벨 텍스트예요. "labelPlacement" 프로퍼티를 사용해 range 기준으로 라벨이 놓일 위치를 제어하세요. |
start |
LTR에서 range 슬라이더의 왼쪽에, RTL에서는 오른쪽에 콘텐츠가 배치돼요. |
더 알아보기 (Learn more)
ion-range는 노브를 드래그해 값을 고르는 슬라이더예요. --bar-*, --knob-*, --pin-* 같은 CSS 변수와 shadow part로 색상·크기까지 세밀하게 다듬을 수 있고, 이중 노브(dualKnobs)로 구간을 고르는 것도 가능합니다. 라벨은 프로퍼티나 슬롯, 그리고 스크린 리더를 위한 aria-label로 지정하세요.