휴대폰 채팅 시트: 새 메시지가 올 때마다 입력 칸 포커스가 빠져 키보드가 닫히던 문제(Sheet가 onClose가 바뀔 때마다 포커스를 다시 잡음) — 열 때 한 번만 포커스를 옮기게
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -47,7 +47,6 @@ export function DisplaySettings() {
|
|||||||
/**
|
/**
|
||||||
* 설정 팝업: opens over the current page so a room stays open underneath (no navigation, no leave).
|
* 설정 팝업: 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.
|
* `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 }) {
|
export function SettingsPopup({ onClose, account }: { onClose: () => void; account?: boolean }) {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -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 }) {
|
export function Sheet({ onClose, children, label }: { onClose: () => void; children: ReactNode; label: string }) {
|
||||||
const ref = useRef<HTMLDivElement>(null);
|
const ref = useRef<HTMLDivElement>(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(() => {
|
useEffect(() => {
|
||||||
const prev = document.activeElement as HTMLElement | null;
|
const prev = document.activeElement as HTMLElement | null;
|
||||||
ref.current?.focus();
|
ref.current?.focus();
|
||||||
const onKey = (e: KeyboardEvent) => e.key === 'Escape' && onClose();
|
const onKey = (e: KeyboardEvent) => e.key === 'Escape' && close.current();
|
||||||
window.addEventListener('keydown', onKey);
|
window.addEventListener('keydown', onKey);
|
||||||
return () => {
|
return () => {
|
||||||
window.removeEventListener('keydown', onKey);
|
window.removeEventListener('keydown', onKey);
|
||||||
prev?.focus?.();
|
prev?.focus?.();
|
||||||
};
|
};
|
||||||
}, [onClose]);
|
}, []);
|
||||||
return (
|
return (
|
||||||
<div className="sheet-backdrop" onClick={(e) => e.target === e.currentTarget && onClose()}>
|
<div className="sheet-backdrop" onClick={(e) => e.target === e.currentTarget && onClose()}>
|
||||||
<div className="sheet" role="dialog" aria-modal="true" aria-label={label} tabIndex={-1} ref={ref}>
|
<div className="sheet" role="dialog" aria-modal="true" aria-label={label} tabIndex={-1} ref={ref}>
|
||||||
|
|||||||
@@ -201,6 +201,25 @@ try {
|
|||||||
await sheet.getByRole('button', { name: '닫기' }).click();
|
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 () => {
|
await step('소리 크기: 방 막대 오른쪽 위, 기본 50, 0~100', async () => {
|
||||||
const btn = a.locator('.room-bar').getByRole('button', { name: /^소리 크기/ });
|
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')}`);
|
if ((await btn.getAttribute('aria-label')) !== '소리 크기 50') throw new Error(`default: ${await btn.getAttribute('aria-label')}`);
|
||||||
|
|||||||
Reference in New Issue
Block a user