휴대폰에서 채팅을 보낸 뒤에도 키보드 유지: "보내기" 버튼을 누르면 포커스가 버튼으로 넘어가 입력 칸이 빠지고 키보드가 내려가던 것을, 버튼의 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 };
|
||||
|
||||
@@ -117,6 +117,7 @@
|
||||
- 방 안(대기실·게임·결과)에서는 사이트 상단 메뉴를 숨기고 방 막대(← 홈 · 게임 이름 · 🔗 방 코드 · 📖 규칙 · ⚙️ 설정 · 🚪 나가기) 한 줄만 둔다. 판이 그만큼 커진다. 높이 계산은 CSS 변수 `--site-h`(방 안에서는 0)를 쓴다.
|
||||
- 채팅의 빠른 반응(이모지·짧은 말)은 한 줄. 넘치면 옆으로 밀어 본다.
|
||||
- 채팅 한 줄은 이름(작은 글씨, 사람마다 다른 색)과 말풍선(내용)을 위아래로 나눠 보여 준다. 내 말은 오른쪽, 같은 사람이 이어서 말하면 이름은 한 번만. 목록은 늘 맨 아래(새 말)에 붙어 있고, 위로 올려 읽는 중에는 움직이지 않다가 내가 보내거나 아래로 내려오면 다시 붙는다(2026-10-13). 사람별 채팅 가리기는 없앴다(사용자 요청, 2026-10-13. 필요하면 방장이 내보내기).
|
||||
- 채팅을 보낸 뒤에도 입력 칸 포커스를 그대로 둔다. 휴대폰에서 "보내기" 버튼을 눌러도 키보드가 내려가지 않는다(버튼을 누를 때 포커스를 가져가지 않음, `keepFocus`). 방 채팅·그림 맞히기·마피아·라이어 게임 채팅 모두 같다(사용자 요청, 2026-10-15).
|
||||
- 결과 창: 진한 버튼은 [🔁 한 판 더] 하나(누르면 그 방 대기실로 돌아간다, docs/06 §결과). [판 보기]·[▶ 다시 보기]는 한 줄에 나란히, [방 나가기]는 글자 버튼, 공정성 확인은 접어 둔다.
|
||||
|
||||
### 3.6 관리자 (PC)
|
||||
|
||||
@@ -204,7 +204,7 @@ try {
|
||||
await sheet.getByRole('button', { name: '닫기' }).click();
|
||||
});
|
||||
|
||||
await step('휴대폰 채팅 시트: 새 메시지가 와도 입력 칸 포커스(키보드)가 그대로', async () => {
|
||||
await step('휴대폰 채팅 시트: 새 메시지가 와도, 보내기를 눌러도 입력 칸 포커스(키보드)가 그대로', async () => {
|
||||
await b.getByRole('button', { name: /^채팅/ }).click();
|
||||
const sheet = b.getByRole('dialog', { name: '채팅' });
|
||||
const input = sheet.locator('input[aria-label="메시지"]');
|
||||
@@ -220,6 +220,12 @@ try {
|
||||
await input.press('Enter');
|
||||
await sheet.locator('.chat-line', { hasText: '치는 중 계속' }).waitFor();
|
||||
if (!(await input.evaluate((el) => el === document.activeElement))) throw new Error('the chat box lost focus after sending');
|
||||
// Tapping 보내기 (not the keyboard's send key) must not take the focus either, or the phone keyboard drops.
|
||||
await input.pressSequentially('버튼으로 보냄');
|
||||
await sheet.getByRole('button', { name: '보내기' }).tap();
|
||||
await sheet.locator('.chat-line', { hasText: '버튼으로 보냄' }).waitFor();
|
||||
await b.waitForTimeout(150);
|
||||
if (!(await input.evaluate((el) => el === document.activeElement))) throw new Error('the chat box lost focus after tapping 보내기');
|
||||
await sheet.getByRole('button', { name: '닫기' }).click();
|
||||
});
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* the keyboard (role="grid" boards support arrows + Enter) and reach the opponent.
|
||||
* Run: bun e2e/games.e2e.ts [gameId...] (needs apps/web/dist built)
|
||||
*/
|
||||
import { chromium, type Page } from 'playwright-core';
|
||||
import { chromium, type Locator, type Page } from 'playwright-core';
|
||||
import { mkdirSync, mkdtempSync } from 'node:fs';
|
||||
import { join } from 'node:path';
|
||||
import { loadConfig } from '../apps/server/src/config';
|
||||
@@ -929,8 +929,8 @@ async function catchmindTurn(pages: Page[], turn: number, shots: boolean): Promi
|
||||
await input.fill(text);
|
||||
await input.press('Enter');
|
||||
};
|
||||
// Wrong guess: visible to the drawer too.
|
||||
await send('모르겠어요');
|
||||
// Wrong guess (with the 맞히기 button; the box keeps the focus): visible to the drawer too.
|
||||
await sendByButton(guesser, input, guesser.locator('.cm-form button'), '모르겠어요');
|
||||
await drawer.locator('.cm-chat-list').getByText('모르겠어요').first().waitFor();
|
||||
// Close guess (last syllable's final consonant changed): "아까워요" for the guesser only.
|
||||
const close = await guesser.evaluate((w) => {
|
||||
@@ -980,6 +980,17 @@ async function mafiaPick(p: Page, nick: string) {
|
||||
await p.locator('button.mf-tile[aria-pressed="true"]', { has: p.locator('.nm', { hasText: new RegExp(`^${nick}( \\(나\\))?$`) }) }).waitFor({ timeout: 15_000 });
|
||||
}
|
||||
|
||||
/** Game chat box: sends a line with its button (a tap on phones) and checks the box keeps the focus (phone keyboard stays up). */
|
||||
async function sendByButton(p: Page, box: Locator, button: Locator, text: string) {
|
||||
await box.click();
|
||||
await box.fill(text);
|
||||
if (await p.evaluate(() => 'ontouchstart' in window)) await button.tap();
|
||||
else await button.click();
|
||||
await p.waitForFunction((el) => (el as HTMLInputElement).value === '', await box.elementHandle(), { timeout: 5000 });
|
||||
await p.waitForTimeout(150);
|
||||
if (!(await box.evaluate((el) => el === document.activeElement))) throw new Error(`the chat box lost focus after pressing the send button ("${text}")`);
|
||||
}
|
||||
|
||||
/** 마피아: writes in the selected channel tab and waits until the line shows up. */
|
||||
async function mafiaSay(p: Page, channel: '전체' | '마피아' | '죽은 사람', text: string) {
|
||||
await p.getByRole('tab', { name: new RegExp(`^${channel} 채팅`) }).click();
|
||||
@@ -2744,6 +2755,11 @@ const PLANS: Record<string, Plan> = {
|
||||
await pages[citizen]!.getByLabel('토론 채팅 메시지').fill(`${LIAR_NICKS[L]}님이 수상해요`);
|
||||
await pages[citizen]!.getByLabel('토론 채팅 메시지').press('Enter');
|
||||
for (const p of pages) await p.locator('.lg-msgs .lg-msg', { hasText: '님이 수상해요' }).waitFor({ timeout: 15_000 });
|
||||
{
|
||||
const ph = pages[citizen === 1 ? 2 : 1]!; // a phone
|
||||
await sendByButton(ph, ph.getByLabel('토론 채팅 메시지'), ph.locator('.lg-form').getByRole('button', { name: '보내기' }), '버튼으로 보낸 말');
|
||||
for (const p of pages) await p.locator('.lg-msgs .lg-msg', { hasText: '버튼으로 보낸 말' }).waitFor({ timeout: 15_000 });
|
||||
}
|
||||
await liarShots(pages, '3-discussion', true);
|
||||
await liarClean('discussion');
|
||||
for (const p of pages) await p.getByRole('button', { name: /^토론 끝내기/ }).click();
|
||||
@@ -2804,6 +2820,8 @@ const PLANS: Record<string, Plan> = {
|
||||
|
||||
await mafiaBanner(host, '인사 시간');
|
||||
await mafiaSay(phone, '전체', '안녕하세요 반가워요');
|
||||
await sendByButton(phone, phone.getByLabel('전체 채팅 메시지'), phone.locator('.mf-form').getByRole('button', { name: '보내기' }), '버튼으로 보낸 인사');
|
||||
for (const p of pages) await p.locator('.mf-msgs .mf-msg', { hasText: '버튼으로 보낸 인사' }).waitFor({ timeout: 15_000 });
|
||||
for (const p of pages) await p.locator('.mf-msgs .mf-msg', { hasText: '안녕하세요 반가워요' }).waitFor({ timeout: 15_000 });
|
||||
// No chat pace limit: 15 lines typed back to back all show up right away, in order, on every screen.
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user