Pular para o conteúdo principal

Textarea

A textarea represents a multi-line text input field that allows users to enter longer texts. It supports properties such as name, label, and event handlers (onChange, onBlur, onFocus).

Textarea

Usage

Example
import type { NubeSDK } from "@tiendanube/nube-sdk-types";
import { Box, Textarea } from "@tiendanube/nube-sdk-jsx";

function MyComponent() {
return (
<Box>
<Textarea
name="message"
label="Your Message"
maxLength={300}
row={3}
onChange={() => {}}
/>
</Box>
);
}

export function App(nube: NubeSDK) {
nube.send("ui:slot:set", () => ({
ui: {
slots: {
after_line_items: <MyComponent />,
},
},
}));
}

Event Handlers

The textarea component supports event handlers that receive an object with the following properties:

onChange: (data: {
type: "change"; // The type of event
state: NubeSDKState; // The current state of the SDK
value?: string; // The new value of the textarea
}) => void

onBlur: (data: {
type: "blur"; // The type of event
state: NubeSDKState; // The current state of the SDK
value?: string; // The current value of the textarea
}) => void

onFocus: (data: {
type: "focus"; // The type of event
state: NubeSDKState; // The current state of the SDK
value?: string; // The current value of the textarea
}) => void

Example usage:

Textarea with onChange handler
import type {
NubeSDK,
NubeComponentTextareaEventHandler,
} from "@tiendanube/nube-sdk-types";
import { Textarea, Box, Text } from "@tiendanube/nube-sdk-jsx";

function MyComponent(nube: NubeSDK) {
const handleChange: NubeComponentTextareaEventHandler = (event) => {
// event.type is "change"
// event.value is string (textarea content)
// event.state is the full NubeSDKState
const textValue = event.value ?? "";

console.log("Textarea value:", textValue);
};

return (
<Box direction="col" gap={12}>
<Text modifiers={["bold"]}>Leave a Message</Text>

<Textarea
name="message"
label="Your Message"
maxLength={300}
row={4}
onChange={handleChange}
/>
</Box>
);
}

export function App(nube: NubeSDK) {
nube.send("ui:slot:set", () => ({
ui: {
slots: {
after_line_items: MyComponent(nube),
},
},
}));
}

Properties

PropertyTypeRequiredDescription
namestringYesThe name of the textarea, used to identify it in forms.
labelstringYesThe label text displayed above the textarea.
valuestringNoThe current value of the textarea.
maxLengthnumberNoThe maximum number of characters allowed in the textarea.
rownumberNoThe number of visible text lines in the textarea.
maskstringNoFormat mask for the field input (e.g., "000.000.000-00" for CPF).
autoFocusbooleanNoWhether the textarea should automatically receive focus when mounted.
styleStyleSheetNoCustom styles for the textarea.
onChangeNubeComponentTextareaEventHandlerNoFunction called when the textarea value changes.
onBlurNubeComponentTextareaEventHandlerNoFunction called when the textarea loses focus.
onFocusNubeComponentTextareaEventHandlerNoFunction called when the textarea receives focus.