Interface HasTextSelection
- All Superinterfaces:
HasElement,Serializable
- All Known Implementing Classes:
BigDecimalField,PasswordField,TextArea,TextField
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 ClassesModifier and TypeInterfaceDescriptionstatic interfaceFor internal use only. -
Method Summary
Modifier and TypeMethodDescriptiondefault voidSelects the entire current value and focuses the field.default voidsetCursorPosition(int position) Moves the cursor to the given position, collapsing any current selection, and focuses the field.default voidsetSelectionRange(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 == selectionEndcollapses the selection and moves the cursor to that position.Indices outside the current value are clamped by the browser; passing
0, Integer.MAX_VALUEtherefore 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, inclusiveselectionEnd- 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 tosetSelectionRange(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
-