mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-06-14 20:21:23 +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.
|
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
|
```tsx
|
||||||
export function Modal({ isOpen, onClose, title, children }: { isOpen: boolean; onClose: () => void; title: string; children: React.ReactNode }) {
|
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(() => {
|
useEffect(() => {
|
||||||
if (isOpen) {
|
if (isOpen) {
|
||||||
|
// Save currently focused element and move focus into modal
|
||||||
previousFocusRef.current = document.activeElement as HTMLElement;
|
previousFocusRef.current = document.activeElement as HTMLElement;
|
||||||
modalRef.current?.focus();
|
modalRef.current?.focus();
|
||||||
} else {
|
} else {
|
||||||
|
// Restore focus to the element that opened the modal
|
||||||
previousFocusRef.current?.focus();
|
previousFocusRef.current?.focus();
|
||||||
}
|
}
|
||||||
}, [isOpen]);
|
}, [isOpen]);
|
||||||
|
|||||||
Reference in New Issue
Block a user