Class DecimalSlider

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

@Tag("vaadin-slider") @NpmPackage(value="@vaadin/slider", version="25.2.0-beta1") @JsModule("@vaadin/slider/src/vaadin-slider.js") public class DecimalSlider extends AbstractSinglePropertyField<DecimalSlider,Double>
DecimalSlider is an input field that allows the user to select a decimal value within a range by dragging a handle along a track or using arrow keys for precise input.

DecimalSlider uses Double as the value type, see IntegerSlider for a version of the component that supports integer values.

Author:
Vaadin Ltd.
See Also:
  • Constructor Details

    • DecimalSlider

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

      The step defaults to 1.

    • DecimalSlider

      public DecimalSlider(double min, double max)
      Constructs a DecimalSlider 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
    • DecimalSlider

      public DecimalSlider(String label)
      Constructs a DecimalSlider 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
    • DecimalSlider

      public DecimalSlider(String label, double min, double max)
      Constructs a DecimalSlider 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
    • clear

      public void clear()
      Clears the slider value, setting it to the minimum value.
      Specified by:
      clear in interface HasValue<TComponent extends com.vaadin.flow.component.slider.NumberSlider<TComponent,TValue>,TValue extends Number>
      See Also:
    • isValueWithinMinMax

      protected boolean isValueWithinMinMax(Double value)
    • isValueAlignedWithStep

      protected boolean isValueAlignedWithStep(Double value)
    • 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
    • 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(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,TNumber,TPresentation>,TValue>
      Overrides:
      setValue in class AbstractField<TComponent extends com.vaadin.flow.component.slider.SliderBase<TComponent,TValue,TNumber,TPresentation>,TValue>
      Parameters:
      value - the new value
    • 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<TComponent extends com.vaadin.flow.component.slider.SliderBase<TComponent,TValue,TNumber,TPresentation>,TValue>
      Returns:
      true if the element property value can be converted to the model type; otherwise false