How to Build a Styled Text Box with a Dynamic Length Counter

This guide walks you through creating a text box with custom border, rounded corners, focus shadow, and a live character‑count indicator that updates as the user types, including step‑by‑step instructions and visual examples.

AI Software Product Manager
AI Software Product Manager
AI Software Product Manager
How to Build a Styled Text Box with a Dynamic Length Counter

Configure the Text Input Field

1. Drag a text input widget onto the canvas.

Set the border color to #DCDEE2 and the corner radius to 4 px .

Define a focus style that adds an outer shadow with the following parameters:

Shadow color: #57A3F3

Opacity: 45 %

Offset X/Y: 0 px

Blur radius: 5 px

Styled text box example
Styled text box example
Focus shadow illustration
Focus shadow illustration
Cursor focus effect
Cursor focus effect
Blue border with blur effect
Blue border with blur effect

Add a Dynamic Length Counter

1. Drag a text widget onto the canvas and rename it Length . Set its initial content to "0/20" and apply a light‑gray font color #DCDEE2 .

2. Create an On Text Change interaction for the input field with the following logic:

maxLength = 20

def on_text_change(text):
    # Truncate excess characters
    if len(text) > maxLength:
        text = text[:maxLength]
        # Update the input field value to the truncated text if the platform allows

    # Compute remaining characters and update the counter widget
    remaining = maxLength - len(text)
    length_widget.text = f"{len(text)}/{maxLength}"  # e.g., "12/20"

This interaction ensures that:

The displayed counter updates in real time as the user types.

Any characters beyond the 20‑character limit are discarded, preventing them from being shown or stored.

Length counter setup
Length counter setup
Dynamic length update
Dynamic length update
Character limit enforcement
Character limit enforcement
Live counter animation
Live counter animation
frontendCSScharacter counttext box
AI Software Product Manager
Written by

AI Software Product Manager

Daily updates of Xiaomi's latest AI internal materials

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.