---
url: https://talkjs.com/docs/UI_Components/React_Native/Object_Types/MessageField
---

# MessageField

Read, update, and control the message entry field.

Ask a question Copy for LLM [View as Markdown](/docs/UI_Components/React_Native/Object_Types/MessageField.md)
Encapsulates the message entry field tied to the currently selected conversation.

## Methods

### getText

```typescript
MessageField.getText(): Promise<string>
```

Gets the current content of the message field.

#### Parameters

None

#### Returns

`Promise<string>`

### setText

```typescript
MessageField.setText(text: string): void
```

Sets the message entry field to text. Useful if you want to guide your user with message suggestions.

#### Parameters

| Name | Type | Description |
| --- | --- | --- |
| **text** Required | `string` | The text to be displayed in the message entry field |

#### Returns

`void`

### typeText

```typescript
MessageField.typeText(text: string): void
```

Types the given `text` into the message field.

Inserts `text` wherever the cursor currently is.

This method may be useful for various bot/simulation scenarios.
Additionally, it lets you make it so that any regular keypress lets the user start
typing into the message field, even if it is not focused.

To do that, capture the keypress using a regular window event listener, ensure that
the user isn't typing into a different input, and then call this method to type the
key, followed by [`focus`](#focus). Note that TalkJS already does this out-of-the box
when the chat UI iframe has focus and ChatboxOptions​.captureKeyboardEvents is off.

#### Parameters

| Name | Type | Description |
| --- | --- | --- |
| **text** Required | `string` | The text to be inserted in the message entry field |

#### Returns

`void`

### setVisible

```typescript
MessageField.setVisible(visible: boolean | ConversationPredicate): void
```

Sets the visibility of the Message Field to a given value or to a certain predicate.

#### Parameters

| Name | Type | Description |
| --- | --- | --- |
| **visible** Required | `boolean` \| [`ConversationPredicate`](/docs/UI_Components/React_Native/Object_Types/ConversationPredicate/) | A boolean or predicate that outlines the circumstances the message field should be hidden |

#### Returns

`void`

### focus

```typescript
MessageField.focus(): void
```

Focuses the message entry field.

#### Parameters

None

#### Returns

`void`