We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All

input

The <input> component provides an interactive interface to receive user input. It can be a radio button, check box, or button.

NOTE

This component is supported since API version 4. Updates will be marked with a superscript to indicate their earliest API version.

Child Components

Not supported.

Attributes

Expand
Name Type Default Value Mandatory Description
type string

button

No

Type of the component,

which cannot be dynamically modified. The options are as follows:

- button: a button that can be clicked.

- checkbox: a check box.

- radio: a radio button that allows users to select one from multiple others with the same name.

- text: a text box for text input. The text input screen can only be started on real devices that support input methods. It cannot be started on UI preview.

checked boolean false No Whether the component is selected. true: selected; false: not selected. This attribute is valid only when type is set to checkbox or radio.
name string - No Name of the <input> component.
value string - No Value of the <input> component. When type is radio, this attribute is mandatory and the value must be unique for radio buttons with the same name.
id string - No Unique ID of the component.
style string - No Style declaration of the component.
class string - No Style class of the component, which is used to refer to a style table.
ref string - No Reference information of child elements, which is registered with the parent component on $refs.

Events

  • When type is set to checkbox or radio, the following events are supported.

    Expand
    Name Parameter Description
    change { checked:true | false } Triggered when the checked status of the checkbox or radio button changes.
    click - Triggered when the component is clicked.
    longpress - Triggered when the component is long pressed.
    swipe5+ SwipeEvent Event object triggered when a user quickly swipes on a component.
  • When type is set to button, the following events are supported.

    Expand
    Name Parameter Description
    click - Triggered when the component is clicked.
    longpress - Triggered when the component is long pressed.
    swipe5+ SwipeEvent Event object triggered when a user quickly swipes on a component.

Styles

Expand
Name Type Default Value Mandatory Description
color <color> #ffffff No Text color of the button.
font-size <length> 30px No Font size of the button.
width <length> - No The default value is 100px when type is set to button.
height <length> - No The default value is 50px when type is set to button.
font-family string SourceHanSansSC-Regular No Font. Only the SourceHanSansSC-Regular font is supported.
padding <length> 0 No

Shorthand attribute to set the padding for all sides.

The attribute can have one to four values:

- If you set only one value, it specifies the padding for all the four sides.

- If you set two values, the first value specifies the top and bottom padding, and the second value specifies the left and right padding.

- 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.

- If you set four values, they respectively specify the padding for top, right, bottom, and left sides (in clockwise order).

padding-[left|top|right|bottom] <length> 0 No Left, top, right, and bottom padding.
margin <length> | <percentage>5+ 0 No

Shorthand attribute to set the margin for all sides. The attribute can have one to four values:

- If you set only one value, it specifies the margin for all the four sides.

- If you set two values, the first value specifies the top and bottom margins, and the second value specifies the left and right margins.

- 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.

- If you set four values, they respectively specify the margin for top, right, bottom, and left sides (in clockwise order).

margin-[left|top|right|bottom] <length> | <percentage>5+ 0 No Left, top, right, and bottom margins.
border-width <length> 0 No Shorthand attribute to set the border width for all sides.
border-color <color> black No Shorthand attribute to set the color for all borders.
border-radius <length> - No Radius of border corners.
background-color <color> - No Background color.
display string flex No

Whether to display a box containing the element and the layout for its child elements. Available values are as follows:

- flex: flexible layout

- none: not rendered

[left|top] <length> | <percentage>6+ - No

Edge of the element.

- The left attribute specifies the 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.

- The top attribute specifies the 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.

Example

  1. Common button

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. <!-- xxx.hml -->
    2. <div class="div-button">
    3. <input class="button" type="button" value="Input-Button"></input>
    4. </div>
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. /* xxx.css */
    2. .div-button {
    3. flex-direction: column;
    4. align-items: center;
    5. width: 100%;
    6. height: 100%;
    7. }
    8. .button {
    9. margin-top: 30px;
    10. width: 280px;
    11. }

  2. Check box

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. <!-- xxx.hml -->
    2. <div class="content">
    3. <input onchange="checkboxOnChange" checked="true" type="checkbox"></input>
    4. <text class="text">{{text}}</text>
    5. </div>
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. /* xxx.css */
    2. .content{
    3. width: 100%;
    4. height: 100%;
    5. flex-direction: column;
    6. align-items: center;
    7. justify-content: center;
    8. }
    9. .text{
    10. font-size: 30px;
    11. text-align: center;
    12. width: 200px;
    13. margin-top: 20px;
    14. height: 100px;
    15. }
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. // xxx.js
    2. export default {
    3. data: {
    4. text: "text"
    5. },
    6. checkboxOnChange(e) {
    7. this.text = e.checked;
    8. }
    9. }

  3. Radio button

    Collapse
    Word wrap
    Dark theme
    Copy code
    1. <!-- xxx.hml -->
    2. <div class="container">
    3. <div class="item">
    4. <input type="radio" checked="true" name="radioSample" value="radio1" onchange="onRadioChange"></input>
    5. <text class="text">radio1</text>
    6. </div>
    7. <div class="item">
    8. <input type="radio" checked="false" name="radioSample" value="radio2" onchange="onRadioChange"></input>
    9. <text class="text">radio2</text>
    10. </div>
    11. <div class="item">
    12. <input type="radio" checked="false" name="radioSample" value="radio3" onchange="onRadioChange"></input>
    13. <text class="text">radio3</text>
    14. </div>
    15. </div>
    Collapse
    Word wrap
    Dark theme
    Copy code
    1. /* xxx.css */
    2. .container {
    3. width: 100%;
    4. height: 100%;
    5. justify-content: center;
    6. align-items: center;
    7. flex-direction: column;
    8. }
    9. .item {
    10. width: 50%;
    11. height: 30%;
    12. justify-content: center;
    13. }
    14. .text {
    15. margin-top: 25%;
    16. font-size: 30px;
    17. text-align: center;
    18. width: 200px;
    19. height: 100px;
    20. }