[Question] Is it possible to focus the text field of a SearchBar programatically? #3350
Unanswered
chaotic-dev
asked this question in
Q&A
Replies: 1 comment 1 reply
-
Like this maybe?: import flet as ft
def main(page):
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
def close_anchor(e):
text = f"Color {e.control.data}"
anchor.value = text
anchor.update()
# print(f"closing view from {text}")
# anchor.close_view(text)
anchor = ft.SearchBar(
view_elevation=4,
divider_color=ft.colors.AMBER,
bar_hint_text="Search colors...",
view_hint_text="Choose a color from the suggestions...",
controls=[
ft.ListTile(title=ft.Text(f"Color {i}"), on_click=close_anchor, data=i)
for i in range(10)
],
)
page.add(
ft.Row(
alignment=ft.MainAxisAlignment.CENTER,
controls=[
ft.OutlinedButton(
"Open Search View",
on_click=lambda _: anchor.open_view(),
),
],
),
anchor,
)
ft.app(target=main) |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Question
I have a
SearchBar
with aListView
populated with search suggestions as its control. When I click one of theListItem
s, it modifies theSearchBar
'svalue
with the search suggestion. After doing so, theSearchBar
's input loses focus and I'd like it to remain focused for the user to continue typing. Is it possible to focus theSearchBar
's input or otherwise get its underlyingTextField
which has a focus method? I've attempted to setautofocus
toTrue
and call itsopen_view
method to try and grab focus, but neither option seem to focus the input.Thanks in advance
Code sample
Update:
OS information: Pop OS
Flet package version: 0.22.1
Error message
No response
------------------------------------------------------
Beta Was this translation helpful? Give feedback.
All reactions