MCPcopy Create free account
hub / github.com/github/awesome-copilot / handleModalKeydown

Function handleModalKeydown

website/src/scripts/modal.ts:491–513  ·  view source on GitHub ↗

* Handle keyboard navigation within modal (focus trap)

(e: KeyboardEvent, modal: HTMLElement)

Source from the content-addressed store, hash-verified

489 * Handle keyboard navigation within modal (focus trap)
490 */
491function handleModalKeydown(e: KeyboardEvent, modal: HTMLElement): void {
492 if (e.key === "Tab") {
493 const focusableElements = getFocusableElements(modal);
494 if (focusableElements.length === 0) return;
495
496 const firstElement = focusableElements[0];
497 const lastElement = focusableElements[focusableElements.length - 1];
498
499 if (e.shiftKey) {
500 // Shift+Tab: if on first element, wrap to last
501 if (document.activeElement === firstElement) {
502 e.preventDefault();
503 lastElement.focus();
504 }
505 } else {
506 // Tab: if on last element, wrap to first
507 if (document.activeElement === lastElement) {
508 e.preventDefault();
509 firstElement.focus();
510 }
511 }
512 }
513}
514
515/**
516 * Setup modal functionality

Callers 1

setupModalFunction · 0.85

Calls 1

getFocusableElementsFunction · 0.85

Tested by

no test coverage detected