diff --git a/apps/web/src/components/SettingsPopup.tsx b/apps/web/src/components/SettingsPopup.tsx index 3dab99d..6d06a0e 100644 --- a/apps/web/src/components/SettingsPopup.tsx +++ b/apps/web/src/components/SettingsPopup.tsx @@ -47,7 +47,6 @@ export function DisplaySettings() { /** * 설정 팝업: opens over the current page so a room stays open underneath (no navigation, no leave). * `account` adds a link to the full 설정 page (nickname, records, logout); rooms leave it out because following it leaves the room. - * Pass a stable `onClose`: Sheet re-focuses itself whenever it changes. */ export function SettingsPopup({ onClose, account }: { onClose: () => void; account?: boolean }) { return ( diff --git a/apps/web/src/components/ui.tsx b/apps/web/src/components/ui.tsx index 1731bbe..6620e3a 100644 --- a/apps/web/src/components/ui.tsx +++ b/apps/web/src/components/ui.tsx @@ -66,16 +66,20 @@ export function ShareButton({ title, text, url, className = 'btn btn-secondary' export function Sheet({ onClose, children, label }: { onClose: () => void; children: ReactNode; label: string }) { const ref = useRef(null); + // Focus moves in once on open and back to the opener on close. Callers often pass a new `onClose` on every render + // (the chat sheet re-renders with each message); re-running this then pulled focus out of the chat box. + const close = useRef(onClose); + close.current = onClose; useEffect(() => { const prev = document.activeElement as HTMLElement | null; ref.current?.focus(); - const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onClose(); + const onKey = (e: KeyboardEvent) => e.key === 'Escape' && close.current(); window.addEventListener('keydown', onKey); return () => { window.removeEventListener('keydown', onKey); prev?.focus?.(); }; - }, [onClose]); + }, []); return (
e.target === e.currentTarget && onClose()}>
diff --git a/e2e/chat.e2e.ts b/e2e/chat.e2e.ts index 9038e65..1f32c58 100644 --- a/e2e/chat.e2e.ts +++ b/e2e/chat.e2e.ts @@ -201,6 +201,25 @@ try { await sheet.getByRole('button', { name: '닫기' }).click(); }); + await step('휴대폰 채팅 시트: 새 메시지가 와도 입력 칸 포커스(키보드)가 그대로', async () => { + await b.getByRole('button', { name: /^채팅/ }).click(); + const sheet = b.getByRole('dialog', { name: '채팅' }); + const input = sheet.locator('input[aria-label="메시지"]'); + await input.click(); + await input.pressSequentially('치는 중'); + for (let i = 1; i <= 3; i++) { + await say(a, `치는 동안 온 메시지 ${i}`); + await sheet.locator('.chat-line', { hasText: `치는 동안 온 메시지 ${i}` }).waitFor(); + } + await b.waitForTimeout(150); + if (!(await input.evaluate((el) => el === document.activeElement))) throw new Error('the chat box lost focus when a line arrived'); + await input.pressSequentially(' 계속'); + 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'); + await sheet.getByRole('button', { name: '닫기' }).click(); + }); + await step('소리 크기: 방 막대 오른쪽 위, 기본 50, 0~100', async () => { const btn = a.locator('.room-bar').getByRole('button', { name: /^소리 크기/ }); if ((await btn.getAttribute('aria-label')) !== '소리 크기 50') throw new Error(`default: ${await btn.getAttribute('aria-label')}`);