RangeControl Edit

RangeControls are used to make selections from a range of incremental values.

A RangeControl for volume

Table of contents Table of contents

  1. Design guidelines
  2. Development guidelines
  3. Related components

Top ↑

Design guidelines Design guidelines

Anatomy Anatomy

A RangeControl can contain the following elements:

  1. Track: The track shows the range available for user selection. For left-to-right (LTR) languages, the smallest value appears on the far left, and the largest value on the far right. For right-to-left (RTL) languages this orientation is reversed, with the smallest value on the far right and the largest value on the far left.
  2. Thumb: The thumb slides along the track, displaying the selected value through its position.
  3. Value entry field (optional): The value entry field displays the currently selected, specific numerical value.
  4. Icon (optional): An icon can be displayed before or after the slider.
  5. Tick mark (optional): Tick marks represent predetermined values to which the user can move the slider.

Top ↑

Types Types

Continuous sliders Continuous sliders

Continuous sliders allow users to select a value along a subjective range. They do not display the selected numeric value. Use them when displaying/editing the numeric value is not important, like volume.

Top ↑

Discrete sliders Discrete sliders

Discrete sliders can be adjusted to a specific value by referencing its value entry field. Use them when it’s important to display/edit the numeric value, like text size.

Possible selections may be organized through the use of tick marks, which a thumb will snap to (or to which an input will round up or down).

Top ↑

Behavior Behavior

  • Click and drag: The slider is controlled by clicking the thumb and dragging it.
  • Click jump: The slider is controlled by clicking the track.
  • Click and arrow: The slider is controlled by clicking the thumb, then using arrow keys to move it.
  • Tab and arrow: The slider is controlled by using the tab key to select the thumb of the desired slider, then using arrow keys to move it.
  • Tick marks (Optional) Discrete sliders can use evenly spaced tick marks along the slider track, and the thumb will snap to them. Each tick mark should change the setting in increments that are discernible to the user.
  • Value entry field (Optional): Discrete sliders have value entry fields. After a text entry is made, the slider position automatically updates to reflect the new value.

Top ↑

Usage Usage

RangeControls reflect a range of values along a track, from which users may select a single value. They are ideal for adjusting settings such as volume, opacity, or text size.

RangeControls can have icons on both ends of the track that reflect a range of values.

Top ↑

Immediate effects Immediate effects

Changes made with RangeControls are immediate, allowing a user to make adjustments until finding their preference. They shouldn’t be paired with settings that have delays in providing feedback.

A RangeControl that requires a save action

Don’t
Don’t use RangeControls if the effect isn’t immediate.

Top ↑

Current state Current state

RangeControls reflect the current state of the settings they control.

Top ↑

Values Values

A RangeControl with an editable numeric value

Editable numeric values: Editable numeric values allow users to set the exact value of a RangeControl. After setting a value, the thumb position is immediately updated to match the new value.

A RangeControl with only two values

Don’t
RangeControls should only be used for choosing selections from a range of values (e.g., don’t use a RangeControl if there are only 2 values).

Don’t
RangeControls should provide the full range of choices available for the user to select from (e.g., don’t disable only part of a RangeControl).

Top ↑

Development guidelines Development guidelines

Top ↑

Usage Usage

Render a RangeControl to make a selection from a range of incremental values.

import { RangeControl } from '@wordpress/components';
import { withState } from '@wordpress/compose';

const MyRangeControl = withState( {
        columns: 2,
} )( ( { columns, setState } ) => (
    <RangeControl
        label="Columns"
        value={ columns }
        onChange={ ( columns ) => setState( { columns } ) }
        min={ 2 }
        max={ 10 }
    />
) );

Top ↑

Props Props

The set of props accepted by the component will be specified below.
Props not included in this set will be applied to the input elements.

Top ↑

label label

If this property is added, a label will be generated using label property as the content.

  • Type: String
  • Required: No
  • Platform: Web | Mobile

Top ↑

help help

If this property is added, a help text will be generated using help property as the content.

  • Type: String|WPElement
  • Required: No
  • Platform: Web

Top ↑

beforeIcon beforeIcon

If this property is added, a DashIcon component will be rendered before the slider with the icon equal to beforeIcon

  • Type: String
  • Required: No
  • Platform: Web

Top ↑

afterIcon afterIcon

If this property is added, a DashIcon component will be rendered after the slider with the icon equal to afterIcon

  • Type: String
  • Required: No
  • Platform: Web

Top ↑

allowReset allowReset

If this property is true, a button to reset the the slider is rendered.

  • Type: Boolean
  • Required: No
  • Platform: Web | Mobile

Top ↑

initialPosition initialPosition

If no value exists this prop contains the slider starting position.

  • Type: Number
  • Required: No
  • Platform: Web | Mobile

Top ↑

value value

The current value of the range slider.

  • Type: Number
  • Required: Yes
  • Platform: Web | Mobile

Top ↑

onChange onChange

A function that receives the new value.
If allowReset is true, when onChange is called without any parameter passed it should reset the value.

  • Type: function
  • Required: Yes
  • Platform: Web | Mobile

Top ↑

min min

The minimum value accepted. If smaller values are inserted onChange will not be called and the value gets reverted when blur event fires.

  • Type: Number
  • Required: No
  • Platform: Web | Mobile

Top ↑

max max

The maximum value accepted. If higher values are inserted onChange will not be called and the value gets reverted when blur event fires.

  • Type: Number
  • Required: No
  • Platform: Web | Mobile

Top ↑

icon icon

An icon to be shown above the slider next to it’s container title.

  • Type: String
  • Required: No
  • Platform: Mobile

Top ↑

separatorType separatorType

Define if separator line under/above control row should be disabled or full width. By default it is placed below excluding underline the control icon.

  • Type: String Enum
  • Values: none | fullWidth | topFullWidth
  • Required: No
  • Platform: Mobile

Top ↑

  • To collect a numerical input in a text field, use the TextControl component.