Rolling forward https://codereview.chromium.org/1155683008/ which was
[chromium-blink-merge.git] / ui / webui / resources / cr_elements / v1_0 / cr_input / cr_input.js
blob6273eccd140e1b9f7332ad15b5f1c5ab75fb9ea9
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 /**
6  * @fileoverview
7  * `cr-input` is a single-line text field for user input. It is a convenience
8  * element wrapping `paper-input`.
9  *
10  * Example:
11  *
12  *    <cr-input></cr-input>
13  *
14  * @group Chrome Elements
15  * @element cr-input
16  */
17 Polymer({
18   is: 'cr-input',
20   properties: {
21     /**
22      * The label for this input. It normally appears as grey text inside
23      * the text input and disappears once the user enters text.
24      */
25     label: {
26       type: String,
27       value: ''
28     },
30     /**
31      * Set to true to mark the input as required.
32      */
33     required: {
34       type: Boolean,
35       value: false
36     },
38     /**
39      * Set to true to disable editing the input.
40      */
41     disabled: {
42       type: Boolean,
43       value: false,
44       reflectToAttribute: true
45     },
47     /**
48      * The current value of the input.
49      */
50     value: {
51       type: String,
52       value: '',
53       notify: true,
54     },
56     /**
57      * The validation pattern for the input.
58      */
59     pattern: String,
61     /**
62      * The type of the input (password, date, etc.).
63      */
64     type: String,
66     /**
67      * The message to display if the input value fails validation. If this
68      * is unset or the empty string, a default message is displayed depending
69      * on the type of validation error.
70      */
71     errorMessage: {
72       type: String,
73       value: '',
74     },
75   },
77   /**
78    * Focuses the 'input' element.
79    */
80   focus: function() {
81     this.$.input.focus();
82   },
84   /** @override */
85   ready: function() {
86     this.$.events.forward(this.$.input, ['change']);
87   },
88 });