1e41f4b71Sopenharmony_ci# input
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciThe **\<input>** component provides an interactive interface to receive user input. It can be a radio button, check box, or button.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **NOTE**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version.
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## Child Components
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ciNot supported
13e41f4b71Sopenharmony_ci
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci## Attributes
16e41f4b71Sopenharmony_ci
17e41f4b71Sopenharmony_ci| Name| Type| Default Value| Mandatory| Description|
18e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
19e41f4b71Sopenharmony_ci| type | string | <br>button | No| Type of the component, which cannot be dynamically modified. The options are as follows:<br>- **button**: a button that can be clicked.<br>- **checkbox**: a check box.<br>- **radio**: a radio button that allows users to select one from multiple others with the same name. |
20e41f4b71Sopenharmony_ci| checked | boolean | false | No| Whether the component is selected. This attribute is valid only when **type** is set to **checkbox** or **radio**.|
21e41f4b71Sopenharmony_ci| name | string | - | No| Name of the component.|
22e41f4b71Sopenharmony_ci| value | string | - | No| Value of the component. When **type** is **radio**, this attribute is mandatory and the value must be unique for radio buttons with the same name.|
23e41f4b71Sopenharmony_ci| id | string | - | No| Unique ID of the component.|
24e41f4b71Sopenharmony_ci| style | string | - | No| Style declaration of the component.|
25e41f4b71Sopenharmony_ci| class | string | - | No| Style class of the component, which is used to refer to a style table.|
26e41f4b71Sopenharmony_ci| ref | string | - | No| Reference information of child elements, which is registered with the parent component on **$refs**.|
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci## Events
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci- When **type** is set to **checkbox** or **radio**, the following events are supported.
32e41f4b71Sopenharmony_ci    | Name| Parameter| Description|
33e41f4b71Sopenharmony_ci  | -------- | -------- | -------- |
34e41f4b71Sopenharmony_ci  | change | { checked:true \| false } | Triggered when the checked status of the **checkbox** or **radio** button changes.|
35e41f4b71Sopenharmony_ci  | click | - | Triggered when the component is clicked. |
36e41f4b71Sopenharmony_ci  | longpress | - | Triggered when the component is long pressed. |
37e41f4b71Sopenharmony_ci  | swipe<sup>5+</sup> | [SwipeEvent](js-lite-common-events.md) | Triggered when a user quickly swipes on the component. |
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci- When **type** is set to **button**, the following events are supported.
40e41f4b71Sopenharmony_ci    | Name| Parameter| Description|
41e41f4b71Sopenharmony_ci  | -------- | -------- | -------- |
42e41f4b71Sopenharmony_ci  | click | - | Triggered when the component is clicked. |
43e41f4b71Sopenharmony_ci  | longpress | - | Triggered when the component is long pressed. |
44e41f4b71Sopenharmony_ci  | swipe<sup>5+</sup> | [SwipeEvent](js-lite-common-events.md) | Triggered when a user quickly swipes on the component. |
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci
47e41f4b71Sopenharmony_ci## Styles
48e41f4b71Sopenharmony_ci
49e41f4b71Sopenharmony_ci| Name| Type| Default Value| Mandatory| Description|
50e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | -------- |
51e41f4b71Sopenharmony_ci| color | &lt;color&gt; | \#ffffff | No| Text color of the component.|
52e41f4b71Sopenharmony_ci| font-size | &lt;length&gt; | 30px | No| Font size of the component.|
53e41f4b71Sopenharmony_ci| width | &lt;length&gt; | - | No| Width of the component. The default value for a button is **100px**.|
54e41f4b71Sopenharmony_ci| height | &lt;length&gt; | - | No| Height of the component. The default value for a button is **50px**.|
55e41f4b71Sopenharmony_ci| font-family | string | SourceHanSansSC-Regular | No| Font. Only the **SourceHanSansSC-Regular** font is supported.|
56e41f4b71Sopenharmony_ci| padding | &lt;length&gt; | 0 | No| Shorthand attribute to set the padding for all sides.<br>The attribute can have one to four values:<br>- If you set only one value, it specifies the padding for all the four sides.<br>- If you set two values, the first value specifies the top and bottom padding, and the second value specifies the left and right padding.<br>- If you set three values, the first value specifies the top padding, the second value specifies the left and right padding, and the third value specifies the bottom padding.<br>- If you set four values, they respectively specify the padding for top, right, bottom, and left sides (in clockwise order).|
57e41f4b71Sopenharmony_ci| padding-[left\|top\|right\|bottom] | &lt;length&gt; | 0 | No| Left, top, right, and bottom padding.|
58e41f4b71Sopenharmony_ci| margin | &lt;length&gt; \| &lt;percentage&gt;<sup>5+</sup> | 0 | No| Shorthand attribute to set the margin for all sides. The attribute can have one to four values:<br>- If you set only one value, it specifies the margin for all the four sides.<br>- If you set two values, the first value specifies the top and bottom margins, and the second value specifies the left and right margins.<br>- If you set three values, the first value specifies the top margin, the second value specifies the left and right margins, and the third value specifies the bottom margin.<br>- If you set four values, they respectively specify the margin for top, right, bottom, and left sides (in clockwise order).|
59e41f4b71Sopenharmony_ci| margin-[left\|top\|right\|bottom] | &lt;length&gt; \| &lt;percentage&gt;<sup>5+</sup> | 0 | No| Left, top, right, and bottom margins.|
60e41f4b71Sopenharmony_ci| border-width | &lt;length&gt; | 0 | No| Shorthand attribute to set the margin for all sides.|
61e41f4b71Sopenharmony_ci| border-color | &lt;color&gt; | black | No| Shorthand attribute to set the color for all borders.|
62e41f4b71Sopenharmony_ci| border-radius | &lt;length&gt; | - | No| Radius of round-corner borders. |
63e41f4b71Sopenharmony_ci| background-color | &lt;color&gt; | - | No| Background color.|
64e41f4b71Sopenharmony_ci| display | string | flex | No| How and whether to display the box containing an element. Available values are as follows:<br>- **flex**: flexible layout<br>- **none**: not rendered|
65e41f4b71Sopenharmony_ci| [left\|top] | &lt;length&gt; \| &lt;percentage&gt;<sup>6+</sup> | - | No| Edge of the element.<br>- **left**: left edge position of the element. This attribute defines the offset between the left edge of the margin area of a positioned element and left edge of its containing block.<br>- **top**: top edge position of the element. This attribute defines the offset between the top edge of a positioned element and that of a block included in the element. |
66e41f4b71Sopenharmony_ci
67e41f4b71Sopenharmony_ci## Example
68e41f4b71Sopenharmony_ci
69e41f4b71Sopenharmony_ci1. Common button
70e41f4b71Sopenharmony_ci
71e41f4b71Sopenharmony_ci   ```html
72e41f4b71Sopenharmony_ci   <!-- xxx.hml -->
73e41f4b71Sopenharmony_ci   <div class="div-button">
74e41f4b71Sopenharmony_ci     <input class="button" type="button" value="Input-Button"></input>
75e41f4b71Sopenharmony_ci   </div>
76e41f4b71Sopenharmony_ci   ```
77e41f4b71Sopenharmony_ci
78e41f4b71Sopenharmony_ci   ```css
79e41f4b71Sopenharmony_ci   /* xxx.css */
80e41f4b71Sopenharmony_ci   .div-button {
81e41f4b71Sopenharmony_ci     flex-direction: column;
82e41f4b71Sopenharmony_ci     align-items: center;
83e41f4b71Sopenharmony_ci     width: 100%;
84e41f4b71Sopenharmony_ci     height: 100%;
85e41f4b71Sopenharmony_ci   }
86e41f4b71Sopenharmony_ci   .button {
87e41f4b71Sopenharmony_ci     margin-top: 30px;
88e41f4b71Sopenharmony_ci     width: 280px;
89e41f4b71Sopenharmony_ci   }
90e41f4b71Sopenharmony_ci   ```
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci   ![input-type-button](figures/input-type-button.png)
93e41f4b71Sopenharmony_ci
94e41f4b71Sopenharmony_ci   
95e41f4b71Sopenharmony_ci
96e41f4b71Sopenharmony_ci2. Check box
97e41f4b71Sopenharmony_ci
98e41f4b71Sopenharmony_ci   ```html
99e41f4b71Sopenharmony_ci   <!-- xxx.hml -->
100e41f4b71Sopenharmony_ci   <div class="content">
101e41f4b71Sopenharmony_ci     <input onchange="checkboxOnChange" checked="true" type="checkbox"></input>
102e41f4b71Sopenharmony_ci     <text class="text">{{text}}</text>
103e41f4b71Sopenharmony_ci   </div>
104e41f4b71Sopenharmony_ci   ```
105e41f4b71Sopenharmony_ci
106e41f4b71Sopenharmony_ci   ```css
107e41f4b71Sopenharmony_ci   /* xxx.css */
108e41f4b71Sopenharmony_ci   .content{
109e41f4b71Sopenharmony_ci     width: 100%;
110e41f4b71Sopenharmony_ci     height: 100%;
111e41f4b71Sopenharmony_ci     flex-direction: column;
112e41f4b71Sopenharmony_ci     align-items: center; 
113e41f4b71Sopenharmony_ci     justify-content: center;   
114e41f4b71Sopenharmony_ci   }
115e41f4b71Sopenharmony_ci   .text{
116e41f4b71Sopenharmony_ci     font-size: 30px;
117e41f4b71Sopenharmony_ci     text-align: center;
118e41f4b71Sopenharmony_ci     width: 200px;
119e41f4b71Sopenharmony_ci     margin-top: 20px;
120e41f4b71Sopenharmony_ci     height: 100px;
121e41f4b71Sopenharmony_ci   }
122e41f4b71Sopenharmony_ci   ```
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci   ```javascript
125e41f4b71Sopenharmony_ci   // xxx.js
126e41f4b71Sopenharmony_ci   export default {
127e41f4b71Sopenharmony_ci     data: {
128e41f4b71Sopenharmony_ci       text: "text"
129e41f4b71Sopenharmony_ci     },
130e41f4b71Sopenharmony_ci     checkboxOnChange(e) {
131e41f4b71Sopenharmony_ci       this.text = e.checked;
132e41f4b71Sopenharmony_ci     }
133e41f4b71Sopenharmony_ci   }
134e41f4b71Sopenharmony_ci   ```
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ci   ![input-type-checkbox](figures/input-type-checkbox.gif)
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ci3. Radio button
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ci   ```html
141e41f4b71Sopenharmony_ci   <!-- xxx.hml -->
142e41f4b71Sopenharmony_ci   <div class="container">
143e41f4b71Sopenharmony_ci     <div class="item">
144e41f4b71Sopenharmony_ci       <input type="radio" checked="true" name="radioSample" value="radio1" onchange="onRadioChange"></input>
145e41f4b71Sopenharmony_ci       <text class="text">radio1</text>
146e41f4b71Sopenharmony_ci     </div>
147e41f4b71Sopenharmony_ci     <div class="item">
148e41f4b71Sopenharmony_ci       <input type="radio" checked="false" name="radioSample" value="radio2" onchange="onRadioChange"></input>
149e41f4b71Sopenharmony_ci       <text class="text">radio2</text>
150e41f4b71Sopenharmony_ci     </div>
151e41f4b71Sopenharmony_ci     <div class="item">
152e41f4b71Sopenharmony_ci       <input type="radio" checked="false" name="radioSample" value="radio3" onchange="onRadioChange"></input>
153e41f4b71Sopenharmony_ci       <text class="text">radio3</text>
154e41f4b71Sopenharmony_ci     </div>
155e41f4b71Sopenharmony_ci   </div>
156e41f4b71Sopenharmony_ci   ```
157e41f4b71Sopenharmony_ci
158e41f4b71Sopenharmony_ci   ```css
159e41f4b71Sopenharmony_ci   /* xxx.css */
160e41f4b71Sopenharmony_ci   .container {
161e41f4b71Sopenharmony_ci     width: 100%;
162e41f4b71Sopenharmony_ci     height: 100%;
163e41f4b71Sopenharmony_ci     justify-content: center;
164e41f4b71Sopenharmony_ci     align-items: center;
165e41f4b71Sopenharmony_ci     flex-direction: column;
166e41f4b71Sopenharmony_ci   }
167e41f4b71Sopenharmony_ci   .item {
168e41f4b71Sopenharmony_ci     width: 50%;
169e41f4b71Sopenharmony_ci     height: 30%;
170e41f4b71Sopenharmony_ci     justify-content: center;
171e41f4b71Sopenharmony_ci   }
172e41f4b71Sopenharmony_ci   .text {
173e41f4b71Sopenharmony_ci     margin-top: 25%;
174e41f4b71Sopenharmony_ci     font-size: 30px;
175e41f4b71Sopenharmony_ci     text-align: center;
176e41f4b71Sopenharmony_ci     width: 200px;
177e41f4b71Sopenharmony_ci     height: 100px;
178e41f4b71Sopenharmony_ci   }
179e41f4b71Sopenharmony_ci   ```
180e41f4b71Sopenharmony_ci
181e41f4b71Sopenharmony_ci   ![input-type-radio](figures/input-type-radio.gif)
182