You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm building a small chat app and what I'd like is to have it always autofocus on the text input whenever I start typing, even if I'm not focused on the text input (because there's really no other place to input text). But I don't want to always auto focus the input when it gets blurred (bc I might want to actually select something in the chat log).
I'm doing this programmatically by keeping track of whether the input is focused1, adding a keyboard event listener to the page, and (if the chat input isn't focused) sending input keys to the input and focusing it.
However, since the text input field automatically selects everything inside when it obtains focus, this means the 1st character is always overwritten if I type anything more.
Type: "123"
"1" is sent to input and then input is focused
"1" is auto-selected
"23" replaces "1" in the input
This also happens even if I focus first, update the page, and then send the first character. It always gets selected anyway. It'd be nice if I could programmatically tell the text input "focus but don't auto select". Or, let focusing and value setting happen separately. I notice if I click on the input, it doesn't auto-select the text. I wonder if that code can be used?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Question
I'm building a small chat app and what I'd like is to have it always autofocus on the text input whenever I start typing, even if I'm not focused on the text input (because there's really no other place to input text). But I don't want to always auto focus the input when it gets blurred (bc I might want to actually select something in the chat log).
I'm doing this programmatically by keeping track of whether the input is focused1, adding a keyboard event listener to the page, and (if the chat input isn't focused) sending input keys to the input and focusing it.
However, since the text input field automatically selects everything inside when it obtains focus, this means the 1st character is always overwritten if I type anything more.
This also happens even if I focus first, update the page, and then send the first character. It always gets selected anyway. It'd be nice if I could programmatically tell the text input "focus but don't auto select". Or, let focusing and value setting happen separately. I notice if I click on the input, it doesn't auto-select the text. I wonder if that code can be used?
Python 3.12
flet 0.28.3
Sort of related: #1891
Code sample
Error message
No response
------------------------------------------------------
Footnotes
Side note- it would be nice if Flet had a property for this instead of having to manage that flag myself by tracking focus/blur events. ↩
Beta Was this translation helpful? Give feedback.
All reactions