Search results

SliderComponent

Represents the React Slider Component

<Slider value={value}></Slider>

Properties

colorRange

ColorRangeDataModel[]

Specifies the color to the slider based on given value.

cssClass

string

Specifies the custom classes to be added to the element used to customize the slider.

<style>
.sliderCss {
    border: 1px solid;
}
</style>
import * as React from 'react';
import { SliderComponent, ColorRangeDataModel } from '@syncfusion/ej2-react-inputs';

export default class App extends React.Component<{}, {}> {
public colorRange: ColorRangeDataModel[] = [{color:"#898b2b", start:10, end:45}];
  render() {
    
    return (
        <div id='container'>
            <div className='wrap'>
                <SliderComponent id='slider' value={30} cssClass={sliderCss} />
            </div>
        </div>
    );
  }
}

Defaults to

customValues

string[] | number[]

Specifies an array of slider values in number or string type. The min and max step values are not considered.

Defaults to null

enableAnimation

boolean

Enables/Disables the animation for slider movement.

Defaults to true

enableHtmlSanitizer

boolean

Defines whether to allow the cross-scripting site or not.

Defaults to false

enablePersistence

boolean

Enable or disable persisting component’s state between page reloads.

Defaults to false

enableRtl

boolean

Enable or disable rendering component in right to left direction.

Defaults to false

enabled

boolean

Enables or Disables the slider.

Defaults to true

limits

LimitDataModel

Specified the limit within which the slider to be moved. Refer the documentation here to know more about this property.

Defaults to { enabled: false }

locale

string

Overrides the global culture and localization value for this component. Default global culture is ‘en-US’.

Defaults to

max

number

Gets/Sets the maximum value of the slider.

Defaults to 100

min

number

Gets/Sets the minimum value of the slider.

Defaults to 0

orientation

string

Specifies whether to render the slider in vertical or horizontal orientation. Refer the documentation here to know more about this property.

Defaults to ‘Horizontal’

readonly

boolean

Specifies whether the render the slider in read-only mode to restrict any user interaction. The slider rendered with user defined values and can’t be interacted with user actions.

Defaults to false

showButtons

boolean

Specifies whether to show or hide the increase/decrease buttons of Slider to change the slider value. Refer the documentation here to know more about this property.

Defaults to false

step

number

Specifies the step value for each value change when the increase / decrease button is clicked or on arrow keys press or on dragging the thumb. Refer the documentation here to know more about this property.

Defaults to 1

ticks

TicksDataModel

It is used to render the slider ticks options such as placement and step values. Refer the documentation here to know more about this property with demo.

import * as React from 'react';
import { SliderComponent, ColorRangeDataModel } from '@syncfusion/ej2-react-inputs';

export default class App extends React.Component<{}, {}> {
public colorRange: ColorRangeDataModel[] = [{color:"#898b2b", start:10, end:45}];
  render() {
    
    return (
        <div id='container'>
            <div className='wrap'>
                <SliderComponent id='slider' value={30} colorRange={this.colorRange} />
            </div>
        </div>
    );
  }
}

Defaults to { placement: ‘before’ }

tooltip

TooltipDataModel

Specifies the visibility, position of the tooltip over the slider element.

Defaults to { placement: ‘Before’, isVisible: false, showOn: ‘Focus’, format: null }

type

string

Defines the type of the Slider. The available options are:

  • default - Allows to a single value in the Slider.
  • minRange - Allows to select a single value in the Slider. It display’s a shadow from the start to the current value.
  • range - Allows to select a range of values in the Slider. It displays shadow in-between the selection range.

    import * as React from "react";
    import { SliderComponent, ColorRangeDataModel, TooltipDataModel } from "@syncfusion/ej2-react-inputs";

export default class App extends React.Component<{}, {}> { public tooltip: TooltipDataModel = { placement: “After”, isVisible: true, showOn: “Focus”}; render() { return (

Default
MinRange
Range
<SliderComponent id=“range” type=“Range” value={[30, 70]} />
); } }

