(event: KeyboardEvent)
| 122 | opener.current = document.activeElement instanceof HTMLElement ? document.activeElement : null; |
| 123 | (pathField.current ?? panel.current)?.focus(); |
| 124 | const keys = (event: KeyboardEvent): void => { |
| 125 | if (event.key === 'Escape') { event.preventDefault(); event.stopPropagation(); closeCallback.current(); return; } |
| 126 | if (event.key !== 'Tab') return; |
| 127 | const controls = [...(panel.current?.querySelectorAll<HTMLElement>('button:not(:disabled), input:not(:disabled), [tabindex="0"]') ?? [])]; |
| 128 | const first = controls[0], last = controls[controls.length - 1]; |
| 129 | if (!first) { event.preventDefault(); panel.current?.focus(); return; } |
| 130 | if (event.shiftKey && (document.activeElement === first || document.activeElement === panel.current)) { event.preventDefault(); last.focus(); } |
| 131 | else if (!event.shiftKey && (document.activeElement === last || !panel.current?.contains(document.activeElement))) { event.preventDefault(); first.focus(); } |
| 132 | }; |
| 133 | window.addEventListener('keydown', keys, true); |
| 134 | return () => { window.removeEventListener('keydown', keys, true); if (opener.current?.isConnected) opener.current.focus(); }; |
| 135 | }, [open]); |
nothing calls this directly
no outgoing calls
no test coverage detected