## 요약 `useAccessibilityHandler`의 `options.withAutoFocus`가 `target`에 `focus()`만 합니다. `<div>` 처럼 기본 포커스 불가 요소면 `focus()`가 무시되고, 요소에 붙은 `keydown`도 받지 못합니다. 호출부가 `tabIndex`를 직접 넣어야 포커스·Esc가 동작합니다. ## 재현 ```tsx const rootRef = useRef<HTMLDivElement>(null); useAccessibilityHandler({ target: rootRef, options: { withAutoFocus: true }, handler: (event) => { if (event.key === "Escape") { onClose(); } }, }); return <div ref={rootRef}>{/* dialog */}</div>; ``` 1. 다이얼로그 등 비포커스 `div`를 `target`으로 넘긴다. 2. `withAutoFocus: true`로 연다. 3. 열린 뒤 Esc를 누른다. ## 실제 동작 - `target.current.focus()`가 호출되지만 포커스가 안 옮겨진다. - Esc가 핸들러까지 안 올라간다. ## 기대 동작 `withAutoFocus: true`이면 호출부가 `tabIndex`를 안 넣어도 `target`에 포커스가 가고, `keydown`이 동작한다. 탭 순서에 넣는 건 아니므로 `tabIndex={0}`이 아니라 `tabindex="-1"`이 맞다. ## 현재 구현 0.1.4, 1.1.7 모두 같습니다. ```js if (enable && target.current) { target.current.addEventListener("keydown", stableHandler); if (options?.withAutoFocus ?? false) target.current.focus(); } ``` 타입 주석에도 `tabindex` 설명이 없고, README 예시는 호출부가 `tabIndex={0}`을 넣도록 하고 있습니다. ## 제안 `withAutoFocus`일 때 `tabindex`가 없으면 `-1`을 넣고 `focus()` 한다. ```ts if (withAutoFocus && target.current) { if (!target.current.getAttribute("tabindex")) { target.current.setAttribute("tabindex", "-1"); } target.current.focus(); } ``` 호출부가 이미 `tabIndex`를 준 경우는 그대로 두면 됩니다. 아니면 `withAutoFocus` 계약(`div` 등에서는 `tabIndex`가 필요함)을 README/타입에 명시해 주세요.
Activity
theo-watcha commentedon Aug 26, 2026
프롭스 동작에 따라 기본값이 적절히 동작하는지 추가 검토하기