Class Select<T>

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.AbstractField<C,T>
com.vaadin.flow.component.AbstractSinglePropertyField<Select<T>,T>
com.vaadin.flow.component.select.Select<T>
Type Parameters:
T - the type of the items for the select
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<Select<T>>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<Select<T>>, com.vaadin.flow.component.FocusNotifier<Select<T>>, com.vaadin.flow.component.HasAriaLabel, com.vaadin.flow.component.HasComponents, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasHelper, com.vaadin.flow.component.HasLabel, com.vaadin.flow.component.HasPlaceholder, com.vaadin.flow.component.HasSize, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.HasTheme, com.vaadin.flow.component.HasValidation, com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Select<T>,T>,T>, com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Select<T>,T>,T>, HasClientValidation, HasOverlayClassName, HasPrefix, HasThemeVariant<SelectVariant>, HasTooltip, HasValidationProperties, InputField<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Select<T>,T>,T>, com.vaadin.flow.data.binder.HasItemComponents<T>, com.vaadin.flow.data.binder.HasValidator<T>, com.vaadin.flow.data.provider.HasDataView<T,Void,SelectDataView<T>>, com.vaadin.flow.data.provider.HasListDataView<T,SelectListDataView<T>>, com.vaadin.flow.data.selection.SingleSelect<Select<T>,T>, Serializable

@Tag("vaadin-select") @NpmPackage(value="@vaadin/polymer-legacy-adapter",version="24.7.12") @NpmPackage(value="@vaadin/select",version="24.7.12") @JsModule("@vaadin/polymer-legacy-adapter/style-modules.js") @JsModule("@vaadin/select/src/vaadin-select.js") @JsModule("./selectConnector.js") public class Select<T> extends com.vaadin.flow.component.AbstractSinglePropertyField<Select<T>,T> implements com.vaadin.flow.component.Focusable<Select<T>>, com.vaadin.flow.component.HasAriaLabel, HasClientValidation, com.vaadin.flow.data.provider.HasDataView<T,Void,SelectDataView<T>>, com.vaadin.flow.data.binder.HasItemComponents<T>, InputField<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Select<T>,T>,T>, com.vaadin.flow.data.provider.HasListDataView<T,SelectListDataView<T>>, HasOverlayClassName, HasPrefix, HasThemeVariant<SelectVariant>, HasValidationProperties, com.vaadin.flow.data.binder.HasValidator<T>, com.vaadin.flow.data.selection.SingleSelect<Select<T>,T>, com.vaadin.flow.component.HasPlaceholder
Select allows users to choose a single value from a list of options presented in an overlay. The dropdown can be opened with a click, up/down arrow keys, or by typing the initial character for one of the options.

Validation

Select comes with a built-in validation mechanism that verifies that the field is not empty when required is enabled.

Validation is triggered whenever the user initiates a value change, for example by selecting an item from the dropdown. Programmatic value changes trigger validation as well. If validation fails, the component is marked as invalid and an error message is displayed below the input.

The required error message can be configured using either Select.SelectI18n.setRequiredErrorMessage(String) or HasValidationProperties.setErrorMessage(String).

For more advanced validation that requires custom rules, you can use Binder. Please note that Binder provides its own API for the required validation, see asRequired().

However, if Binder doesn't fit your needs and you want to implement fully custom validation logic, you can disable the built-in validation by setting setManualValidation(boolean) to true. This will allow you to control the invalid state and the error message manually using HasValidationProperties.setInvalid(boolean) and HasValidationProperties.setErrorMessage(String) API.

