Skip to content

TextInput

The TextInput widget displays a single-line text input field. It is useful for entering names, labels, filters, search queries, or any short text values in your Mercury App.

You can try the TextInput widget directly in this interactive example:

🚀 Load interactive demo Hover to start

To create a TextInput widget, provide a label. The current text entered by the user is always available via .value.

Code

import mercury as mr
text = mr.TextInput(
label="Enter your name"
)

To get the current value:

text.value

You can provide an initial value using the value argument.

Code

text = mr.TextInput(
label="City",
value="Warsaw"
)
text.value

Output

Warsaw

Use the position argument to control where the widget is displayed. The default is position="sidebar".

Available positions:

  • "sidebar" — displayed in the left sidebar (default)
  • "inline" — displayed in the main notebook output
  • "bottom" — displayed after all notebook cells

Code

mr.TextInput(
label="Search",
position="inline"
)

type: string

Text displayed above the input field. The default is "Enter text".


type: string

Initial text value.

  • If omitted, defaults to an empty string.
  • The value always reflects the current text entered by the user.

type: "sidebar" | "inline" | "bottom"

Controls where the widget is rendered:

  • sidebar — in the sidebar (default)
  • inline — directly in the notebook cell output
  • bottom — after all notebook cells

type: bool

If True, the input is visible but cannot be edited. The default is False.


type: bool

If True, the widget exists in the UI state but is not rendered. The default is False.


type: string

Unique identifier used to distinguish widgets with identical arguments.


  • The widget value is always available via .value.
  • Changes are debounced slightly to avoid excessive updates.
  • This widget is intended for single-line text. For longer text, consider a textarea-style widget.