Skip to content

fix: update the max_length counter of text and text_area while typing - #12029

Open
burrows99 wants to merge 1 commit into
marimo-team:mainfrom
burrows99:fix/text-length-counter-while-typing
Open

burrows99 wants to merge 1 commit into
marimo-team:mainfrom
burrows99:fix/text-length-counter-while-typing

Conversation

@burrows99

@burrows99 burrows99 commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

This pull request was authored by a coding agent.

📝 Summary

With max_length, mo.ui.text and mo.ui.text_area show a character counter. Both default to debounce=True, and in that mode the counter read the committed value, so it stayed at 0/20 while you typed and only caught up when you left the field or pressed Ctrl+Enter. The same happened with a numeric debounce.

The live value is held inside OnBlurredInput/DebouncedInput (and the textarea versions), so the plugin can't see it. Input's endAdornment and Textarea's bottomAdornment now also accept a function of the current value, and the two plugins pass the counter as one. The other adornment caller (the keyboard shortcut editor) passes a node and is unchanged. When the value reaches Python is unchanged.

flowchart TD
    A[Type Hello marimo into a text field with max_length 20] --> B{Counter while typing}
    B -->|Before| C[Stays at 0 of 20 until blur]
    B -->|After| D[Shows 12 of 20]
Loading

Narrated recording, before then after (sound on):

text-counter.mp4

Edge cases and unchanged behavior checked

Checked in the running editor (Vite dev server and marimo edit from main at a8d229e, then this branch, same notebook with mo.ui.text(max_length=20), mo.ui.text_area(max_length=80) and mo.ui.text()), and shown in the recording:

  • Before: typing Hello marimo leaves the title counter at 0/20; it shows 12/20 only after moving to the summary, whose counter then stays at 0/80 while typing.
  • After: the title counter reads 12/20 and the summary counter 15/80 while typing.
  • Edge case: typing past the limit stops at 20/20 (the native maxlength still refuses extra characters).
  • Edge case: Backspace counts down (14/20).
  • Unchanged: the value still reaches Python only when the field loses focus (the output cell updates after Tab, not while typing).
  • Unchanged: a mo.ui.text() without max_length shows no counter.

Covered by tests only: debounce=200 for both widgets.

Tests

  • vitest run src/plugins/impl/__test__/text-labels.test.tsx: new test "counts typed characters before committing" for text and text_area with debounce=true and debounce=200. The 4 cases fail on main (counter stays 0/10) and pass on this branch.
  • vitest run src/plugins/impl/ src/components/ui/ src/components/editor/controls: 69 files, 934 passed.
  • tsgo (frontend typecheck): clean. oxlint and oxfmt --check on the changed files: clean.
  • Not run: make check, the Python suite, e2e.

AI assistance (Claude Code) was used for this change; the bug was reproduced and the fix checked in the running editor by the agent.

📋 Pre-Review Checklist

  • For large changes, or changes that affect the public API: this change was discussed or approved through an issue, on Discord, or the community discussions (Please provide a link if applicable). Not applicable: a small bug fix with no public API change.
  • Any AI generated code has been reviewed line-by-line by the human PR author, who stands by it.
  • Video or media evidence is provided for any visual changes.

✅ Merge Checklist

  • I have read the contributor guidelines.
  • Documentation has been updated where applicable, including docstrings for API changes. No documentation covers this behavior.
  • Tests have been added for the changes made.

🤖 Generated with Claude Code

With debounce (the default for mo.ui.text and mo.ui.text_area) the
character counter read the committed value, so it stayed at 0/N while
typing and only caught up on blur or Ctrl+Enter. The counter now
renders from the input's current value.
@github-actions

Copy link
Copy Markdown
Contributor

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@burrows99
burrows99 marked this pull request as ready for review November 24, 2026 00:39
Copilot AI balanced review requested due to automatic review settings November 24, 2026 00:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants