(event: KeyboardEvent)
| 79 | if (!pending) return; |
| 80 | |
| 81 | const handleKeyDown = (event: KeyboardEvent) => { |
| 82 | if (event.key === 'Escape') { |
| 83 | settle(false); |
| 84 | return; |
| 85 | } |
| 86 | |
| 87 | if (event.key !== 'Tab') return; |
| 88 | |
| 89 | const focusable = Array.from( |
| 90 | dialogRef.current?.querySelectorAll<HTMLButtonElement>('button:not([disabled])') ?? [] |
| 91 | ); |
| 92 | if (focusable.length === 0) return; |
| 93 | |
| 94 | const first = focusable[0]; |
| 95 | const last = focusable[focusable.length - 1]; |
| 96 | const activeElement = document.activeElement; |
| 97 | |
| 98 | if (event.shiftKey && activeElement === first) { |
| 99 | event.preventDefault(); |
| 100 | last.focus(); |
| 101 | } else if (!event.shiftKey && activeElement === last) { |
| 102 | event.preventDefault(); |
| 103 | first.focus(); |
| 104 | } |
| 105 | }; |
| 106 | |
| 107 | document.addEventListener('keydown', handleKeyDown); |
| 108 | return () => document.removeEventListener('keydown', handleKeyDown); |
nothing calls this directly
no test coverage detected