Class ComboBox<T>

  • Type Parameters:
    T - the type of the items to be selectable from the combo box
    All Implemented Interfaces:
    com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.BlurNotifier<ComboBox<T>>, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.Focusable<ComboBox<T>>, com.vaadin.flow.component.FocusNotifier<ComboBox<T>>, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasHelper, com.vaadin.flow.component.HasLabel, 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<ComboBox<T>,​T>,​T>, com.vaadin.flow.component.HasValueAndElement<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ComboBox<T>,​T>,​T>, HasAllowedCharPattern, HasClearButton, HasThemeVariant<ComboBoxVariant>, HasTooltip, com.vaadin.flow.data.binder.HasValidator<T>, com.vaadin.flow.data.provider.HasDataView<T,​String,​ComboBoxDataView<T>>, com.vaadin.flow.data.provider.HasLazyDataView<T,​String,​ComboBoxLazyDataView<T>>, com.vaadin.flow.data.provider.HasListDataView<T,​ComboBoxListDataView<T>>, Serializable

    @Tag("vaadin-combo-box")
    @NpmPackage(value="@vaadin/polymer-legacy-adapter",version="23.4.0") @NpmPackage(value="@vaadin/combo-box",version="23.4.0") @NpmPackage(value="@vaadin/vaadin-combo-box",version="23.4.0")
    @JsModule("@vaadin/polymer-legacy-adapter/style-modules.js") @JsModule("@vaadin/combo-box/src/vaadin-combo-box.js") @JsModule("@vaadin/polymer-legacy-adapter/template-renderer.js") @JsModule("./flow-component-renderer.js") @JsModule("./comboBoxConnector.js")
    public class ComboBox<T>
    extends ComboBoxBase<ComboBox<T>,​T,​T>
    implements HasThemeVariant<ComboBoxVariant>
    Combo Box allows the user to choose a value from a filterable list of options presented in an overlay.

    ComboBox supports lazy loading. This means that when using large data sets, items are requested from the server one "page" at a time when the user scrolls down the overlay. The number of items in one page is by default 50, and can be changed with ComboBoxBase.setPageSize(int).

    ComboBox can do filtering either in the browser or in the server. When ComboBox has only a relatively small set of items, the filtering will happen in the browser, allowing smooth user-experience. When the size of the data set is larger than the pageSize, the webcomponent doesn't necessarily have all the data available, and it will make requests to the server to handle the filtering. Also, if you have defined custom filtering logic, with eg. ComboBoxBase.setItems(ItemFilter, Collection), filtering will happen in the server. To enable client-side filtering with larger data sets, you can override the pageSize to be bigger than the size of your data set. However, then the full data set will be sent to the client immediately, and you will lose the benefits of lazy loading.

    Author:
    Vaadin Ltd
    See Also:
    Serialized Form
    • Constructor Detail

      • ComboBox

        public ComboBox​(int pageSize)
        Creates an empty combo box with the defined page size for lazy loading.

        The default page size is 50.

        The page size is also the largest number of items that can support client-side filtering. If you provide more items than the page size, the component has to fall back to server-side filtering.

        Parameters:
        pageSize - the amount of items to request at a time for lazy loading
        See Also:
        ComboBoxBase.setPageSize(int)
      • ComboBox

        public ComboBox()
        Default constructor. Creates an empty combo box.
      • ComboBox

        public ComboBox​(String label)
        Creates an empty combo box with the defined label.
        Parameters:
        label - the label describing the combo box
        See Also:
        HasLabel.setLabel(String)
      • ComboBox

        public ComboBox​(String label,
                        Collection<T> items)
        Creates a combo box with the defined label and populated with the items in the collection.
        Parameters:
        label - the label describing the combo box
        items - the items to be shown in the list of the combo box
        See Also:
        HasLabel.setLabel(String), ComboBoxBase.setItems(Collection)
      • ComboBox

        @SafeVarargs
        public ComboBox​(String label,
                        T... items)
        Creates a combo box with the defined label and populated with the items in the array.
        Parameters:
        label - the label describing the combo box
        items - the items to be shown in the list of the combo box
        See Also:
        HasLabel.setLabel(String), HasListDataView.setItems(Object...)
      • ComboBox

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

        public ComboBox​(String label,
                        com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ComboBox<T>,​T>> listener)
        Constructs a combo box with the defined label and a value change listener.
        Parameters:
        label - the label describing the combo box
        listener - the value change listener to add
        See Also:
        HasLabel.setLabel(String), AbstractField.addValueChangeListener(ValueChangeListener)
      • ComboBox

        @SafeVarargs
        public ComboBox​(String label,
                        com.vaadin.flow.component.HasValue.ValueChangeListener<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ComboBox<T>,​T>> listener,
                        T... items)
        Constructs a combo box with the defined label, a value change listener and populated with the items in the array.
        Parameters:
        label - the label describing the combo box
        listener - the value change listener to add
        items - the items to be shown in the list of the combo box
        See Also:
        HasLabel.setLabel(String), AbstractField.addValueChangeListener(ValueChangeListener), HasListDataView.setItems(Object...)
    • Method Detail

      • isPreventInvalidInput

        @Deprecated
        public boolean isPreventInvalidInput()
        Deprecated.
        Since 23.2, this API is deprecated.
        Whether the component should block user input that does not match the configured pattern
        Returns:
        true if the component should block user input that does not match the configured pattern, false otherwise
      • setPreventInvalidInput

        @Deprecated
        public void setPreventInvalidInput​(boolean preventInvalidInput)
        Deprecated.
        Since 23.2, this API is deprecated in favor of HasAllowedCharPattern.setAllowedCharPattern(String)
        Sets whether the component should block user input that does not match the configured pattern
        Parameters:
        preventInvalidInput - true if the component should block user input that does not match the configured pattern, false otherwise
      • getPattern

        public String getPattern()
        The pattern to validate the input with
        Returns:
        the pattern to validate the input with
      • setPattern

        public void setPattern​(String pattern)
        Sets the pattern with which to validate the input
        Parameters:
        pattern - the pattern to validate the input with
      • refreshValue

        protected void refreshValue()
        Description copied from class: ComboBoxBase
        Refresh value / selection of the web component after changes that might affect the presentation / rendering of items
        Specified by:
        refreshValue in class ComboBoxBase<ComboBox<T>,​T,​T>
      • isSelected

        protected boolean isSelected​(T item)
        Description copied from class: ComboBoxBase
        Whether the item is currently selected in the combo box.
        Specified by:
        isSelected in class ComboBoxBase<ComboBox<T>,​T,​T>
        Parameters:
        item - the item to check
        Returns:
        true if the item is selected, false otherwise
      • getEmptyValue

        public T getEmptyValue()
        Specified by:
        getEmptyValue in interface com.vaadin.flow.component.HasValue<com.vaadin.flow.component.AbstractField.ComponentValueChangeEvent<ComboBox<T>,​T>,​T>
        Overrides:
        getEmptyValue in class com.vaadin.flow.component.AbstractField<ComboBox<T>,​T>
      • addToPrefix

        @Deprecated
        protected void addToPrefix​(com.vaadin.flow.component.Component... components)
        Deprecated.
        since v23.3
        Adds the given components as children of this component at the slot 'prefix'.
        Parameters:
        components - The components to add.
        See Also:
        MDN page about slots, Spec website about slots
      • remove

        @Deprecated
        protected void remove​(com.vaadin.flow.component.Component... components)
        Deprecated.
        since v23.3
        Removes the given child components from this component.
        Parameters:
        components - The components to remove.
        Throws:
        IllegalArgumentException - if any of the components is not a child of this component.
      • removeAll

        @Deprecated
        protected void removeAll()
        Deprecated.
        since v23.3
        Removes all contents from this component, this includes child components, text content as well as child elements that have been added directly to this component using the Element API.