휴대폰에서 채팅을 보낸 뒤에도 키보드 유지: "보내기" 버튼을 누르면 포커스가 버튼으로 넘어가 입력 칸이 빠지고 키보드가 내려가던 것을, 버튼의 pointerdown/mousedown 기본 동작을 막아(lib/chat-input keepFocus) 포커스를 입력 칸에 두고, 보낸 뒤에도 입력 칸에 포커스를 다시 줌. 방 채팅(ChatPanel)·그림 맞히기·마피아·라이어 게임 채팅 모두. Esc로 빠져나가기와 포커스가 빠질 때 "입력 중" 끄기는 그대로. chat.e2e.ts(휴대폰 시트에서 보내기 탭)와 games.e2e.ts(catchmind·mafia·liar 보내기 버튼)에 확인 추가, docs/07에 한 줄
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@ import { useEffect, useRef, useState } from 'react';
|
||||
import { CHAT_MAX, EMOTE_LABEL, EMOTES, type PublicUser, type RoomView } from '@bg/shared/lite';
|
||||
import { create } from 'zustand';
|
||||
import { socket, useRoom } from '../net/socket';
|
||||
import { useTypingSignal } from '../lib/chat-input';
|
||||
import { keepFocus, useTypingSignal } from '../lib/chat-input';
|
||||
import { useStickToBottom } from '../lib/useStickToBottom';
|
||||
import { BotActivity } from './BotActivity';
|
||||
import { ChatMessage, sameRun } from './ChatMessage';
|
||||
@@ -70,6 +70,7 @@ export function ChatPanel({ room, me, title = true }: { room: RoomView; me: Publ
|
||||
setText('');
|
||||
typing.stop();
|
||||
pin();
|
||||
inputRef.current?.focus();
|
||||
}}
|
||||
>
|
||||
<input
|
||||
@@ -88,7 +89,9 @@ export function ChatPanel({ room, me, title = true }: { room: RoomView; me: Publ
|
||||
aria-label="메시지"
|
||||
enterKeyHint="send"
|
||||
/>
|
||||
<button className="btn btn-primary btn-sm">보내기</button>
|
||||
<button className="btn btn-primary btn-sm" {...keepFocus}>
|
||||
보내기
|
||||
</button>
|
||||
</form>
|
||||
) : (
|
||||
<p className="muted small">이 방은 채팅을 쓰지 않아요. 반응 버튼은 쓸 수 있어요.</p>
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { PublicUser, ServerMessage } from '@bg/shared/lite';
|
||||
import { nameHue } from '../../components/ChatMessage';
|
||||
import { Avatar } from '../../components/ui';
|
||||
import { useServerNow } from '../../components/TurnTimer';
|
||||
import { keepFocus } from '../../lib/chat-input';
|
||||
import { haptic, noise, sfx, sounds, tone } from '../../lib/feedback';
|
||||
import { useWide } from '../../lib/media';
|
||||
import { socket } from '../../net/socket';
|
||||
@@ -1005,6 +1006,7 @@ function GuessPanel({ v, me, players, act, pending }: { v: CatchmindView; me: st
|
||||
if (!t || !enabled) return;
|
||||
act(v.canGuess ? { type: 'guess', text: t.slice(0, max) } : { type: 'chat', text: t.slice(0, max) });
|
||||
setText('');
|
||||
inputRef.current?.focus();
|
||||
}}
|
||||
>
|
||||
<input
|
||||
@@ -1020,7 +1022,7 @@ function GuessPanel({ v, me, players, act, pending }: { v: CatchmindView; me: st
|
||||
autoComplete="off"
|
||||
onKeyDown={(e) => e.key === 'Escape' && e.currentTarget.blur()}
|
||||
/>
|
||||
<button className="btn btn-primary" disabled={!enabled || !text.trim() || pending} style={{ minWidth: 72 }}>
|
||||
<button className="btn btn-primary" disabled={!enabled || !text.trim() || pending} style={{ minWidth: 72 }} {...keepFocus}>
|
||||
{v.canGuess && v.role !== 'solver' ? '맞히기' : '보내기'}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
@@ -15,7 +15,7 @@ import { haptic, sfx, sounds, tone, useChatSound } from '../../lib/feedback';
|
||||
import { cssEsc, useBanner, type BannerTone } from '../card-fx';
|
||||
import { ChatMessage, nameHue, sameRun } from '../../components/ChatMessage';
|
||||
import { useStickToBottom } from '../../lib/useStickToBottom';
|
||||
import { useTypingSignal } from '../../lib/chat-input';
|
||||
import { keepFocus, useTypingSignal } from '../../lib/chat-input';
|
||||
import type { BoardProps, GameUI, OptionsProps } from '../types';
|
||||
import { helpNow } from './help';
|
||||
import { quickStart } from './quick';
|
||||
@@ -435,6 +435,7 @@ function ChatBox({ v, players, me, act }: { v: LiarView; players: Record<string,
|
||||
const talk = v.phase.kind === 'discussion' || v.phase.kind === 'vote';
|
||||
const canWrite = !!v.my?.canChat && talk;
|
||||
const typing = useTypingSignal('game', canWrite);
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const why = !me || !v.my ? '관전 중에는 채팅을 쓸 수 없어요.' : talk ? (v.my.chatWhy ?? '') : v.phase.kind === 'describe' ? '토론 채팅은 설명이 다 끝나면 열려요.' : (v.my.chatWhy ?? '');
|
||||
return (
|
||||
<section className="lg-box lg-chat" aria-label="토론 채팅">
|
||||
@@ -464,9 +465,11 @@ function ChatBox({ v, players, me, act }: { v: LiarView; players: Record<string,
|
||||
setText('');
|
||||
typing.stop();
|
||||
pin();
|
||||
inputRef.current?.focus();
|
||||
}}
|
||||
>
|
||||
<input
|
||||
ref={inputRef}
|
||||
className="input"
|
||||
value={text}
|
||||
onChange={(e) => {
|
||||
@@ -479,7 +482,9 @@ function ChatBox({ v, players, me, act }: { v: LiarView; players: Record<string,
|
||||
aria-label="토론 채팅 메시지"
|
||||
enterKeyHint="send"
|
||||
/>
|
||||
<button className="btn btn-primary btn-sm">보내기</button>
|
||||
<button className="btn btn-primary btn-sm" {...keepFocus}>
|
||||
보내기
|
||||
</button>
|
||||
</form>
|
||||
) : (
|
||||
why && <p className="lg-why">{why}</p>
|
||||
|
||||
@@ -15,7 +15,7 @@ import { haptic, noise, sfx, sounds, tone, useChatSound } from '../../lib/feedba
|
||||
import { useBanner, type BannerTone } from '../card-fx';
|
||||
import { ChatMessage, sameRun } from '../../components/ChatMessage';
|
||||
import { useStickToBottom } from '../../lib/useStickToBottom';
|
||||
import { useTypingSignal } from '../../lib/chat-input';
|
||||
import { keepFocus, useTypingSignal } from '../../lib/chat-input';
|
||||
import type { BoardProps, GameUI, OptionsProps } from '../types';
|
||||
import { helpNow } from './help';
|
||||
import { quickStart } from './quick';
|
||||
@@ -485,6 +485,7 @@ function ChatBox({ v, players, me, act }: { v: MafiaView; players: Record<string
|
||||
const canWrite = !!ch?.canWrite;
|
||||
// "입력 중" only from the public 전체 chat (night channels stay secret).
|
||||
const typing = useTypingSignal('game', canWrite && cur === 'day');
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
const why = ch ? ch.why : me ? '이 채팅은 읽기만 할 수 있어요.' : '관전 중에는 채팅을 쓸 수 없어요.';
|
||||
const onTabKey = (e: KeyboardEvent<HTMLDivElement>) => {
|
||||
if (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight') return;
|
||||
@@ -542,9 +543,11 @@ function ChatBox({ v, players, me, act }: { v: MafiaView; players: Record<string
|
||||
setText('');
|
||||
typing.stop();
|
||||
pin();
|
||||
inputRef.current?.focus();
|
||||
}}
|
||||
>
|
||||
<input
|
||||
ref={inputRef}
|
||||
className="input"
|
||||
value={text}
|
||||
onChange={(e) => {
|
||||
@@ -557,7 +560,9 @@ function ChatBox({ v, players, me, act }: { v: MafiaView; players: Record<string
|
||||
aria-label={`${CHANNEL_KO[cur]} 채팅 메시지`}
|
||||
enterKeyHint="send"
|
||||
/>
|
||||
<button className="btn btn-primary btn-sm">보내기</button>
|
||||
<button className="btn btn-primary btn-sm" {...keepFocus}>
|
||||
보내기
|
||||
</button>
|
||||
</form>
|
||||
) : (
|
||||
<p className="mf-why">{why}</p>
|
||||
|
||||
@@ -4,8 +4,10 @@
|
||||
* Chat lines are sent the moment Enter is pressed — no queue and no pace limit.
|
||||
* - `useTypingSignal`: tells the others "입력 중" while there is text in the box (renewed every 2 s, cleared when the
|
||||
* box is emptied or the line is sent, and when the box goes away).
|
||||
* - `keepFocus`: props for the send button so pressing it leaves the focus in the chat box — on phones the keyboard
|
||||
* stays up after sending, like with the keyboard's own send key (catchmind uses it too).
|
||||
*/
|
||||
import { useCallback, useEffect, useRef } from 'react';
|
||||
import { useCallback, useEffect, useRef, type SyntheticEvent } from 'react';
|
||||
import { socket } from '../net/socket';
|
||||
|
||||
const RENEW_MS = 2000;
|
||||
@@ -36,3 +38,7 @@ export function useTypingSignal(ch: 'room' | 'game', enabled = true) {
|
||||
useEffect(() => stop, [stop]);
|
||||
return { onText, stop };
|
||||
}
|
||||
|
||||
/** Spread on a chat form's send button: pressing it doesn't move the focus off the input (the phone keyboard stays up). */
|
||||
const noFocus = (e: SyntheticEvent) => e.preventDefault();
|
||||
export const keepFocus = { onPointerDown: noFocus, onMouseDown: noFocus };
|
||||
|
||||
Reference in New Issue
Block a user