2 Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
3 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE
4 The complete set of authors may be found at http://polymer.github.io/AUTHORS
5 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS
6 Code distributed by Google as part of the polymer project is also
7 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS
12 `core-input` is an unstyled single-line input field. It extends the native
17 <input is="core-input">
19 The input's value is considered "committed" if the user hits the "enter" key
20 or blurs the input after changing the value. The committed value is stored in
21 the `committedValue` property.
23 If the input has `type = number`, this element will also prevent non-numeric characters
24 from being typed into the text field.
29 The following ARIA attributes are set automatically:
31 - `aria-label`: set to the `placeholder` attribute
32 - `aria-disabled`: set if `disabled` is true
34 @group Polymer Core Elements
39 <link href=
"../polymer/polymer.html" rel=
"import">
41 <style shim-shadowdom
>
42 /* FIXME consider theming */
44 html /deep/ input[is=core-input] {
49 background-color: transparent;
55 <polymer-element name=
"core-input" extends=
"input">
59 Polymer('core-input', {
64 * The "committed" value of the input, ie. the input value when the user
65 * hits the "enter" key or blurs the input after changing the value. You
66 * can bind to this value instead of listening for the "change" event.
67 * Setting this property has no effect on the input value.
69 * @attribute committedValue
76 * Set to true to prevent invalid input from being entered.
78 * @attribute preventInvalidInput
82 preventInvalidInput
: false
86 previousValidInput
: '',
90 change
: 'changeAction'
94 /* set ARIA attributes */
95 this.disabledHandler();
96 this.placeholderHandler();
99 attributeChanged: function(attr
, old
) {
100 if (this[attr
+ 'Handler']) {
101 this[attr
+ 'Handler'](old
);
105 disabledHandler: function() {
107 this.setAttribute('aria-disabled', '');
109 this.removeAttribute('aria-disabled');
113 placeholderHandler: function() {
114 if (this.placeholder
) {
115 this.setAttribute('aria-label', this.placeholder
);
117 this.removeAttribute('aria-label');
122 * Commits the `value` to `committedValue`
127 this.committedValue
= this.value
;
130 changeAction: function() {
134 inputAction: function(e
) {
135 if (this.preventInvalidInput
) {
136 if (!e
.target
.validity
.valid
) {
137 e
.target
.value
= this.previousValidInput
;
139 this.previousValidInput
= e
.target
.value
;