All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.vaadin.flow.component.select.generated.GeneratedVaadinSelect Maven / Gradle / Ivy

There is a newer version: 24.6.0
Show newest version
/*
 * Copyright 2000-2022 Vaadin Ltd.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.vaadin.flow.component.select.generated;

import com.vaadin.flow.component.AbstractSinglePropertyField;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.ComponentEvent;
import com.vaadin.flow.component.ComponentEventListener;
import com.vaadin.flow.component.Focusable;
import com.vaadin.flow.component.HasStyle;
import com.vaadin.flow.component.NotSupported;
import com.vaadin.flow.component.Synchronize;
import com.vaadin.flow.component.Tag;
import com.vaadin.flow.component.dependency.HtmlImport;
import com.vaadin.flow.component.dependency.JsModule;
import com.vaadin.flow.component.dependency.NpmPackage;
import com.vaadin.flow.dom.Element;
import com.vaadin.flow.function.SerializableBiFunction;
import com.vaadin.flow.function.SerializableFunction;
import com.vaadin.flow.shared.Registration;

/**
 * 

* Description copied from corresponding location in WebComponent: *

*

* {@code } is a Web Component for selecting values from a list * of items. The content of the the select can be populated in two ways: * imperatively by using renderer callback function and declaratively by using * Polymer's Templates. *

*

Rendering

*

* By default, the select uses the content provided by using the renderer * callback function. *

*

* The renderer function provides {@code root}, {@code select} arguments. * Generate DOM content, append it to the {@code root} element and control the * state of the host element by accessing {@code select}. *

*

* <vaadin-select id="select"></vaadin-select> * {@code const select = document.querySelector('#select');select.renderer = * function(root, select) const listBox = * document.createElement('vaadin-list-box'); // append 3 elements * ['Jose', 'Manolo', 'Pedro'].forEach(function(name) { const item = * document.createElement('vaadin-item'); item.textContent = name; * listBox.appendChild(item); }); *

*

* // update the content root.appendChild(listBox); };} *

*

* Renderer is called on initialization of new select and on its opening. DOM * generated during the renderer call can be reused in the next renderer call * and will be provided with the {@code root} argument. On first call it will be * empty. *

*

Polymer Templates

*

* Alternatively, the content can be provided with Polymer's Template. Select * finds the first child template and uses that in case renderer callback * function is not provided. You can also set a custom template using the * {@code template} property. *

*

* {@code } *

*

* Hint: By setting the {@code label} property of inner vaadin-items you will be * able to change the visual representation of the selected value in the input * part. *

*

Styling

*

* The following shadow DOM parts are available for styling: *

* * * * * * * * * * * * *
Part nameDescription
{@code toggle-button}The toggle button
*

* The following state attributes are available for styling: *

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
AttributeDescriptionPart name
{@code opened}Set when the select is open:host
{@code invalid}Set when the element is invalid:host
{@code focused}Set when the element is focused:host
{@code focus-ring}Set when the element is keyboard focused:host
{@code readonly}Set when the select is read only:host
*

* {@code } element sets these custom CSS properties: *

* * * * * * * * * * * * * * *
Property nameDescriptionTheme for element
{@code --vaadin-select-text-field-width}Width of the select text field{@code vaadin-select-overlay}
*

* See * ThemableMixin * – how to apply styles for shadow parts *

*

* In addition to {@code } itself, the following internal * components are themable: *

*
    *
  • {@code }
  • *
  • {@code }
  • *
*

* Note: the {@code theme} attribute value set on {@code } is * propagated to the internal themable components listed above. *

*/ @Tag("vaadin-select") @HtmlImport("frontend://bower_components/vaadin-select/src/vaadin-select.html") @NpmPackage(value = "@vaadin/vaadin-select", version = "2.5.0") @JsModule("@vaadin/vaadin-select/src/vaadin-select.js") public abstract class GeneratedVaadinSelect, T> extends AbstractSinglePropertyField implements HasStyle, Focusable { /** *

* Description copied from corresponding location in WebComponent: *

*

* Specify that this control should have input focus when the page loads. *

* This property is not synchronized automatically from the client side, so * the returned value may not be the same as in client side. *

* * @return the {@code autofocus} property from the webcomponent */ protected boolean isAutofocusBoolean() { return getElement().getProperty("autofocus", false); } /** *

* Description copied from corresponding location in WebComponent: *

*

* Specify that this control should have input focus when the page loads. *

* * @param autofocus * the boolean value to set */ protected void setAutofocus(boolean autofocus) { getElement().setProperty("autofocus", autofocus); } /** *

* Description copied from corresponding location in WebComponent: *

*

* If true, the user cannot interact with this element. *

* This property is not synchronized automatically from the client side, so * the returned value may not be the same as in client side. *

* * @return the {@code disabled} property from the webcomponent */ protected boolean isDisabledBoolean() { return getElement().getProperty("disabled", false); } /** *

* Description copied from corresponding location in WebComponent: *

*

* If true, the user cannot interact with this element. *

* * @param disabled * the boolean value to set */ protected void setDisabled(boolean disabled) { getElement().setProperty("disabled", disabled); } /** *

* Description copied from corresponding location in WebComponent: *

*

* Set when the select is open *

* This property is synchronized automatically from client side when a * 'opened-changed' event happens. *

* * @return the {@code opened} property from the webcomponent */ @Synchronize(property = "opened", value = "opened-changed") protected boolean isOpenedBoolean() { return getElement().getProperty("opened", false); } /** *

* Description copied from corresponding location in WebComponent: *

*

* Set when the select is open *

* * @param opened * the boolean value to set */ protected void setOpened(boolean opened) { getElement().setProperty("opened", opened); } /** *

* Description copied from corresponding location in WebComponent: *

*

* The error message to display when the select value is invalid *

* This property is not synchronized automatically from the client side, so * the returned value may not be the same as in client side. *

* * @return the {@code errorMessage} property from the webcomponent */ protected String getErrorMessageString() { return getElement().getProperty("errorMessage"); } /** *

* Description copied from corresponding location in WebComponent: *

*

* The error message to display when the select value is invalid *

* * @param errorMessage * the String value to set */ protected void setErrorMessage(String errorMessage) { getElement().setProperty("errorMessage", errorMessage == null ? "" : errorMessage); } /** *

* Description copied from corresponding location in WebComponent: *

*

* String used for the label element. *

* This property is not synchronized automatically from the client side, so * the returned value may not be the same as in client side. *

* * @return the {@code label} property from the webcomponent */ protected String getLabelString() { return getElement().getProperty("label"); } /** *

* Description copied from corresponding location in WebComponent: *

*

* String used for the label element. *

* * @param label * the String value to set */ protected void setLabel(String label) { getElement().setProperty("label", label == null ? "" : label); } /** *

* Description copied from corresponding location in WebComponent: *

*

* The current required state of the select. True if required. *

* This property is not synchronized automatically from the client side, so * the returned value may not be the same as in client side. *

* * @return the {@code required} property from the webcomponent */ protected boolean isRequiredBoolean() { return getElement().getProperty("required", false); } /** *

* Description copied from corresponding location in WebComponent: *

*

* The current required state of the select. True if required. *

* * @param required * the boolean value to set */ protected void setRequired(boolean required) { getElement().setProperty("required", required); } /** *

* Description copied from corresponding location in WebComponent: *

*

* Set to true if the value is invalid. *

* This property is not synchronized automatically from the client side, so * the returned value may not be the same as in client side. *

* * @return the {@code invalid} property from the webcomponent */ protected boolean isInvalidBoolean() { return getElement().getProperty("invalid", false); } /** *

* Description copied from corresponding location in WebComponent: *

*

* Set to true if the value is invalid. *

* * @param invalid * the boolean value to set */ protected void setInvalid(boolean invalid) { getElement().setProperty("invalid", invalid); } /** *

* Description copied from corresponding location in WebComponent: *

*

* The name of this element. *

* This property is not synchronized automatically from the client side, so * the returned value may not be the same as in client side. *

* * @return the {@code name} property from the webcomponent */ protected String getNameString() { return getElement().getProperty("name"); } /** *

* Description copied from corresponding location in WebComponent: *

*

* The name of this element. *

* * @param name * the String value to set */ protected void setName(String name) { getElement().setProperty("name", name == null ? "" : name); } /** *

* Description copied from corresponding location in WebComponent: *

*

* A hint to the user of what can be entered in the control. 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. *

* This property is not synchronized automatically from the client side, so * the returned value may not be the same as in client side. *

* * @return the {@code placeholder} property from the webcomponent */ protected String getPlaceholderString() { return getElement().getProperty("placeholder"); } /** *

* Description copied from corresponding location in WebComponent: *

*

* A hint to the user of what can be entered in the control. 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. *

* * @param placeholder * the String value to set */ protected void setPlaceholder(String placeholder) { getElement().setProperty("placeholder", placeholder == null ? "" : placeholder); } /** *

* Description copied from corresponding location in WebComponent: *

*

* When present, it specifies that the element is read-only. *

* This property is not synchronized automatically from the client side, so * the returned value may not be the same as in client side. *

* * @return the {@code readonly} property from the webcomponent */ protected boolean isReadonlyBoolean() { return getElement().getProperty("readonly", false); } /** *

* Description copied from corresponding location in WebComponent: *

*

* When present, it specifies that the element is read-only. *

* * @param readonly * the boolean value to set */ protected void setReadonly(boolean readonly) { getElement().setProperty("readonly", readonly); } /** *

* Description copied from corresponding location in WebComponent: *

*

* Manually invoke existing renderer. *

*/ protected void render() { getElement().callFunction("render"); } /** *

* Description copied from corresponding location in WebComponent: *

*

* Returns true if {@code value} is valid, and sets the {@code invalid} flag * appropriately. *

*

* This function is not supported by Flow because it returns a * boolean. Functions with return types different than void are * not supported at this moment. */ @NotSupported protected void validate() { } public static class OpenedChangeEvent> extends ComponentEvent { private final boolean opened; public OpenedChangeEvent(R source, boolean fromClient) { super(source, fromClient); this.opened = source.isOpenedBoolean(); } public boolean isOpened() { return opened; } } /** * Adds a listener for {@code opened-changed} events fired by the * webcomponent. * * @param listener * the listener * @return a {@link Registration} for removing the event listener */ protected Registration addOpenedChangeListener( ComponentEventListener> listener) { return getElement() .addPropertyChangeListener("opened", event -> listener.onComponentEvent( new OpenedChangeEvent((R) this, event.isUserOriginated()))); } public static class InvalidChangeEvent> extends ComponentEvent { private final boolean invalid; public InvalidChangeEvent(R source, boolean fromClient) { super(source, fromClient); this.invalid = source.isInvalidBoolean(); } public boolean isInvalid() { return invalid; } } /** * Adds a listener for {@code invalid-changed} events fired by the * webcomponent. * * @param listener * the listener * @return a {@link Registration} for removing the event listener */ protected Registration addInvalidChangeListener( ComponentEventListener> listener) { return getElement() .addPropertyChangeListener("invalid", event -> listener.onComponentEvent( new InvalidChangeEvent((R) this, event.isUserOriginated()))); } /** * Adds the given components as children of this component at the slot * 'prefix'. * * @param components * The components to add. * @see MDN * page about slots * @see Spec * website about slots */ protected void addToPrefix(Component... components) { for (Component component : components) { component.getElement().setAttribute("slot", "prefix"); getElement().appendChild(component.getElement()); } } /** * Removes the given child components from this component. * * @param components * The components to remove. * @throws IllegalArgumentException * if any of the components is not a child of this component. */ protected void remove(Component... components) { for (Component component : components) { if (getElement().equals(component.getElement().getParent())) { component.getElement().removeAttribute("slot"); getElement().removeChild(component.getElement()); } else { throw new IllegalArgumentException("The given component (" + component + ") is not a child of this component"); } } } /** * 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 {@link Element} API. */ protected void removeAll() { getElement().getChildren() .forEach(child -> child.removeAttribute("slot")); getElement().removeAllChildren(); } /** * Constructs a new GeneratedVaadinSelect component with the given * arguments. * * @param initialValue * the initial value to set to the value * @param defaultValue * the default value to use if the value isn't defined * @param elementPropertyType * the type of the element property * @param presentationToModel * a function that converts a string value to a model value * @param modelToPresentation * a function that converts a model value to a string value * @param

* the property type */ public

GeneratedVaadinSelect(T initialValue, T defaultValue, Class

elementPropertyType, SerializableFunction presentationToModel, SerializableFunction modelToPresentation) { super("value", defaultValue, elementPropertyType, presentationToModel, modelToPresentation); if (initialValue != null) { setModelValue(initialValue, false); setPresentationValue(initialValue); } } /** * Constructs a new GeneratedVaadinSelect component with the given * arguments. * * @param initialValue * the initial value to set to the value * @param defaultValue * the default value to use if the value isn't defined * @param acceptNullValues * whether null is accepted as a model value */ public GeneratedVaadinSelect(T initialValue, T defaultValue, boolean acceptNullValues) { super("value", defaultValue, acceptNullValues); if (initialValue != null) { setModelValue(initialValue, false); setPresentationValue(initialValue); } } /** * Constructs a new GeneratedVaadinSelect component with the given * arguments. * * @param initialValue * the initial value to set to the value * @param defaultValue * the default value to use if the value isn't defined * @param elementPropertyType * the type of the element property * @param presentationToModel * a function that accepts this component and a property value * and returns a model value * @param modelToPresentation * a function that accepts this component and a model value and * returns a property value * @param

* the property type */ public

GeneratedVaadinSelect(T initialValue, T defaultValue, Class

elementPropertyType, SerializableBiFunction presentationToModel, SerializableBiFunction modelToPresentation) { super("value", defaultValue, elementPropertyType, presentationToModel, modelToPresentation); if (initialValue != null) { setModelValue(initialValue, false); setPresentationValue(initialValue); } } /** * Default constructor. */ public GeneratedVaadinSelect() { this(null, null, null, (SerializableFunction) null, (SerializableFunction) null); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy