Skip to content

Conversation

@FoamyGuy
Copy link
Contributor

This adds a new argument and property to TextBox that will cause the background box to remain visible when there is no text in the TextBox if set to True

It defaults to False so the behavior is the same by default.

I'm using TextBox as an input for the user to click on, and then type into and I want the box to remain visible when it's empty because they haven't typed anything yet, or have erased the text in the box with backspace.

Copy link
Contributor

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

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

This makes sense. I am kind of surprised at the current behavior: I would have thought it was already going to show the box even if the text was empty. Text as None might have made it go invisible (or use .hidden, if that's available). But this is a good upward-compatible fix.

Do you know of code that depends on this behavior? Should we change the behavior to always display?

@FoamyGuy
Copy link
Contributor Author

I had a look through learn project repo. I did find a handful of cases where TextBox is used with a background color and an initial text value of "". I think most of them are not necessarily relying on the current behavior though because they use hidden also and only show the TextBox once it has been populated.

There are a few that I'm not 100% on though. I'll need to test them out on the device to see how they look currently. The background color might be blending in to something behind it which would make the behavior change not matter.

Ultimately though I am open to the idea of making it always display the box instead of having an API to set True or False. Any code that doesn't want it to show can always still use hidden. I think the "always show" behavior does make more sense for a TextBox whose size has been set explicitly by the user. I think it was just overlooked when TextBox was created and never noticed until now.

@FoamyGuy
Copy link
Contributor Author

@dhalbert I tested all of the usages of TextBox that I was unsure about from the learn repo. All of them seem to function fine and look the same with "always show when empty" applied.

The latest commit removes the API and just makes this the default behavior for TextBox.

Copy link
Contributor

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

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

Great - this seems like simpler semantics.

@dhalbert
Copy link
Contributor

could make this a major version release

@FoamyGuy FoamyGuy merged commit 2aefd1a into adafruit:main Dec 12, 2025
1 check passed
adafruit-adabot pushed a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Dec 13, 2025
Updating https://github.com/adafruit/Adafruit_CircuitPython_Display_Text to 4.0.0 from 3.4.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#233 from FoamyGuy/textbox_show_when_empty
  > Merge pull request adafruit/Adafruit_CircuitPython_Display_Text#232 from FoamyGuy/text_box_fix_tilegrid_prop
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