React Range Component

Range

React range component. Use our custom range inputs for consistent cross-browser styling and built-in customization.

Other frameworks

CoreUI components are available as native Angular, Bootstrap (Vanilla JS), and Vue components. To learn more please visit the following pages.

Overview#

Create custom <input type="range"> controls with <CFormRange>. The track (the background) and thumb (the value) are both styled to appear the same across browsers. As only Edge Legacy and Firefox supports "filling" their track from the left or right of the thumb as a means to visually indicate progress, we do not currently support it.

<CFormRange id="customRange1" label="Example range" />

Disabled#

Add the disabled boolean attribute on an input to give it a grayed out appearance and remove pointer events.

<CFormRange id="disabledRange" label="Disabled range" disabled />

Min and max#

Range inputs have implicit values for min and max0 and 100, respectively. You may specify new values for those using the min and max attributes.

<CFormRange min={0} max={5} label="Example range" defaultValue="3" id="customRange2" />

Steps#

By default, range inputs "snap" to integer values. To change this, you can specify a step value. In the example below, we double the number of steps by using step={0.5}.

<CFormRange min={0} max={5} step={0.5} label="Example range" defaultValue="3" id="customRange3" />

Customizing#

SASS variables#

$form-range-track-width: 100% !default;
$form-range-track-height: .5rem !default;
$form-range-track-cursor: pointer !default;
$form-range-track-bg: var(--cui-secondary-bg) !default;
$form-range-track-border-radius: 1rem !default;
$form-range-track-box-shadow: var(--cui-box-shadow-inset) !default;
$form-range-thumb-width: 1rem !default;
$form-range-thumb-height: $form-range-thumb-width !default;
$form-range-thumb-bg: $component-active-bg !default;
$form-range-thumb-border: 0 !default;
$form-range-thumb-border-radius: 1rem !default;
$form-range-thumb-box-shadow: 0 .1rem .25rem rgba($black, .1) !default;
$form-range-thumb-focus-box-shadow: 0 0 0 1px $body-bg, $input-focus-box-shadow !default;
$form-range-thumb-focus-box-shadow-width: $input-focus-width !default; // For focus box shadow issue in Edge
$form-range-thumb-active-bg: tint-color($primary, 70%) !default;
$form-range-thumb-disabled-bg: var(--cui-secondary-color) !default;
$form-range-thumb-transition: background-color .15s ease-in-out, border-color .15s ease-in-out, box-shadow .15s ease-in-out !default;

API#

CFormRange#

import { CFormRange } from '@coreui/react'
// or
import CFormRange from '@coreui/react/src/components/form/CFormRange'
PropertyDescriptionTypeDefault
classNameA string of all className you want applied to the component.string-
disabledToggle the disabled state for the component.boolean-
label
4.2.0+
Add a caption for a component.ReactNode-
maxSpecifies the maximum value for the component.number-
minSpecifies the minimum value for the component.number-
onChangeMethod called immediately after the value prop changes.ChangeEventHandler<HTMLInputElement>-
readOnlyToggle the readonly state for the component.boolean-
stepSpecifies the interval between legal numbers in the component.number-
valueThe value attribute of component.string | number | string[]-