fix: maintain chat input focus after sending message #2360
Reference in New Issue
Block a user
Delete Branch "fix/ai-input-focus"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR fixes the issue where the chat input field loses focus after sending a message, requiring users to click back into the field to continue typing.
Changes
MessagesController#createto respond with Turbo Streams instead of redirectingcreate.turbo_stream.erbto handle the async form submissionTesting
field)
Demo
https://github.com/user-attachments/assets/b8c3b418-aef7-4738-899e-468ff64af61b
Related Issues
Fixes #2335
@@ -0,0 +1,14 @@<%# Add thinking indicator to messages area %>Generally prefer to not use
<script>tags in this way. Should make use of Rails javascript conventions with Stimulus.🚨 BugBot couldn't run
Pull requests from forked repositories are not yet supported (requestId: serverGenReqId_96cea5c4-1dc9-4dff-aeb4-a7518e95b5f4).
@@ -0,0 +1,14 @@<%# Add thinking indicator to messages area %>I'll update now
@@ -0,0 +11,4 @@<%# Focus the input after form replacement using Stimulus %><%= turbo_stream.append "messages" do %><div data-controller="focus-chat-input"></div><% end %>I'm wondering if this stream is necessary. If we're pushing a replacement to the
chat-formabove, could we just auto-focus the form every time it mounts to the DOM?Maybe in chat-controller, we listen for "form connected callback" and then trigger a focus? I believe that would work since we're pushing a brand new instance of the form here.
Pull request closed