Skip to content

Commit 11650ca

Browse files
committed
Send keeps the keyboard up
Tapping the send button moved focus off the textarea on iOS (keyboard slides away), then reset-on-success refocused it (keyboard slides back) — a full hide/show bounce per send. keepFocus prevents the default on the button's pointerdown/mousedown, which stops the focus shift without cancelling the click that submits.
1 parent 9083a31 commit 11650ca

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

app/javascript/chats/composer_controller.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ export default class extends Controller {
3636
this.pingTyping()
3737
}
3838

39+
// Wired to the send button's pointerdown/mousedown: preventing the default
40+
// there stops the tap from moving focus OFF the textarea — without it, iOS
41+
// blurs the input (keyboard slides away), the submit completes, and the
42+
// reset-on-success refocus brings the keyboard right back: a full
43+
// hide/show bounce on every send. Click is NOT cancelled by a prevented
44+
// pointerdown, so the form still submits normally.
45+
// https://developer.mozilla.org/en-US/docs/Web/API/Element/pointerdown_event
46+
keepFocus(event) {
47+
event.preventDefault()
48+
}
49+
3950
enterSend(event) {
4051
if (event.shiftKey || event.isComposing) return
4152
if (!window.matchMedia("(pointer: fine)").matches) return

app/views/chats/messages/_composer.html.erb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@
5757
action: "input->chats--composer#typed keydown.enter->chats--composer#enterSend"
5858
} %>
5959

60-
<%= form.button type: :submit, class: "chats-composer__send", "aria-label": t("chats.composer.send") do %>
60+
<%# pointerdown/mousedown keepFocus: keeps the textarea focused (and the
61+
mobile keyboard up) through the send tap — see composer controller. %>
62+
<%= form.button type: :submit, class: "chats-composer__send", "aria-label": t("chats.composer.send"),
63+
data: { action: "pointerdown->chats--composer#keepFocus mousedown->chats--composer#keepFocus" } do %>
6164
<span aria-hidden="true"></span>
6265
<% end %>
6366
</div>

0 commit comments

Comments
 (0)