| 40 | }; |
| 41 | |
| 42 | const focusInputById = (inputId: string, remainingFrames = 30): void => { |
| 43 | if (typeof document === 'undefined') { |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | const input = document.getElementById(inputId); |
| 48 | if (input) { |
| 49 | input.focus(); |
| 50 | input.scrollIntoView?.({ behavior: 'smooth', block: 'center' }); |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | if (remainingFrames <= 0) { |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | requestAnimationFrame(() => focusInputById(inputId, remainingFrames - 1)); |
| 59 | }; |
| 60 | |
| 61 | export interface NewCommentRef { |
| 62 | onShowInput: (origin: Origin) => void; |