duck.html.components.textareaยถ

Textarea HTML Component.

This module provides a customizable TextArea component for handling multi-line text input in HTML forms.

Module Contentsยถ

Classesยถ

TextArea

A reusable HTML <textarea> component for multi-line text input.

APIยถ

class duck.html.components.textarea.TextArea(element: Optional[str] = None, properties: Optional[Dict[str, str]] = None, props: Optional[Dict[str, str]] = None, style: Optional[Dict[str, str]] = None, inner_html: Optional[Union[str, str, float]] = None, children: Optional[List[duck.html.components.HtmlComponent]] = None, **kwargs)[source]ยถ

Bases: duck.html.components.InnerComponent

A reusable HTML <textarea> component for multi-line text input.

Parameters:
  • name โ€“ The name attribute of the textarea, used for form submissions.

  • placeholder โ€“ Placeholder text displayed inside the textarea before user input.

  • required โ€“ Whether the textarea is a required field in a form.

  • maxlength โ€“ The maximum number of characters allowed in the textarea.

  • minlength โ€“ The minimum number of characters.

  • disabled โ€“ Whether input is disabled.

Example:

textarea = TextArea(
    name="user_message",
    placeholder="Enter your message...",
    required=True,
    maxlength=500
)
component.add_child(textarea)

Generates:

<textarea name="user_message" placeholder="Enter your message..." required maxlength="500"></textarea>

Default Styling:

  • Uses padding, borders, and font settings from the Theme class.

  • Minimum width is set to 50% and minimum height to 80px.

Returns:

  • A <textarea> HTML element.

Initialization

Initialize an HTML component.

Parameters:
  • element โ€“ The HTML element tag name (e.g., textarea, input, button). Can be None, but make sure element is returned by get_element method.

  • accept_inner_html โ€“ Whether the HTML component accepts an inner body (e.g., inner-body-here).

  • inner_html โ€“ Inner html to add to the HTML component. Defaults to None.

  • properties โ€“ Dictionary for properties to initialize the component with.

  • props โ€“ Just same as properties argument (added for simplicity).

  • style โ€“ Dictionary for style to initialize the component with.

  • **kwargs โ€“ Extra keyword arguments

Raises:

HtmlComponentError โ€“ If โ€˜elementโ€™ is not a string or โ€˜inner_htmlโ€™ is set but โ€˜accept_inner_htmlโ€™ is False.

get_element()[source]ยถ

Returns the HTML tag for the component.

on_create()[source]ยถ

Initializes the component with default styles and attributes.