Author:
Vaadin Ltd.
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    invalid-changed event is sent when the invalid state changes.
    static class 
    opened-changed event is sent when the overlay opened state changes.
    static class 
    The internationalization properties for Select.

    Nested classes/interfaces inherited from class com.vaadin.flow.component.AbstractField

    com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<C extends com.vaadin.flow.component.Component,V extends Object>

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.BlurNotifier

    com.vaadin.flow.component.BlurNotifier.BlurEvent<C extends com.vaadin.flow.component.Component>

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.FocusNotifier

    com.vaadin.flow.component.FocusNotifier.FocusEvent<C extends com.vaadin.flow.component.Component>

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.shared.HasClientValidation

    HasClientValidation.ClientValidatedEvent

    Nested classes/interfaces inherited from interface com.vaadin.flow.data.binder.HasItemComponents

    com.vaadin.flow.data.binder.HasItemComponents.ItemComponent<T extends Object>

    Nested classes/interfaces inherited from interface com.vaadin.flow.component.HasValue

    com.vaadin.flow.component.HasValue.ValueChangeEvent<V extends Object>, com.vaadin.flow.component.HasValue.ValueChangeListener<E extends com.vaadin.flow.component.HasValue.ValueChangeEvent<?>>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a select.
    Select(com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Select<T>,T>> listener)
    Constructs a select with the initial value change listener.
    Select(String label, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Select<T>,T>> listener)
    Constructs a select with the initial label text and value change listener.
    Select(String label, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Select<T>,T>> listener, T... items)
    Constructs a select with the initial label text and value change listener.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(com.vaadin.flow.component.Component... components)
    void
    addComponentAsFirst(com.vaadin.flow.component.Component component)
    void
    addComponentAtIndex(int index, com.vaadin.flow.component.Component component)
    void
    addComponents(T afterItem, com.vaadin.flow.component.Component... components)
     
    protected com.vaadin.flow.shared.Registration
    addInvalidChangeListener(com.vaadin.flow.component.ComponentEventListener<Select.InvalidChangeEvent> listener)
    Adds a listener for invalid-changed events fired by the webcomponent.
    protected com.vaadin.flow.shared.Registration
    addOpenedChangeListener(com.vaadin.flow.component.ComponentEventListener<Select.OpenedChangeEvent> listener)
    Adds a listener for opened-changed events fired by the webcomponent.
     
     
    Stream<com.vaadin.flow.component.Component>
     
    com.vaadin.flow.data.provider.DataProvider<T,?>
    Gets the data provider used by this Select.
    com.vaadin.flow.data.binder.Validator<T>
     
     
    Gets the generic data view for the Select.
    Gets the internationalization object previously set for this component.
    com.vaadin.flow.function.SerializablePredicate<T>
    Returns the item enabled predicate.
    com.vaadin.flow.component.ItemLabelGenerator<T>
    Gets the item label generator.
    int
     
    ComponentRenderer<? extends com.vaadin.flow.component.Component,T>
    Returns the item component renderer.
    Gets the string for the label element.
    Gets the list data view for the Select.
    protected boolean
     
    boolean
    Gets whether this select has been set to autofocus when the page loads.
    boolean
    Returns whether the user is allowed to select nothing.
    boolean
    Returns whether the overlay should overlap the input element
    protected boolean
    Whether the dropdown is opened or not.
    boolean
    Gets whether the user is required to provide a value.
    protected void
    onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
     
    void
    onEnabledStateChanged(boolean enabled)
     
    void
    prependComponents(T beforeItem, com.vaadin.flow.component.Component... components)
     
    void
    remove(com.vaadin.flow.component.Component... components)
    Removes the given child components from this component.
    void
    Removes all child components that are not items.
    void
    setAriaLabel(String ariaLabel)
     
    void
    setAriaLabelledBy(String ariaLabelledBy)
     
    void
    setAutofocus(boolean autofocus)
    Sets the select to have focus when the page loads.
    void
    setDataProvider(com.vaadin.flow.data.provider.DataProvider<T,?> dataProvider)
    Sets a generic data provider for the Select to use.
    void
    setEmptySelectionAllowed(boolean emptySelectionAllowed)
    Sets whether the user is allowed to select nothing.
    void
    setEmptySelectionCaption(String emptySelectionCaption)
    Sets the empty selection caption when setEmptySelectionAllowed(boolean) has been enabled.
    void
    Sets the internationalization object for this component.
    void
    setItemEnabledProvider(com.vaadin.flow.function.SerializablePredicate<T> itemEnabledProvider)
    Sets the item enabled predicate for this select.
    void
    setItemLabelGenerator(com.vaadin.flow.component.ItemLabelGenerator<T> itemLabelGenerator)
    Sets the item label generator.
    setItems(com.vaadin.flow.data.provider.DataProvider<T,Void> dataProvider)
     
    setItems(com.vaadin.flow.data.provider.InMemoryDataProvider<T> inMemoryDataProvider)
     
    setItems(com.vaadin.flow.data.provider.ListDataProvider<T> dataProvider)
     
    void
    Sets the string for the label element.
    void
    setManualValidation(boolean enabled)
     
    void
    setNoVerticalOverlap(boolean noVerticalOverlap)
    Defines whether the overlay should overlap the input element in the y-axis, or be positioned right above/below it.
    protected void
    setOpened(boolean opened)
    Set true to open the dropdown overlay.
    void
    setOverlayWidth(float width, com.vaadin.flow.component.Unit unit)
    Sets the dropdown overlay width.
    void
    Sets the dropdown overlay width.
    void
    setPlaceholder(String placeholder)
    Sets the placeholder hint for the user.
    void
    setRenderer(ComponentRenderer<? extends com.vaadin.flow.component.Component,T> renderer)
    Sets the item renderer for this select group.
    void
    setRequiredIndicatorVisible(boolean required)
    Sets whether the user is required to provide a value.
    void
    setTextRenderer(com.vaadin.flow.component.ItemLabelGenerator<T> itemLabelGenerator)
    Convenience setter for creating a TextRenderer from the given function that converts the item to a string.
    protected void
    Validates the current value against the constraints and sets the invalid property and the errorMessage property based on the result.
    protected boolean
    valueEquals(T value1, T value2)
    Compares two value instances to each other to determine whether they are equal.

    Methods inherited from class com.vaadin.flow.component.AbstractSinglePropertyField

    getSynchronizationRegistration, setPresentationValue, setSynchronizedEvent

    Methods inherited from class com.vaadin.flow.component.AbstractField

    addValueChangeListener, getEmptyValue, getValue, isEmpty, setModelValue, setValue

    Methods inherited from class com.vaadin.flow.component.Component

    addListener, findAncestor, fireEvent, from, get, getElement, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onDetach, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisible

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

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

    addAttachListener

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

    addBlurListener

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

    addDetachListener

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

    addFocusShortcut, blur, focus, getTabIndex, setTabIndex

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

    addFocusListener

    Methods inherited from interface com.vaadin.flow.component.shared.HasClientValidation

    addClientValidatedEventListener

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

    add, add, remove

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

    getElement

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

    isEnabled, setEnabled

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

    getHelperComponent, getHelperText, setHelperComponent, setHelperText

    Methods inherited from interface com.vaadin.flow.data.provider.HasListDataView

    setItems, setItems

    Methods inherited from interface com.vaadin.flow.component.shared.HasOverlayClassName

    getOverlayClassName, setOverlayClassName

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

    getPlaceholder

    Methods inherited from interface com.vaadin.flow.component.shared.HasPrefix

    getPrefixComponent, setPrefixComponent

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

    getHeight, getHeightUnit, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getWidth, getWidthUnit, setHeight, setHeight, setHeightFull, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull

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

    addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName

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

    addThemeName, addThemeNames, getThemeName, getThemeNames, hasThemeName, removeThemeName, removeThemeNames, setThemeName, setThemeName

    Methods inherited from interface com.vaadin.flow.component.shared.HasThemeVariant

    addThemeVariants, removeThemeVariants

    Methods inherited from interface com.vaadin.flow.component.shared.HasTooltip

    getTooltip, setTooltipText

    Methods inherited from interface com.vaadin.flow.component.shared.HasValidationProperties

    getErrorMessage, isInvalid, setErrorMessage, setInvalid

    Methods inherited from interface com.vaadin.flow.data.binder.HasValidator

    addValidationStatusChangeListener

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

    addValueChangeListener, clear, getEmptyValue, getOptionalValue, getValue, isEmpty, setValue

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

    isReadOnly, setReadOnly
  • Field Details

  • Constructor Details

    • Select

      public Select()
      Constructs a select.
    • Select

      public Select(com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Select<T>,T>> listener)
      Constructs a select with the initial value change listener.
      Parameters:
      listener - the value change listener to add
      See Also:
      • AbstractField.addValueChangeListener(ValueChangeListener)
    • Select

      public Select(String label, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Select<T>,T>> listener)
      Constructs a select with the initial label text and value change listener.
      Parameters:
      label - the label describing the select
      listener - the value change listener to add
      See Also:
    • Select

      @SafeVarargs public Select(String label, com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Select<T>,T>> listener, T... items)
      Constructs a select with the initial label text and value change listener.
      Parameters:
      label - the label describing the select
      listener - the value change listener to add
      items - the items to be shown in the list of the select
      See Also:
      • setLabel(String)
      • HasListDataView.setItems(Object...)
      • AbstractField.addValueChangeListener(ValueChangeListener)
  • Method Details

    • getItemRenderer

      public ComponentRenderer<? extends com.vaadin.flow.component.Component,T> getItemRenderer()
      Returns the item component renderer.
      Returns:
      the item renderer or null if none set
      See Also:
    • setRenderer

      public void setRenderer(ComponentRenderer<? extends com.vaadin.flow.component.Component,T> renderer)
      Sets the item renderer for this select group. The renderer is applied to each item to create a component which represents the item option in the select's drop down.

      Default is null which means that the item's Object.toString() method is used and set as the text content of the vaadin item element.

      Parameters:
      renderer - the item renderer, or null to clear
    • setTextRenderer

      public void setTextRenderer(com.vaadin.flow.component.ItemLabelGenerator<T> itemLabelGenerator)
      Convenience setter for creating a TextRenderer from the given function that converts the item to a string.

      NOTE: even though this accepts an ItemLabelGenerator, this is not the same as setItemLabelGenerator(ItemLabelGenerator) which does a different thing.

      Parameters:
      itemLabelGenerator - the function that creates the text content from the item, not null
    • setEmptySelectionAllowed

      public void setEmptySelectionAllowed(boolean emptySelectionAllowed)
      Sets whether the user is allowed to select nothing. When set true a special empty item is shown to the user.

      Default is false. The empty selection item can be customized with setEmptySelectionCaption(String).

      Parameters:
      emptySelectionAllowed - true to allow not selecting anything, false to require selection
      See Also:
    • isEmptySelectionAllowed

      public boolean isEmptySelectionAllowed()
      Returns whether the user is allowed to select nothing.
      Returns:
      true if empty selection is allowed, false otherwise
    • setEmptySelectionCaption

      public void setEmptySelectionCaption(String emptySelectionCaption)
      Sets the empty selection caption when setEmptySelectionAllowed(boolean) has been enabled. The caption is shown for the empty selection item in the drop down.

      When the empty selection item is selected, the select shows the value provided by setItemLabelGenerator(ItemLabelGenerator) for the null item, or the string set with setPlaceholder(String) or an empty string if not placeholder is set.

      Default is an empty string "", which will show the place holder when selected.

      Parameters:
      emptySelectionCaption - the empty selection caption to set, not null
      See Also:
    • getEmptySelectionCaption

      public String getEmptySelectionCaption()
    • getItemEnabledProvider

      public com.vaadin.flow.function.SerializablePredicate<T> getItemEnabledProvider()
      Returns the item enabled predicate.
      Returns:
      the item enabled predicate or null if not set
      See Also:
    • setItemEnabledProvider

      public void setItemEnabledProvider(com.vaadin.flow.function.SerializablePredicate<T> itemEnabledProvider)
      Sets the item enabled predicate for this select. The predicate is applied to each item to determine whether the item should be enabled (true) or disabled (false). Disabled items are displayed as grayed out and the user cannot select them.

      By default is null and all the items are enabled.

      Parameters:
      itemEnabledProvider - the item enable predicate or null to clear
    • getItemLabelGenerator

      public com.vaadin.flow.component.ItemLabelGenerator<T> getItemLabelGenerator()
      Gets the item label generator. It generates the text that is shown in the input part for the item when it has been selected.

      Default is null.

      Returns:
      the item label generator, null if not set
    • setItemLabelGenerator

      public void setItemLabelGenerator(com.vaadin.flow.component.ItemLabelGenerator<T> itemLabelGenerator)
      Sets the item label generator. It generates the text that is shown in the input part for the item when it has been selected.

      Default is null and the text content generated for the item with setRenderer(ComponentRenderer) is used instead.

      Parameters:
      itemLabelGenerator - the item label generator to set, or null to clear
    • setPlaceholder

      public void setPlaceholder(String placeholder)
      Sets the placeholder hint for the user.

      The placeholder will be displayed in the case that there is no item selected, or the selected item has an empty string label, or the selected item has no label and it's DOM content is empty.

      Default value is null.

      Specified by:
      setPlaceholder in interface com.vaadin.flow.component.HasPlaceholder
      Parameters:
      placeholder - the placeholder to set, or null to remove
    • setLabel

      public void setLabel(String label)
      Sets the string for the label element.

      NOTE: the label must be set for the required indicator to be visible.

      Specified by:
      setLabel in interface com.vaadin.flow.component.HasLabel
      Parameters:
      label - string or null to clear it
    • getLabel

      public String getLabel()
      Gets the string for the label element.
      Specified by:
      getLabel in interface com.vaadin.flow.component.HasLabel
      Returns:
      the label string, or null if not set
    • setAriaLabel

      public void setAriaLabel(String ariaLabel)
      Specified by:
      setAriaLabel in interface com.vaadin.flow.component.HasAriaLabel
    • getAriaLabel

      public Optional<String> getAriaLabel()
      Specified by:
      getAriaLabel in interface com.vaadin.flow.component.HasAriaLabel
    • setAriaLabelledBy

      public void setAriaLabelledBy(String ariaLabelledBy)
      Specified by:
      setAriaLabelledBy in interface com.vaadin.flow.component.HasAriaLabel
    • getAriaLabelledBy

      public Optional<String> getAriaLabelledBy()
      Specified by:
      getAriaLabelledBy in interface com.vaadin.flow.component.HasAriaLabel
    • setAutofocus

      public void setAutofocus(boolean autofocus)
      Sets the select to have focus when the page loads.

      Default is false.

      Parameters:
      autofocus - the autofocus to set
    • isAutofocus

      public boolean isAutofocus()
      Gets whether this select has been set to autofocus when the page loads.
      Returns:
      true if set to autofocus, false if not
    • setNoVerticalOverlap

      public void setNoVerticalOverlap(boolean noVerticalOverlap)
      Defines whether the overlay should overlap the input element in the y-axis, or be positioned right above/below it.
      Parameters:
      noVerticalOverlap - whether the overlay should overlap the input element
    • isNoVerticalOverlap

      public boolean isNoVerticalOverlap()
      Returns whether the overlay should overlap the input element
      Returns:
      true if the overlay should overlap the input element, false otherwise
    • setDataProvider

      public void setDataProvider(com.vaadin.flow.data.provider.DataProvider<T,?> dataProvider)
      Sets a generic data provider for the Select to use.

      Use this method when none of the setItems methods are applicable, e.g. when having a data provider with filter that cannot be transformed to DataProvider<T, Void>.

      Parameters:
      dataProvider - DataProvider instance to use, not null
    • getDataProvider

      public com.vaadin.flow.data.provider.DataProvider<T,?> getDataProvider()
      Gets the data provider used by this Select.

      To get information and control over the items in the Select, use either getListDataView() or getGenericDataView() instead.

      Returns:
      the data provider used by this Select
    • setItems

      public SelectDataView<T> setItems(com.vaadin.flow.data.provider.DataProvider<T,Void> dataProvider)
      Specified by:
      setItems in interface com.vaadin.flow.data.provider.HasDataView<T,Void,SelectDataView<T>>
    • setItems

      public SelectDataView<T> setItems(com.vaadin.flow.data.provider.InMemoryDataProvider<T> inMemoryDataProvider)
      Specified by:
      setItems in interface com.vaadin.flow.data.provider.HasDataView<T,Void,SelectDataView<T>>
    • setItems

      public SelectListDataView<T> setItems(com.vaadin.flow.data.provider.ListDataProvider<T> dataProvider)
      Specified by:
      setItems in interface com.vaadin.flow.data.provider.HasListDataView<T,SelectListDataView<T>>
    • getGenericDataView

      public SelectDataView<T> getGenericDataView()
      Gets the generic data view for the Select. This data view should only be used when getListDataView() is not applicable for the underlying data provider.
      Specified by:
      getGenericDataView in interface com.vaadin.flow.data.provider.HasDataView<T,Void,SelectDataView<T>>
      Returns:
      the generic DataView instance implementing Select
    • getListDataView

      public SelectListDataView<T> getListDataView()
      Gets the list data view for the Select. This data view should only be used when the items are in-memory and set with: If the items are not in-memory, an exception is thrown.
      Specified by:
      getListDataView in interface com.vaadin.flow.data.provider.HasListDataView<T,SelectListDataView<T>>
      Returns:
      the list data view that provides access to the data bound to the Select
    • onEnabledStateChanged

      public void onEnabledStateChanged(boolean enabled)
      Overrides:
      onEnabledStateChanged in class com.vaadin.flow.component.Component
    • setRequiredIndicatorVisible

      public void setRequiredIndicatorVisible(boolean required)
      Sets whether the user is required to provide a value. When required, an indicator appears next to the label and the field invalidates if the value is cleared.

      NOTE: The required indicator is only visible when the field has a label, see setLabel(String).

      Specified by:
      setRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Select<T>,T>,T>
      Specified by:
      setRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Select<T>,T>,T>
      Parameters:
      required - true to make the field required, false otherwise
    • isRequiredIndicatorVisible

      public boolean isRequiredIndicatorVisible()
      Gets whether the user is required to provide a value.
      Specified by:
      isRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Select<T>,T>,T>
      Specified by:
      isRequiredIndicatorVisible in interface com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<Select<T>,T>,T>
      Returns:
      true if the field is required, false otherwise
      See Also:
    • add

      public void add(com.vaadin.flow.component.Component... components)

      NOTE: If you add a component with the slot attribute set, it will be placed in the light-dom of the vaadin-select instead of the dropdown.

      Specified by:
      add in interface com.vaadin.flow.component.HasComponents
    • addComponents

      public void addComponents(T afterItem, com.vaadin.flow.component.Component... components)
      Specified by:
      addComponents in interface com.vaadin.flow.data.binder.HasItemComponents<T>
    • prependComponents

      public void prependComponents(T beforeItem, com.vaadin.flow.component.Component... components)
      Specified by:
      prependComponents in interface com.vaadin.flow.data.binder.HasItemComponents<T>
    • getItemPosition

      public int getItemPosition(T item)
      Specified by:
      getItemPosition in interface com.vaadin.flow.data.binder.HasItemComponents<T>
    • addComponentAtIndex

      public void addComponentAtIndex(int index, com.vaadin.flow.component.Component component)

      NOTE: If you add a component with the slot attribute set, it will be placed in the light-dom of the vaadin-select instead of the dropdown.

      Specified by:
      addComponentAtIndex in interface com.vaadin.flow.component.HasComponents
    • addComponentAsFirst

      public void addComponentAsFirst(com.vaadin.flow.component.Component component)

      NOTE: If you add a component with the slot attribute set, it will be placed in the light-dom of the vaadin-select instead of the dropdown.

      Specified by:
      addComponentAsFirst in interface com.vaadin.flow.component.HasComponents
    • getChildren

      public Stream<com.vaadin.flow.component.Component> getChildren()
      Overrides:
      getChildren in class com.vaadin.flow.component.Component
    • remove

      public void remove(com.vaadin.flow.component.Component... components)
      Removes the given child components from this component.

      NOTE: any component with the slot attribute will be attempted to removed from the light dom of the vaadin-select, instead of inside the options drop down.

      Specified by:
      remove in interface com.vaadin.flow.component.HasComponents
      Parameters:
      components - the components to remove
      Throws:
      IllegalArgumentException - if any of the components is not a child of this component
    • removeAll

      public void removeAll()
      Removes all child components that are not items. To remove all items, reset the data provider or use HasListDataView.setItems(Object[]).

      NOTE: this will remove all non-items from the drop down and any slotted components from vaadin-select's light dom.

      Specified by:
      removeAll in interface com.vaadin.flow.component.HasComponents
      See Also:
      • HasComponents.removeAll()
    • setOverlayWidth

      public void setOverlayWidth(String width)
      Sets the dropdown overlay width.
      Parameters:
      width - the new dropdown width. Pass in null to set the dropdown width back to the default value.
    • setOverlayWidth

      public void setOverlayWidth(float width, com.vaadin.flow.component.Unit unit)
      Sets the dropdown overlay width. Negative number implies unspecified size (the dropdown width is reverted back to the default value).
      Parameters:
      width - the width of the dropdown.
      unit - the unit used for the dropdown.
    • setOpened

      protected void setOpened(boolean opened)
      Set true to open the dropdown overlay.
      Parameters:
      opened - the boolean value to set
    • isOpened

      @Synchronize(property="opened", value="opened-changed") protected boolean isOpened()
      Whether the dropdown is opened or not.
      Returns:
      true if the drop-down is opened, false otherwise
    • hasValidValue

      protected boolean hasValidValue()
      Overrides:
      hasValidValue in class com.vaadin.flow.component.AbstractSinglePropertyField<Select<T>,T>
    • onAttach

      protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
      Overrides:
      onAttach in class com.vaadin.flow.component.Component
    • valueEquals

      protected boolean valueEquals(T value1, T value2)
      Compares two value instances to each other to determine whether they are equal. Equality is used to determine whether to update internal state and fire an event when AbstractField.setValue(Object) or AbstractField.setModelValue(Object, boolean) is called. Subclasses can override this method to define an alternative comparison method instead of Object.equals(Object).
      Overrides:
      valueEquals in class com.vaadin.flow.component.AbstractField<Select<T>,T>
      Parameters:
      value1 - the first instance
      value2 - the second instance
      Returns:
      true if the instances are equal; otherwise false
    • setManualValidation

      public void setManualValidation(boolean enabled)
      Specified by:
      setManualValidation in interface com.vaadin.flow.component.HasValidation
    • getDefaultValidator

      public com.vaadin.flow.data.binder.Validator<T> getDefaultValidator()
      Specified by:
      getDefaultValidator in interface com.vaadin.flow.data.binder.HasValidator<T>
    • validate

      protected void validate()
      Validates the current value against the constraints and sets the invalid property and the errorMessage property based on the result. If a custom error message is provided with HasValidationProperties.setErrorMessage(String), it is used. Otherwise, the error message defined in the i18n object is used.

      The method does nothing if the manual validation mode is enabled.

    • addOpenedChangeListener

      protected com.vaadin.flow.shared.Registration addOpenedChangeListener(com.vaadin.flow.component.ComponentEventListener<Select.OpenedChangeEvent> listener)
      Adds a listener for opened-changed events fired by the webcomponent.
      Parameters:
      listener - the listener
      Returns:
      a Registration for removing the event listener
    • addInvalidChangeListener

      protected com.vaadin.flow.shared.Registration addInvalidChangeListener(com.vaadin.flow.component.ComponentEventListener<Select.InvalidChangeEvent> listener)
      Adds a listener for invalid-changed events fired by the webcomponent.
      Parameters:
      listener - the listener
      Returns:
      a Registration for removing the event listener
    • getI18n

      public Select.SelectI18n getI18n()
      Gets the internationalization object previously set for this component.

      NOTE: Updating the instance that is returned from this method will not update the component if not set again using setI18n(SelectI18n)

      Returns:
      the i18n object or null if no i18n object has been set
    • setI18n

      public void setI18n(Select.SelectI18n i18n)
      Sets the internationalization object for this component.
      Parameters:
      i18n - the i18n object, not null