> For AI agents: the complete documentation index is available at /next/llms.txt, the full documentation bundle is available at /next/llms-full.txt.

# `<input>`

APISummary
`<input>` is used to create interactive input controls that allow users to input and edit single-line text.

:::tip

This feature requires the client to add additional dependencies. Please refer to [More Elements](/next/guide/start/integrate-with-existing-apps.md) for the integration method.

:::

## Usage

### Basic

Below is a basic usage example of the `<input>` component:

**This is an example below: input**

**Bundle:** `dist/autoHeight.lynx.bundle`

```tsx {13-20}
// Copyright 2024 The Lynx Authors. All rights reserved.
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.

import { root, useState } from "@lynx-js/react";

const App = () => {
  const [inputContent, setInputContent] = useState("");

  return (
    <view style={{ linearOrientation: "vertical", width: "100%", height: "100%", padding: "10px" }}>
      <view style={{ width: "100%", padding: "10px", backgroundColor: "#12345678", borderRadius: "10px" }}>
        <input
          style={{ width: "100%", color: "blue", fontSize: "30px" }}
          placeholder="search"
          bindinput={(res: any) => {
            console.log(res.detail.value);
            setInputContent(res.detail.value);
          }}
        />
      </view>
      <scroll-view
        scroll-orientation="vertical"
        list-type="single"
        span-count={1}
        style={{
          width: "100%",
          height: "100%",
        }}
      >
        {Array.from({ length: 50 }).map((item, index) => {
          return (
            <text style={{ fontSize: "20px", color: "gray", padding: "10px" }}>
              {`item-${index}${inputContent ? `-${inputContent}` : ""}`}
            </text>
          );
        })}
      </scroll-view>
    </view>
  );
};

root.render(<App />);

if (import.meta.webpackHot) {
  import.meta.webpackHot.accept();
}

```

v0.7.0



### Keyboard Avoidance

`<input>` doesn't automatically avoid keyboards, but you can adjust its position by listening to keyboard events and modifying its position accordingly:

**This is an example below: input**

**Bundle:** `dist/autoHeight.lynx.bundle`

```tsx {116-123}
// Copyright 2024 The Lynx Authors. All rights reserved.
// Licensed under the Apache License Version 2.0 that can be found in the
// LICENSE file in the root directory of this source tree.

import { root, useLynxGlobalEventListener, useState } from "@lynx-js/react";

const App = () => {
  const [inputContent, setInputContent] = useState("");

  const setNativeProps = (itemId: string, props: Record<string, unknown>) => {
    lynx
      .createSelectorQuery()
      .select(`#${itemId}`)
      .setNativeProps(props)
      .exec();
  };

  const getItemRect = (
    itemId: string,
    success: (
      left: number,
      top: number,
      right: number,
      bottom: number,
      width: number,
      height: number,
    ) => void,
    fail?: (res: any) => void,
  ) => {
    const nodeRef = itemId === "root"
      ? lynx.createSelectorQuery().selectRoot()
      : lynx.createSelectorQuery().select(`#${itemId}`);

    nodeRef
      .invoke({
        method: "boundingClientRect",
        params: {
          relativeTo: "screen",
        },
        success: res => {
          success(
            /* eslint-disable @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access*/
            res.left,
            res.top,
            res.right,
            res.bottom,
            res.width,
            res.height,
            /* eslint-enable. no-safe-argument */
          );
        },
        fail: res => {
          fail?.(res);
        },
      })
      .exec();
  };

  const keyboardChanged = (keyboardHeightInPx: number) => {
    if (keyboardHeightInPx === 0) {
      setNativeProps("panel", {
        transform: `translateY(${0}px)`,
        transition: "transform 0.1s",
      });
    } else {
      setNativeProps("panel", {
        transform: `translateY(${-keyboardHeightInPx}px)`,
        transition: "transform 0.3s",
      });
    }
  };

  useLynxGlobalEventListener(
    "keyboardstatuschanged",
    (status: unknown, keyboardHeight: unknown) => {
      console.log(status);
      console.log(keyboardHeight);
      // @ts-ignore
      keyboardChanged(status === "on" ? keyboardHeight : 0);
    },
  );

  return (
    <view style={{ linearOrientation: "vertical", width: "100%", height: "100%", padding: "10px" }}>
      <scroll-view
        scroll-orientation="vertical"
        list-type="single"
        span-count={1}
        style={{
          width: "100%",
          height: "100%",
        }}
      >
        {Array.from({ length: 50 }).map((item, index) => {
          return (
            <text style={{ fontSize: "20px", color: "gray", padding: "10px" }}>
              {`item-${index}${inputContent ? `-${inputContent}` : ""}`}
            </text>
          );
        })}
      </scroll-view>
      <view
        id="panel"
        style={{
          width: "100%",
          padding: "10px",
          backgroundColor: "white",
          height: "100px",
          background: "lightgray",
          border: "1px solid black",
          position: "absolute",
          bottom: "0px",
        }}
      >
        {
          <input
            style={{ width: "100%", color: "blue", fontSize: "30px" }}
            placeholder="search"
            bindinput={(res: any) => {
              console.log(res.detail.value);
              setInputContent(res.detail.value);
            }}
          />
        }
      </view>
    </view>
  );
};

