휴대폰 채팅 시트: 새 메시지가 올 때마다 입력 칸 포커스가 빠져 키보드가 닫히던 문제(Sheet가 onClose가 바뀔 때마다 포커스를 다시 잡음) — 열 때 한 번만 포커스를 옮기게

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
EJClaw
2026-10-14 04:21:43 +09:00
parent 18f0530237
commit 1ba83766d0
3 changed files with 25 additions and 3 deletions

View File

@@ -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 (

View File

@@ -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<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(() => {
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 (
<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}>