Interface HasTextSelection

All Superinterfaces:
com.vaadin.flow.component.HasElement, Serializable

public interface HasTextSelection extends com.vaadin.flow.component.HasElement
Mixin interface for field components that wrap a native HTML input and support programmatic control of the text selection.

The methods mirror HTMLInputElement.setSelectionRange() / selectionStart / selectionEnd: indices are zero-based, with selectionStart the index of the first selected character and selectionEnd the index after the last selected character.

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static interface 
    For internal use only.
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Selects the entire current value and focuses the field.
    default void
    setCursorPosition(int position)
    Moves the cursor to the given position, collapsing any current selection, and focuses the field.
    default void
    setSelectionRange(int selectionStart, int selectionEnd)
    Sets the text selection to the range [selectionStart, selectionEnd) and focuses the field.

    Methods inherited from interface com.vaadin.flow.component.HasElement

    getElement
  • Method Details

    • setSelectionRange

      default void setSelectionRange(int selectionStart, int selectionEnd)
      Sets the text selection to the range [selectionStart, selectionEnd) and focuses the field. selectionStart == selectionEnd collapses the selection and moves the cursor to that position.

      Indices outside the current value are clamped by the browser; passing 0, Integer.MAX_VALUE therefore selects the whole value.

      Text selection depends on native browser behavior, which differs between browsers and platforms. On mobile devices in particular, focusing the field programmatically may not work.

      Parameters:
      selectionStart - the index of the first selected character, inclusive
      selectionEnd - the index after the last selected character, exclusive
    • selectAll

      default void selectAll()
      Selects the entire current value and focuses the field.

      Text selection depends on native browser behavior, which differs between browsers and platforms. On mobile devices in particular, focusing the field programmatically may not work.

    • setCursorPosition

      default void setCursorPosition(int position)
      Moves the cursor to the given position, collapsing any current selection, and focuses the field. Equivalent to setSelectionRange(position, position).

      Text selection depends on native browser behavior, which differs between browsers and platforms. On mobile devices in particular, focusing the field programmatically may not work.

      Parameters:
      position - the cursor position, zero-based