Web: `TextField.focus()` after `on_submit` discards keys typed while the focus request is in flight
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- flutter, python, web-dev
- Lĩnh vực
- frontend, mobile-dev
Hướng nghiên cứu
Start by tracing how Enter affects TextField focus in the web client, then follow the client handling of the focus() method invoked from Python. The issue provides a minimal app and reproducible Playwright steps; use those to compare input value and active element around the focus request. Done means the retyped characters are preserved or Enter can keep focus, with the behavior verified against the reported cases.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Flet: 1.0.3 (stock, no other code). Browser: Chromium headless shell (Playwright), mobile emulation 390x844
with touch; macOS host. Mode: web (ft.run(main, view=None, port=8772)).
What happens
On web, pressing Enter in a TextField takes focus away from it: the field's <input> is removed and focus moves to
flutter-view. This happens with or without an on_submit handler. To let the user retype without tapping the field
again, the handler calls await field.focus(). Keys the user types after the Enter and before that focus request
lands in the client are lost. Once focus is back, the field holds only the keys typed after it arrived.
Minimal app
import flet as ft
def main(page: ft.Page):
password = ft.TextField(label="Password", password=True)
async def on_submit(e):
print("submit", "empty" if not e.data else "nonempty")
if not e.data:
await password.focus() # let the user retype without tapping the field
password.on_submit = on_submit
page.add(password)
ft.run(main, view=None, port=8772)
Steps
Each run uses a fresh browser context.
- Click the field.
- Press Enter with the field empty.
- Type a 14-character value with no click.
- Press Enter.
Each run records the DOM value and document.activeElement after every key, and compares the second on_submit
value with the typed text: exact, prefix lost, or empty.
Results (n=20 per arm)
| arm | timing | second submit |
|---|---|---|
focus() in the handler |
typing starts at once after the Enter | 0/20 exact, 20/20 prefix lost |
focus() in the handler |
typing starts 250 ms after the handler ran, then 120 ms per key | 19/20 exact, 1/20 prefix lost |
focus() only, no other update in the handler |
at once | 0/20 exact, 20/20 prefix lost |
no focus(), the test clicks the field again right after the Enter |
at once | 20/20 exact |
no focus(), no click |
0.3 s after the handler ran | the keys go nowhere: no second submit in 20/20 |
no on_submit at all; Enter caught by page.on_keyboard_event |
at once | the field loses focus within a few keys of the Enter in 20/20; the retype never reaches it (second submit empty in 20/20) |
no on_submit, no keyboard handler |
at once | the same: the field loses focus after the Enter in 20/20 and keeps none of the retype |
TextField.focus() is only _invoke_method("focus") on the Python side, so the reset happens in the web client when
the focus request is handled. In 2 runs the DOM <input> was briefly absent as the focus landed: the editing element
appears to be recreated.
Expected
Either:
- Enter on a
TextFieldcan keep its focus (an option, or no blur whenon_submitdoes not ask for it); or focus()on a field that the user is already typing into keeps the characters typed so far.
Caveat
Playwright key events are not a phone's soft keyboard. We have not measured a real device's Go key.
- Ngôn ngữ chính
- Python
- Star
- 17.5k
- Fork
- 740
- Merge trung bình
- 1 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 74
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của flet-dev/flet
-
feature: python 3.15 supportĐang mởfeature request
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
flet-dev/flet#6985 · 3 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Web: TextField values set through the DOM (autofill-like) are lost; on_submit carries an empty valueĐang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
Maintainer thường phản hồi trong vòng 1 ngày
-
feature request
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 1-2 ngày Mức phù hợp với người mới 42/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của flet-dev/flet
Issue tương tự
-
integration: logger
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
home-assistant/core#191147 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation p4
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
MillenniumDawn/focus-tree-creation-tool#417 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
CharlesP44/Beem_Energy#96 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
rheeloaded/paperpull#153 ·
Maintainer thường phản hồi trong vòng 1 ngày