package.src.vaadin-number-field.js Maven / Gradle / Ivy
/**
* @license
* Copyright (c) 2021 - 2024 Vaadin Ltd.
* This program is available under Apache License Version 2.0, available at https://vaadin.com/license/
*/
import '@vaadin/input-container/src/vaadin-input-container.js';
import { html, PolymerElement } from '@polymer/polymer';
import { defineCustomElement } from '@vaadin/component-base/src/define.js';
import { ElementMixin } from '@vaadin/component-base/src/element-mixin.js';
import { TooltipController } from '@vaadin/component-base/src/tooltip-controller.js';
import { inputFieldShared } from '@vaadin/field-base/src/styles/input-field-shared-styles.js';
import { registerStyles, ThemableMixin } from '@vaadin/vaadin-themable-mixin/vaadin-themable-mixin.js';
import { NumberFieldMixin } from './vaadin-number-field-mixin.js';
import { numberFieldStyles } from './vaadin-number-field-styles.js';
registerStyles('vaadin-number-field', [inputFieldShared, numberFieldStyles], {
moduleId: 'vaadin-number-field-styles',
});
/**
* `` is an input field web component that only accepts numeric input.
*
* ```html
*
* ```
*
* ### Styling
*
* `` provides 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
* ------------------|-------------------------
* `increase-button` | Increase ("plus") button
* `decrease-button` | Decrease ("minus") button
*
* Note, the `input-prevented` state attribute is only supported when `allowedCharPattern` is set.
*
* See [Styling Components](https://vaadin.com/docs/latest/styling/styling-components) documentation.
*
* ### Change events
*
* Depending on the nature of the value change that the user attempts to commit e.g. by pressing Enter,
* the component can fire either a `change` event or an `unparsable-change` event:
*
* Value change | Event
* :------------------------|:------------------
* empty => parsable | change
* empty => unparsable | unparsable-change
* parsable => empty | change
* parsable => parsable | change
* parsable => unparsable | change
* unparsable => empty | unparsable-change
* unparsable => parsable | change
* unparsable => unparsable | -
*
* Note, there is currently no way to detect unparsable => unparsable changes because the browser
* doesn't provide access to unparsable values of native [type=number] inputs.
*
* @fires {Event} input - Fired when the value is changed by the user: on every typing keystroke, and the value is cleared using the clear button.
* @fires {Event} change - Fired when the user commits a value change.
* @fires {Event} unparsable-change - Fired when the user commits an unparsable value change and there is no change event.
* @fires {CustomEvent} invalid-changed - Fired when the `invalid` 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 NumberFieldMixin
* @mixes ElementMixin
* @mixes ThemableMixin
*/
export class NumberField extends NumberFieldMixin(ThemableMixin(ElementMixin(PolymerElement))) {
static get is() {
return 'vaadin-number-field';
}
static get template() {
return html`
`;
}
/** @protected */
ready() {
super.ready();
this._tooltipController = new TooltipController(this);
this.addController(this._tooltipController);
this._tooltipController.setPosition('top');
this._tooltipController.setAriaTarget(this.inputElement);
}
}
defineCustomElement(NumberField);
© 2015 - 2024 Weber Informatics LLC | Privacy Policy