Class Slider

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

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

    • Slider

      public Slider()
      Constructs a Slider with min 0 and max 100. The initial value is 0.

      The step defaults to 1.

    • Slider

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

      The step defaults to 1.

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

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

      The step defaults to 1.

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

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

      The step defaults to 1.

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

    • setAriaLabel

      public void setAriaLabel(String ariaLabel)
      Sets an accessible name for the range input element of the slider.
      Specified by:
      setAriaLabel in interface HasAriaLabel
      Parameters:
      ariaLabel - the accessible name to set, or null to remove it
    • getAriaLabel

      public Optional<String> getAriaLabel()
      Gets the accessible name for the range input element of the slider.
      Specified by:
      getAriaLabel in interface HasAriaLabel
      Returns:
      an optional accessible name, or an empty optional if no accessible name has been set
    • setAriaLabelledBy

      public void setAriaLabelledBy(String ariaLabelledBy)
      Sets the id of an element to be used as the accessible name for the range input element of the slider.
      Specified by:
      setAriaLabelledBy in interface HasAriaLabel
      Parameters:
      ariaLabelledBy - the id of the element to be used as the label, or null to remove it
    • getAriaLabelledBy

      public Optional<String> getAriaLabelledBy()
      Gets the id of the element used as the accessible name for the range input element of the slider.
      Specified by:
      getAriaLabelledBy in interface HasAriaLabel
      Returns:
      an optional id of the element used as the label, or an empty optional if no id 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 minimum value.
      Specified by:
      clear in interface HasValue<AbstractField.ComponentValueChangeEvent<Slider,Double>,Double>
      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<Slider,Double>
      Returns:
      true if the element property value can be converted to the model type; otherwise false
    • isValueWithinMinMax

      protected boolean isValueWithinMinMax(Double value)
    • isValueAlignedWithStep

      protected boolean isValueAlignedWithStep(Double 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
    • 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(Double 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