mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-06-11 02:33:10 +08:00
fix(skills): clarify modal focus restoration scope in frontend-a11y
This commit is contained in:
@@ -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]);
|
||||
|
||||
Reference in New Issue
Block a user