Class RangeSlider

All Implemented Interfaces:
AttachNotifier, BlurNotifier<RangeSlider>, DetachNotifier, Focusable<RangeSlider>, FocusNotifier<RangeSlider>, HasElement, HasEnabled, HasHelper, HasLabel, HasSize, HasStyle, HasValidation, HasValue<AbstractField.ComponentValueChangeEvent<RangeSlider,RangeSliderValue>,RangeSliderValue>, HasValueAndElement<AbstractField.ComponentValueChangeEvent<RangeSlider,RangeSliderValue>,RangeSliderValue>, KeyNotifier, HasTooltip, HasValidationProperties, InputField<AbstractField.ComponentValueChangeEvent<RangeSlider,RangeSliderValue>,RangeSliderValue>, HasValueChangeMode, Serializable

@Tag("vaadin-range-slider") @NpmPackage(value="@vaadin/slider", version="25.1.2") @JsModule("@vaadin/slider/src/vaadin-range-slider.js") public class RangeSlider extends AbstractSinglePropertyField<RangeSlider,RangeSliderValue>
RangeSlider is an input field that allows the user to select a numeric range within bounds by dragging two thumbs along a track or using arrow keys for precise input.
Author:
Vaadin Ltd.
See Also:
  • Constructor Details

    • RangeSlider

      public RangeSlider()
      Constructs a RangeSlider with min 0 and max 100. The initial value is [0, 100].

      The step defaults to 1.

    • RangeSlider

      public RangeSlider(double min, double max)
      Constructs a RangeSlider with the given min and max. The initial value is set to [min, max].

      The step defaults to 1.

      Parameters:
      min - the minimum value
      max - the maximum value
    • RangeSlider

      public RangeSlider(String label)
      Constructs a RangeSlider with the given label, min 0, and max 100. The initial value is [0, 100].

      The step defaults to 1.

      Parameters:
      label - the text to set as the label
    • RangeSlider

      public RangeSlider(String label, double min, double max)
      Constructs a RangeSlider with the given label, min and max. The initial value is set to [min, max].

      The step defaults to 1.

      Parameters:
      label - the text to set as the label
      min - the minimum value
      max - the maximum value
  • Method Details

    • setAccessibleNameStart

      public void setAccessibleNameStart(String accessibleName)
      Sets an accessible name for the start range input element of the slider.
      Parameters:
      accessibleName - the accessible name to set, or null to remove it
    • getAccessibleNameStart

      public Optional<String> getAccessibleNameStart()
      Gets the accessible name for the start range input element of the slider.
      Returns:
      an optional accessible name, or an empty optional if no accessible name has been set
    • setAccessibleNameEnd

      public void setAccessibleNameEnd(String accessibleName)
      Sets an accessible name for the end range input element of the slider.
      Parameters:
      accessibleName - the accessible name to set, or null to remove it
    • getAccessibleNameEnd

      public Optional<String> getAccessibleNameEnd()
      Gets the accessible name for the end range input element of the slider.
      Returns:
      an optional accessible name, or an empty optional if no accessible name has been set
    • getMin

      public double getMin()
      Gets the minimum value of the slider.
      Returns:
      the minimum value
    • setMin

      public void setMin(double min)
      Sets the minimum value of the slider.
      Parameters:
      min - the minimum value
    • getMax

      public double getMax()
      Gets the maximum value of the slider.
      Returns:
      the maximum value
    • setMax

      public void setMax(double max)
      Sets the maximum value of the slider.
      Parameters:
      max - the maximum value
    • getStep

      public double getStep()
      Gets the step value of the slider.

      Valid slider values are calculated relative to the minimum value: min, min + step, min + 2*step, etc.

      Returns:
      the step value
    • setStep

      public void setStep(double step)
      Sets the step value of the slider.

      Valid slider values are calculated relative to the minimum value: min, min + step, min + 2*step, etc.

      Parameters:
      step - the step value
    • clear

      public void clear()
      Clears the slider value, setting it to the full range from minimum to maximum.
      See Also:
    • hasValidValue

      protected boolean hasValidValue()
      Description copied from class: AbstractSinglePropertyField
      Checks whether the element property has a value that can be converted to the model type. Property changes from the element will be ignored if this method returns false. The default implementation always return true.
      Overrides:
      hasValidValue in class AbstractSinglePropertyField<RangeSlider,RangeSliderValue>
      Returns:
      true if the element property value can be converted to the model type; otherwise false
    • isValueWithinMinMax

      protected boolean isValueWithinMinMax(RangeSliderValue value)
    • isValueAlignedWithStep

      protected boolean isValueAlignedWithStep(RangeSliderValue value)
    • onAttach

      protected void onAttach(AttachEvent attachEvent)
      Description copied from class: Component
      Called when the component is attached to a UI.

      This method is invoked before the AttachEvent is fired for the component. Make sure to call super.onAttach when overriding this method.

      Overrides:
      onAttach in class Component
      Parameters:
      attachEvent - the attach event
    • bindMin

      public SignalBinding<Double> bindMin(Signal<Double> signal)
      Binds the given signal to the minimum value of the slider as a one-way binding so that the property is updated when the signal's value is updated.

      The minimum value is set immediately with the current signal value when the binding is created, and is kept synchronized with any subsequent signal value changes while the component is in attached state. When the component is in detached state, signal value changes have no effect.

      While a signal is bound, any attempt to set the minimum value manually through the setter throws a BindingActiveException.

      Parameters:
      signal - the signal to bind the minimum value to, not null
      Returns:
      a SignalBinding that can be used to register onChange callbacks
      Since:
      25.1
      See Also:
    • bindMax

      public SignalBinding<Double> bindMax(Signal<Double> signal)
      Binds the given signal to the maximum value of the slider as a one-way binding so that the property is updated when the signal's value is updated.

      The maximum value is set immediately with the current signal value when the binding is created, and is kept synchronized with any subsequent signal value changes while the component is in attached state. When the component is in detached state, signal value changes have no effect.

      While a signal is bound, any attempt to set the maximum value manually through the setter throws a BindingActiveException.

      Parameters:
      signal - the signal to bind the maximum value to, not null
      Returns:
      a SignalBinding that can be used to register onChange callbacks
      Since:
      25.1
      See Also:
    • bindStep

      public SignalBinding<Double> bindStep(Signal<Double> signal)
      Binds the given signal to the step value of the slider as a one-way binding so that the property is updated when the signal's value is updated.

      The step value is set immediately with the current signal value when the binding is created, and is kept synchronized with any subsequent signal value changes while the component is in attached state. When the component is in detached state, signal value changes have no effect.

      While a signal is bound, any attempt to set the step value manually through the setter throws a BindingActiveException.

      Parameters:
      signal - the signal to bind the step value to, not null
      Returns:
      a SignalBinding that can be used to register onChange callbacks
      Since:
      25.1
      See Also:
    • setValueAlwaysVisible

      public void setValueAlwaysVisible(boolean valueAlwaysVisible)
      Sets whether the value bubble is always visible, regardless of focus or hover state. By default, bubble is hidden and only shown on interaction.
      Parameters:
      valueAlwaysVisible - true to always show the value bubble, false otherwise
    • isValueAlwaysVisible

      public boolean isValueAlwaysVisible()
      Gets whether the value bubble is always visible, regardless of focus or hover state. By default, bubble is hidden and only shown on interaction.
      Returns:
      true if the value bubble is always visible, false otherwise
    • setMinMaxVisible

      public void setMinMaxVisible(boolean minMaxVisible)
      Sets whether the min and max values are displayed below the slider track. By default, min and max values are hidden.
      Parameters:
      minMaxVisible - true to display min and max values, false otherwise
    • isMinMaxVisible

      public boolean isMinMaxVisible()
      Gets whether the min and max values are displayed below the slider track. By default, min and max values are hidden.
      Returns:
      true if the min and max values are displayed, false otherwise
    • getValueChangeMode

      public ValueChangeMode getValueChangeMode()
      Gets current value change mode of the component.

      The default value is ValueChangeMode.ON_CHANGE.

      Specified by:
      getValueChangeMode in interface HasValueChangeMode
      Returns:
      current value change mode of the component, or null if the value is not synchronized
    • setValueChangeMode

      public void setValueChangeMode(ValueChangeMode valueChangeMode)
      Description copied from interface: HasValueChangeMode
      Sets new value change mode for the component.
      Specified by:
      setValueChangeMode in interface HasValueChangeMode
      Parameters:
      valueChangeMode - new value change mode, or null to disable the value synchronization
    • setValueChangeTimeout

      public void setValueChangeTimeout(int valueChangeTimeout)
      Description copied from interface: HasValueChangeMode
      Sets how often HasValue.ValueChangeEvents are triggered when the ValueChangeMode is set to ValueChangeMode.LAZY, or ValueChangeMode.TIMEOUT.

      Implementations should use ValueChangeMode.applyChangeTimeout(ValueChangeMode, int, DomListenerRegistration).

      Specified by:
      setValueChangeTimeout in interface HasValueChangeMode
      Parameters:
      valueChangeTimeout - the timeout in milliseconds of how often HasValue.ValueChangeEvents are triggered.
    • getValueChangeTimeout

      public int getValueChangeTimeout()
      Description copied from interface: HasValueChangeMode
      Returns the currently set timeout, for how often HasValue.ValueChangeEvents are triggered when the ValueChangeMode is set to ValueChangeMode.LAZY, or ValueChangeMode.TIMEOUT.
      Specified by:
      getValueChangeTimeout in interface HasValueChangeMode
      Returns:
      the timeout in milliseconds of how often HasValue.ValueChangeEvents are triggered.
    • setValue

      public void setValue(RangeSliderValue value)
      Description copied from interface: HasValue
      Sets the value of this object. If the new value is not equal to getValue(), fires a value change event. May throw IllegalArgumentException if the value is not acceptable.

      Implementation note: the implementing class should document whether null values are accepted or not, and override HasValue.getEmptyValue() if the empty value is not null.

      Specified by:
      setValue in interface HasValue<TComponent extends com.vaadin.flow.component.slider.SliderBase<TComponent,TValue>,TValue>
      Overrides:
      setValue in class AbstractField<TComponent extends com.vaadin.flow.component.slider.SliderBase<TComponent,TValue>,TValue>
      Parameters:
      value - the new value