root.render(<App />);

if (import.meta.webpackHot) {
  import.meta.webpackHot.accept();
}

```

v0.7.0



## Attributes

### `android-fullscreen-mode`

Android
3.4

```tsx
// @defaultValue: true
'android-fullscreen-mode'?: boolean;
```

Whether to enter the full-screen input mode when in landscape screen, in which the keyboard and input box will take up the entire screen

### `confirm-type`

Android
iOS
Harmony
3.4

```tsx
// @defaultValue: 'send'
'confirm-type'?: 'search' | 'send' | 'go' | 'done' | 'next';
```

The type of confirm button

### `disabled`

Android
iOS
Harmony
3.5

```tsx
// @defaultValue: false
disabled?: boolean;
```

Interaction enabled

### `input-filter`

Android
iOS
Harmony
3.4

```tsx
// @defaultValue: undefined
'input-filter'?: string;
```

Filter the input content and process it in the form of regular expressions

### `ios-auto-correct`

iOS
3.4

```tsx
// @defaultValue: true
'ios-auto-correct'?: boolean;
```

Auto correct input content on iOS

### `ios-spell-check`

iOS
3.4

```tsx
// @defaultValue: true
'ios-spell-check'?: boolean;
```

Check spelling issue on iOS

### `maxlength`

Android
iOS
Harmony
3.4

```tsx
// @defaultValue: 140
maxlength?: number;
```

Max input length

### `placeholder`

Android
iOS
Harmony
3.4

```tsx
placeholder?: string;
```

Placeholder

### `readonly`

Android
iOS
Harmony
3.4

```tsx
// @defaultValue: false
readonly?: boolean;
```

Readonly

### `show-soft-input-on-focus`

Android
iOS
Harmony
3.4

```tsx
// @defaultValue: true
'show-soft-input-on-focus'?: boolean;
```

Show soft input keyboard while focused

### `type`

Android
iOS
Harmony
3.4

```tsx
// @defaultValue: "text"
type?: 'number' | 'text' | 'digit' | 'password' | 'tel' | 'email';
```

Input content type

## Events

Frontend can bind corresponding event callbacks to listen for runtime behaviors of the element, as shown below.

### `bindblur`

Android
iOS
Harmony
3.4

```tsx
bindblur = (e: InputBlurEvent) => {};
```

| Field | Type | Optional | Default | Platforms | Since | Description |
| --- | --- | --- | --- | --- | --- | --- |
| value | string | No | – | Android iOS Harmony 3.4 | 3.4 | Input content |

Blurred

### `bindconfirm`

Android
iOS
Harmony
3.4

```tsx
bindconfirm = (e: InputConfirmEvent) => {};
```

| Field | Type | Optional | Default | Platforms | Since | Description |
| --- | --- | --- | --- | --- | --- | --- |
| value | string | No | – | Android iOS Harmony 3.4 | 3.4 | Input content |

Confirm button clicked

### `bindfocus`

Android
iOS
Harmony
3.4

```tsx
bindfocus = (e: InputFocusEvent) => {};
```

| Field | Type | Optional | Default | Platforms | Since | Description |
| --- | --- | --- | --- | --- | --- | --- |
| value | string | No | – | Android iOS Harmony 3.4 | 3.4 | Input content |

Focused

### `bindinput`

Android
iOS
Harmony
3.4

```tsx
bindinput = (e: InputInputEvent) => {};
```

| Field | Type | Optional | Default | Platforms | Since | Description |
| --- | --- | --- | --- | --- | --- | --- |
| isComposing | boolean | Yes | – | Android iOS Harmony 3.4 | 3.4 | Is composing or not |
| selectionEnd | number | No | – | Android iOS Harmony 3.4 | 3.4 | The end position of the selection |
| selectionStart | number | No | – | Android iOS Harmony 3.4 | 3.4 | The start position of the selection |
| value | string | No | – | Android iOS Harmony 3.4 | 3.4 | Input content |

Input content changed

### `bindselection`

Android
iOS
Harmony
3.4

```tsx
bindselection = (e: InputSelectionEvent) => {};
```

| Field | Type | Optional | Default | Platforms | Since | Description |
| --- | --- | --- | --- | --- | --- | --- |
| selectionEnd | number | No | – | Android iOS Harmony 3.4 | 3.4 | The end position of the selection |
| selectionStart | number | No | – | Android iOS Harmony 3.4 | 3.4 | The start position of the selection |

Input selection changed

## Methods

Frontend can invoke component methods via the [SelectorQuery](/next/api/lynx-api/nodes-ref/nodes-ref-invoke.md) API.

### `blur`

Android
iOS
Harmony
3.4

```ts

