UNPKG

@vaadin/combo-box

Version:

Web Component for displaying a list of items with filtering

95 lines (88 loc) 3.36 kB
/** * @license * Copyright (c) 2015 - 2025 Vaadin Ltd. * This program is available under Apache License Version 2.0, available at https://vaadin.com/license/ */ import './vaadin-combo-box-item.js'; import './vaadin-combo-box-overlay.js'; import './vaadin-combo-box-scroller.js'; import { html, PolymerElement } from '@polymer/polymer/polymer-element.js'; import { defineCustomElement } from '@vaadin/component-base/src/define.js'; import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js'; import { ComboBoxLightMixin } from './vaadin-combo-box-light-mixin.js'; /** * `<vaadin-combo-box-light>` is a customizable version of the `<vaadin-combo-box>` providing * only the dropdown functionality and leaving the input field definition to the user. * * The element has the same API as `<vaadin-combo-box>`. * * To create a custom input field, you need to add a child element which has a two-way * data-bindable property representing the input value. The property name is expected * to be `value` by default. For example, you can use `<vaadin-text-field>` element: * * ```html * <vaadin-combo-box-light> * <vaadin-text-field></vaadin-text-field> * </vaadin-combo-box-light> * ``` * * If you are using custom input field that has other property for value, * set `class="input"` to enable corresponding logic, and use `attr-for-value` * attribute to specify which property to use: * * ```html * <vaadin-combo-box-light attr-for-value="input-value"> * <custom-input class="input"></custom-input> * </vaadin-combo-box-light> * ``` * * You can also pass custom toggle and clear buttons with corresponding classes: * * ```html * <vaadin-combo-box-light> * <custom-input class="input" attr-for-value="input-value"> * <button slot="suffix" class="clear-button">Clear</button> * <button slot="suffix" class="toggle-button">Toggle</button> * </custom-input> * </vaadin-combo-box-light> * ``` * * @fires {Event} change - Fired when the user commits a value change. * @fires {CustomEvent} custom-value-set - Fired when the user sets a custom value. * @fires {CustomEvent} filter-changed - Fired when the `filter` property changes. * @fires {CustomEvent} invalid-changed - Fired when the `invalid` property changes. * @fires {CustomEvent} opened-changed - Fired when the `opened` property changes. * @fires {CustomEvent} selected-item-changed - Fired when the `selectedItem` property changes. * @fires {CustomEvent} value-changed - Fired when the `value` property changes. * @fires {CustomEvent} validated - Fired whenever the field is validated. * * @customElement * @extends HTMLElement * @mixes ComboBoxLightMixin * @mixes ThemableMixin */ class ComboBoxLight extends ComboBoxLightMixin(ThemableMixin(PolymerElement)) { static get is() { return 'vaadin-combo-box-light'; } static get template() { return html` <style> :host([opened]) { pointer-events: auto; } </style> <slot></slot> <vaadin-combo-box-overlay id="overlay" opened="[[_overlayOpened]]" loading$="[[loading]]" theme$="[[_theme]]" position-target="[[inputElement]]" no-vertical-overlap ></vaadin-combo-box-overlay> `; } } defineCustomElement(ComboBoxLight); export { ComboBoxLight };