fix(skills): clarify modal focus restoration scope in frontend-a11y

This commit is contained in:
hjkim0905
2026-05-25 00:12:17 +09:00
parent b54a4fc2d0
commit 85b4114248

View File

@@ -308,7 +308,9 @@ export function Dropdown({ options, onSelect }: { options: string[]; onSelect: (
Focus must move logically when UI state changes — especially for modals and route transitions.
### Modal Focus Trap
### Modal Focus Restoration
> This example covers initial focus and restoration. For a full focus trap (Tab/Shift+Tab cycling within the modal), use a library like [`focus-trap-react`](https://github.com/focus-trap/focus-trap-react) which handles edge cases like dynamic content and nested portals.
```tsx
export function Modal({ isOpen, onClose, title, children }: { isOpen: boolean; onClose: () => void; title: string; children: React.ReactNode }) {
@@ -317,9 +319,11 @@ export function Modal({ isOpen, onClose, title, children }: { isOpen: boolean; o
useEffect(() => {
if (isOpen) {
// Save currently focused element and move focus into modal
previousFocusRef.current = document.activeElement as HTMLElement;
modalRef.current?.focus();
} else {
// Restore focus to the element that opened the modal
previousFocusRef.current?.focus();
}
}, [isOpen]);