* Get all focusable elements within a container
(container: HTMLElement)
| 471 | * Get all focusable elements within a container |
| 472 | */ |
| 473 | function getFocusableElements(container: HTMLElement): HTMLElement[] { |
| 474 | const focusableSelectors = [ |
| 475 | "button:not([disabled])", |
| 476 | "a[href]", |
| 477 | "input:not([disabled])", |
| 478 | "select:not([disabled])", |
| 479 | "textarea:not([disabled])", |
| 480 | '[tabindex]:not([tabindex="-1"])', |
| 481 | ].join(", "); |
| 482 | |
| 483 | return Array.from( |
| 484 | container.querySelectorAll<HTMLElement>(focusableSelectors) |
| 485 | ).filter((el) => el.offsetParent !== null); // Filter out hidden elements |
| 486 | } |
| 487 | |
| 488 | /** |
| 489 | * Handle keyboard navigation within modal (focus trap) |
no outgoing calls
no test coverage detected