selectpackage.src.vaadin-select.d.ts Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vaadin-webcomponents Show documentation
Show all versions of vaadin-webcomponents Show documentation
Mvnpm composite: Vaadin webcomponents
/**
* @license
* Copyright (c) 2017 - 2024 Vaadin Ltd.
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
*/
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
import { ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
import { SelectBaseMixin } from './vaadin-select-base-mixin.js';
export interface SelectItem {
label?: string;
value?: string;
component?: string;
disabled?: boolean;
className?: string;
}
/**
* Fired when the user commits a value change.
*/
export type SelectChangeEvent = Event & {
target: Select;
};
/**
* Function for rendering the content of the ``.
* Receives two arguments:
*
* - `root` The `` internal container
* DOM element. Append your content to it.
* - `select` The reference to the `` element.
*/
export type SelectRenderer = (root: HTMLElement, select: Select) => void;
/**
* Fired when the `opened` property changes.
*/
export type SelectOpenedChangedEvent = CustomEvent<{ value: boolean }>;
/**
* Fired when the `invalid` property changes.
*/
export type SelectInvalidChangedEvent = CustomEvent<{ value: boolean }>;
/**
* Fired when the `value` property changes.
*/
export type SelectValueChangedEvent = CustomEvent<{ value: string }>;
/**
* Fired whenever the field is validated.
*/
export type SelectValidatedEvent = CustomEvent<{ valid: boolean }>;
export interface SelectCustomEventMap {
'opened-changed': SelectOpenedChangedEvent;
'invalid-changed': SelectInvalidChangedEvent;
'value-changed': SelectValueChangedEvent;
validated: SelectValidatedEvent;
}
export interface SelectEventMap extends HTMLElementEventMap, SelectCustomEventMap {
change: SelectChangeEvent;
}
/**
* `` is a Web Component for selecting values from a list of items.
*
* ### Items
*
* Use the `items` property to define possible options for the select:
*
* ```html
*
* ```
* ```js
* const select = document.querySelector('#select');
* select.items = [
* { label: 'Most recent first', value: 'recent' },
* { component: 'hr' },
* { label: 'Rating: low to high', value: 'rating-asc', className: 'asc' },
* { label: 'Rating: high to low', value: 'rating-desc', className: 'desc' },
* { component: 'hr' },
* { label: 'Price: low to high', value: 'price-asc', disabled: true },
* { label: 'Price: high to low', value: 'price-desc', disabled: true }
* ];
* ```
*
* ### Rendering
*
* Alternatively, the content of the select can be populated by using the renderer callback function.
*
* The renderer function provides `root`, `select` arguments.
* Generate DOM content, append it to the `root` element and control the state
* of the host element by accessing `select`.
*
* ```js
* 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;
* item.setAttribute('label', 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 `root` argument.
* On first call it will be empty.
*
* * Hint: By setting the `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 custom properties are available for styling:
*
* Custom property | Description | Target element | Default
* -----------------------------------|------------------------------|----------------------------------
* `--vaadin-field-default-width` | Default width of the field | :host | `12em`
* `--vaadin-select-text-field-width` | Effective width of the field | `vaadin-select-overlay` |
*
* `` provides mostly the same set of shadow DOM parts and state attributes as ``.
* See [``](#/elements/vaadin-text-field) for the styling documentation.
*
*
* In addition to `` parts, the following parts are available for theming:
*
* Part name | Description
* ----------------|----------------
* `toggle-button` | The toggle button
*
* In addition to `` state attributes, the following state attributes are available for theming:
*
* Attribute | Description | Part name
* ----------|-----------------------------|-----------
* `opened` | Set when the select is open | :host
*
* There are two exceptions in terms of styling compared to ``:
* - the `clear-button` shadow DOM part does not exist in ``.
* - the `input-prevented` state attribute is not supported by ``.
*
* ### Internal components
*
* In addition to `` itself, the following internal
* components are themable:
*
* - `` - has the same API as [``](#/elements/vaadin-overlay).
* - `` - has the same API as [``](#/elements/vaadin-button).
* - [``](#/elements/vaadin-input-container) - an internal element wrapping the button.
*
* Note: the `theme` attribute value set on `` is
* propagated to the internal components listed above.
*
* See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
*
* @fires {Event} change - Fired when the user commits a value change.
* @fires {CustomEvent} invalid-changed - Fired when the `invalid` property changes.
* @fires {CustomEvent} opened-changed - Fired when the `opened` property changes.
* @fires {CustomEvent} value-changed - Fired when the `value` property changes.
* @fires {CustomEvent} validated - Fired whenever the field is validated.
*/
declare class Select extends SelectBaseMixin(ElementMixin(ThemableMixin(HTMLElement))) {
addEventListener(
type: K,
listener: (this: Select, ev: SelectEventMap[K]) => void,
options?: AddEventListenerOptions | boolean,
): void;
removeEventListener(
type: K,
listener: (this: Select, ev: SelectEventMap[K]) => void,
options?: EventListenerOptions | boolean,
): void;
}
declare global {
interface HTMLElementTagNameMap {
'vaadin-select': Select;
}
}
export { Select };