lynx.createSelectorQuery()
     .select('#id')
     .invoke({
      method: 'blur',
      success: function (res) {},
      fail: function (res) {},
    })
    .exec();

```

Release focus

### `focus`

Android
iOS
Harmony
3.4

```ts

lynx.createSelectorQuery()
     .select('#id')
     .invoke({
      method: 'focus',
      success: function (res) {},
      fail: function (res) {},
    })
    .exec();

```

Require focus

### `getValue`

Android
iOS
Harmony
3.4

```ts
interface GetValueResult {
  /**
   * Is composing or not, iOS only
   * @Android
   * @iOS
   * @Harmony
   * @Web
   * @since 3.4
   */
  isComposing: boolean;
  /**
   * End position of the selection
   * @Android
   * @iOS
   * @Harmony
   * @Web
   * @since 3.4
   */
  selectionEnd: number;
  /**
   * Begin position of the selection
   * @Android
   * @iOS
   * @Harmony
   * @Web
   * @since 3.4
   */
  selectionStart: number;
  /**
   * Input content
   * @Android
   * @iOS
   * @Harmony
   * @Web
   * @since 3.4
   */
  value: string;
}

lynx.createSelectorQuery()
     .select('#id')
     .invoke({
      method: 'getValue',
      success: function (res: GetValueResult) {},
      fail: function (res) {},
    })
    .exec();

```

Get input content

### `setSelectionRange`

Android
iOS
Harmony
3.4

```ts

lynx.createSelectorQuery()
     .select('#id')
     .invoke({
      method: 'setSelectionRange',
      params: {
        /**
         * End position of the selection
         * @Android
         * @iOS
         * @Harmony
         * @Web
         * @since 3.4
         */
        selectionEnd: 5,
        /**
         * Start position of the selection
         * @Android
         * @iOS
         * @Harmony
         * @Web
         * @since 3.4
         */
        selectionStart: 0,
      },
      success: function (res) {},
      fail: function (res) {},
    })
    .exec();

```

Set selection range

### `setValue`

Android
iOS
Harmony
3.4

```ts