<h3 class="doc-prop-wrapper" id="value" data-Path="value-value">
<a href="#value" aria-hidden="true" class="anchor">
<svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16">
<path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 
3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 
4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 
1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z">
</path>
</svg>
</a><span class='doc-prop-name'>value</span>

<span class="doc-prop-type"> `number` &#124;  `number[]`
</span>

</h3>


It is used to denote the current value of the Slider.
The value should be specified in array of number when render Slider type as range.


Defaults to *null*

<h3 class="doc-prop-wrapper" id="width" data-Path="width-width">
<a href="#width" aria-hidden="true" class="anchor">
<svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16">
<path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 
3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 
4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 
1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z">
</path>
</svg>
</a><span class='doc-prop-name'>width</span>

<span class="doc-prop-type"> `number` &#124;  `string`
</span>

</h3>


Specifies the width of the Slider.

Defaults to *null*

## Methods

### destroy

Removes the component from the DOM and detaches all its related event handlers.
Also it removes the attributes and classes.

Returns *void*

### reposition

It is used to reposition slider.

Returns *void*

## Events

<h3 class="doc-prop-wrapper" id="change" data-Path="change-change">
<a href="#change" aria-hidden="true" class="anchor">
<svg aria-hidden="true" height="16" version="1.1" viewBox="0 0 16 16" width="16">
<path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 
3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 
4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 
1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z">
</path>
</svg>
</a><span class='doc-prop-name'>change</span>

<span class="doc-prop-type"> [`EmitType<SliderChangeEventArgs>`](./sliderChangeEventArgs)
</span>

</h3>


We can trigger change event whenever Slider value is changed.
 In other term, this event will be triggered while drag the slider thumb.
