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.0-alpha7") @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, max 100, and initial value [0, 100].

      The step defaults to 1.

    • RangeSlider

      Constructs a RangeSlider with min 0, max 100, initial value [0, 100], and a value change listener.

      The step defaults to 1.

      Parameters:
      listener - the value change listener
    • RangeSlider

      public RangeSlider(double min, double max, RangeSliderValue value)
      Constructs a RangeSlider with the given min, max, and initial value.

      The step defaults to 1.

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

      public RangeSlider(double min, double max, RangeSliderValue value, HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<RangeSlider,RangeSliderValue>> listener)
      Constructs a RangeSlider with the given min, max, initial value, and a value change listener.

      The step defaults to 1.

      Parameters:
      min - the minimum value
      max - the maximum value
      value - the initial value
      listener - the value change listener
    • RangeSlider

      public RangeSlider(double min, double max, double step, RangeSliderValue value)
      Constructs a RangeSlider with the given min, max, step, and initial value.
      Parameters:
      min - the minimum value
      max - the maximum value
      step - the step value
      value - the initial value
    • RangeSlider

      public RangeSlider(double min, double max, double step, RangeSliderValue value, HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<RangeSlider,RangeSliderValue>> listener)
      Constructs a RangeSlider with the given min, max, step, initial value, and a value change listener.
      Parameters:
      min - the minimum value
      max - the maximum value
      step - the step value
      value - the initial value
      listener - the value change listener
    • RangeSlider

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

      The step defaults to 1.

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

      Constructs a RangeSlider with the given label, min 0, max 100, initial value [0, 100], and a value change listener.

      The step defaults to 1.

      Parameters:
      label - the text to set as the label
      listener - the value change listener
    • RangeSlider

      public RangeSlider(String label, double min, double max, RangeSliderValue value)
      Constructs a RangeSlider with the given label, min, max, and initial value.

      The step defaults to 1.

      Parameters:
      label - the text to set as the label
      min - the minimum value
      max - the maximum value
      value - the initial value
    • RangeSlider

      public RangeSlider(String label, double min, double max, RangeSliderValue value, HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<RangeSlider,RangeSliderValue>> listener)
      Constructs a RangeSlider with the given label, min, max, initial value, and a value change listener.

      The step defaults to 1.

      Parameters:
      label - the text to set as the label
      min - the minimum value
      max - the maximum value
      value - the initial value
      listener - the value change listener
    • RangeSlider

      public RangeSlider(String label, double min, double max, double step, RangeSliderValue value)
      Constructs a RangeSlider with the given label, min, max, step, and initial value.
      Parameters:
      label - the text to set as the label
      min - the minimum value
      max - the maximum value
      step - the step value
      value - the initial value
    • RangeSlider

      public RangeSlider(String label, double min, double max, double step, RangeSliderValue value, HasValue.ValueChangeListener<? super AbstractField.ComponentValueChangeEvent<RangeSlider,RangeSliderValue>> listener)
      Constructs a RangeSlider with the given label, min, max, step, initial value, and a value change listener.
      Parameters:
      label - the text to set as the label
      min - the minimum value
      max - the maximum value
      step - the step value
      value - the initial value
      listener - the value change listener
  • 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.

      This method automatically clamps both the current start and end values to be no less than the new minimum, which may trigger a value change event. To set the value explicitly along with the new minimum, use the

      invalid reference
      setValue(value, min,
       max)
      method instead.
      Parameters:
      min - the minimum value
      Throws:
      IllegalArgumentException - if min is greater than the current max
    • 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.

      This method automatically clamps both the current start and end values to be no greater than the new maximum, which may trigger a value change event. To set the value explicitly along with the new maximum, use the

      invalid reference
      setValue(value, min,
       max)
      method instead.
      Parameters:
      max - the maximum value
      Throws:
      IllegalArgumentException - if max is less than the current min
    • 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.

      This method automatically adjusts both the current start and end values to be aligned with the new step, which may trigger a value change event. To set the value explicitly along with the new step, use the

      invalid reference
      setValue(value, min, max, step)
      method instead.
      Parameters:
      step - the step value
      Throws:
      IllegalArgumentException - if step is not positive
    • 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
    • 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
    • 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
    • setValue

      public void setValue(RangeSliderValue value)
      Sets the value of the slider.
      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 value
      Throws:
      IllegalArgumentException - if value is not valid for the current min, max and step
    • setValue

      public void setValue(RangeSliderValue value, double min, double max)
      Sets the minimum, maximum, and value of the slider atomically.

      The step remains unchanged.

      Parameters:
      value - the value
      min - the minimum value
      max - the maximum value
      Throws:
      IllegalArgumentException - if min is greater than max
      IllegalArgumentException - if value is not valid for the given min, max and current step
    • setValue

      public void setValue(RangeSliderValue value, double min, double max, double step)
      Sets the minimum, maximum, step, and value of the slider atomically.
      Parameters:
      value - the value
      min - the minimum value
      max - the maximum value
      step - the step value
      Throws:
      IllegalArgumentException - if min is greater than max
      IllegalArgumentException - if step is not positive
      IllegalArgumentException - if value is not valid for the given min, max and step
    • 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.