lynx.createSelectorQuery()
     .select('#id')
     .invoke({
      method: 'setValue',
      params: {
        /**
         * Input content
         * @Android
         * @iOS
         * @Harmony
         * @Web
         * @since 3.4
         */
        value: 'hello',
      },
      success: function (res) {},
      fail: function (res) {},
    })
    .exec();

```

Set input content

## Compatibility

**Compatibility Table**

**Query:** `elements.input`

[Source](https://github.com/lynx-family/lynx-website/tree/main/packages/lynx-compat-data/elements/input.json)

| Feature | Android | HarmonyOS | iOS | macOS | Windows | Web |
| --- | --- | --- | --- | --- | --- | --- |
| input | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes |
| attributes | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Partial |
| attributes.placeholder | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes |
| attributes.confirm-type | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes |
| attributes.maxlength | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes |
| attributes.readonly | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes |
| attributes.show-soft-input-on-focus | Yes (3.4) | Yes (3.4) | Yes (3.4) | No | No | No |
| attributes.type | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes |
| attributes.input-filter | Yes (3.4) | Yes (3.4) | Yes (3.4) | No | No | Yes |
| attributes.android-fullscreen-mode | Yes (3.4) | No | No | No | No | No |
| attributes.default-value | Yes (4.0) | Yes (4.0) | Yes (3.4) | No | No | No |
| attributes.disabled | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes |
| attributes.ios-auto-correct | No | No | Yes (3.4) | No | No | No |
| attributes.ios-spell-check | No | No | Yes (3.4) | No | No | Yes |
| rests | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes |
| events.bindblur | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes |
| events.bindconfirm | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (4.0) | Yes (4.0) | Yes |
| events.bindfocus | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes |
| events.bindinput | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes |
| events.bindselection | Yes (3.4) | Yes (3.4) | Yes (3.4) | No | No | Yes |
| methods.blur | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (4.0) | Yes (4.0) | Yes |
| methods.focus | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes |
| methods.getValue | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes |
| methods.setSelectionRange | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes |
| methods.setValue | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes |
| methods.boundingClientRect | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes |
| methods.scrollIntoView | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes (3.4) | Yes |
| methods.setFocus | No | No | No | Yes (3.4) | Yes (3.4) | No |

**`input`**

input

**`attributes`**

attributes

- **Web — Supported (version unknown):** Partial support; Web Lynx implements only part of this grouped feature.

**`attributes.placeholder`**

<code>placeholder</code>

**`attributes.confirm-type`**

<code>confirm-type</code>

**`attributes.maxlength`**

<code>maxlength</code>

**`attributes.readonly`**

<code>readonly</code>

**`attributes.show-soft-input-on-focus`**

<code>show-soft-input-on-focus</code>

**`attributes.type`**

<code>type</code>

**`attributes.input-filter`**

<code>input-filter</code>

**`attributes.android-fullscreen-mode`**

<code>android-fullscreen-mode</code>

**`attributes.default-value`**

<code>default-value</code>

**`attributes.disabled`**

<code>disabled</code>

**`attributes.ios-auto-correct`**

<code>ios-auto-correct</code>

**`attributes.ios-spell-check`**

<code>ios-spell-check</code>

**`rests`**

All the rest

**`events.bindblur`**

<code>bindblur</code>

**`events.bindconfirm`**

<code>bindconfirm</code>

**`events.bindfocus`**

<code>bindfocus</code>

**`events.bindinput`**

<code>bindinput</code>

**`events.bindselection`**

<code>bindselection</code>

**`methods.blur`**

<code>blur</code>

**`methods.focus`**

<code>focus</code>

**`methods.getValue`**

<code>getValue</code>

**`methods.setSelectionRange`**

<code>setSelectionRange</code>

**`methods.setValue`**

<code>setValue</code>

**`methods.boundingClientRect`**

<code>boundingClientRect</code>

**`methods.scrollIntoView`**

<code>scrollIntoView</code>

**`methods.setFocus`**

<code>setFocus</code>