```tsx
import * as React from "react";
import { SliderComponent, SliderChangeEventArgs } from "@syncfusion/ej2-react-inputs";

export default class App extends React.Component<{}, {}> {
  private defaultObj: SliderComponent = null as any;
  private sliderTrack: HTMLElement = null as any;
  private sliderHandle: HTMLElement = null as any;
  private changeEvent(args: SliderChangeEventArgs): void {
      if (args.value > 0 && args.value <= 25) {
      // Change handle and range bar color to green when
          this.sliderHandle.style.backgroundColor = "green";
          this.sliderTrack.style.backgroundColor = "green";
      } else if (args.value > 25 && args.value <= 50) {
      // Change handle and range bar color to royal blue
          this.sliderHandle.style.backgroundColor = "royalblue";
          this.sliderTrack.style.backgroundColor = "royalblue";
      } else if (args.value > 50 && args.value <= 75) {
      // Change handle and range bar color to dark orange
          this.sliderHandle.style.backgroundColor = "darkorange";
          this.sliderTrack.style.backgroundColor = "darkorange";
      } else if (args.value > 75 && args.value <= 100) {
      // Change handle and range bar color to red
          this.sliderHandle.style.backgroundColor = "red";
          this.sliderTrack.style.backgroundColor = "red";
    }
  }
  
  private created(): void {
      this.sliderTrack = this.defaultObj.element.querySelector(".e-range") as any;
      this.sliderHandle = this.defaultObj.element.querySelector(".e-handle") as any;
      this.sliderHandle.style.backgroundColor = "green";
      this.sliderTrack.style.backgroundColor = "green";
  }
  render() {
    return (
      <div id="container">
        <div className="wrap">
        <SliderComponent
                id="dynamic_color_slider"
                ref={slider => {
                  this.defaultObj = slider as any;
                }}
                type="MinRange"
                min={0}
                max={100}
                value={30}
                change={this.changeEvent.bind(this) as any}
                created={this.created.bind(this)}
              />
        </div>
      </div>
    );
  }
}

changed

EmitType<SliderChangeEventArgs>

Fires whenever the Slider value is changed. In other term, this event will be triggered, while drag the slider thumb completed.

created

EmitType<Object>

Triggers when the Slider is successfully created.

renderedTicks

EmitType<SliderTickRenderedEventArgs>

Triggers when the ticks are rendered on the Slider.

import * as React from "react";
import { SliderComponent, TooltipDataModel,SliderTickRenderedEventArgs,TicksDataModel } from "@syncfusion/ej2-react-inputs";

export default class App extends React.Component<{}, {}> {
 
  private custom: TicksDataModel = { placement: "Both", largeStep: 20, smallStep: 5 };
  private value: number[] = [30, 70];
  private customTicks(args: SliderTickRenderedEventArgs): void {
      let li: any = args.ticksWrapper.getElementsByClassName("e-large");
      let remarks: any = ["Very Poor", "Poor", "Average", "Good", "Very Good", "Excellent"];
      for (let i: number = 0; i < li.length; ++i) {
          (li[i].querySelectorAll(".e-tick-both")[1] as HTMLElement).innerText = remarks[i];
    }
  }
  render() {
    return (
      <div id="container">
        <div className="wrap">
        <SliderComponent
                id="slider"
                type="MinRange"
                min={0}
                max={100}
                value={this.value}
                ticks={this.custom}
                renderedTicks={this.customTicks.bind(this) as any}
              />
        </div>
      </div>
    );
  }
}

renderingTicks

EmitType<SliderTickEventArgs>

Triggers on rendering the ticks element in the Slider, which is used to customize the ticks labels dynamically.

import * as React from "react";
import { SliderComponent, TooltipDataModel, SliderTickEventArgs,TicksDataModel } from "@syncfusion/ej2-react-inputs";

export default class App extends React.Component<{}, {}> {
  public min = new Date("2013-06-13").getTime();
  public max = new Date("2013-06-21").getTime();
  public step = 86400000;
  public value = new Date("2013-06-15").getTime();
  public ticks: TicksDataModel = { placement: "After", largeStep: 2 * 86400000 };
  renderingTicksHandler(args: SliderTickEventArgs) {
    let totalMiliSeconds = Number(args.value);
    let custom = { year: "numeric", month: "short", day: "numeric" };
    args.text = new Date(totalMiliSeconds).toLocaleDateString("en-us", custom);
  }
  render() {
    return (
      <div id="container">
        <div className="wrap">
          <SliderComponent
            id="slider"
            min={this.min}
            max={this.max}
            value={this.value}
            step={this.step}
            ticks={this.ticks}
            showButtons={true}
            renderingTicks={this.renderingTicksHandler.bind(this) as any}
          />
        </div>
      </div>
    );
  }
}

tooltipChange

EmitType<SliderTooltipEventArgs>

Triggers when the Sider tooltip value is changed.

import * as React from "react";
import { SliderComponent, TooltipDataModel,SliderTooltipEventArgs,TicksDataModel } from "@syncfusion/ej2-react-inputs";

export default class App extends React.Component<{}, {}> {
  public min = new Date("2013-06-13").getTime();
  public max = new Date("2013-06-21").getTime();
  public step = 86400000;
  public value = new Date("2013-06-15").getTime();
  public tooltip: TooltipDataModel = { placement: "Before", isVisible: true };
  tooltipChangeHandler(args: SliderTooltipEventArgs) {
    let totalMiliSeconds = Number(args.text);
    let custom = { year: "numeric", month: "short", day: "numeric" };
    args.text = new Date(totalMiliSeconds).toLocaleDateString("en-us", custom);
  }
  render() {
    return (
      <div id="container">
        <div className="wrap">
          <SliderComponent
            id="slider"
            min={this.min}
            max={this.max}
            value={this.value}
            step={this.step}
            tooltip={this.tooltip}
            showButtons={true}
            tooltipChange={this.tooltipChangeHandler.bind(this) as any}
          />
        </div>
      </div>
    );
  }
}