* Create modal container with backdrop
(className = '')
| 391 | |
| 392 | // Prevent main input from stealing focus while modal is open |
| 393 | const mainInput = document.getElementById('message-input'); |
| 394 | if (mainInput) { |
| 395 | mainInput.setAttribute('tabindex', '-1'); |
| 396 | this._restoreMainInput = () => mainInput.removeAttribute('tabindex'); |
| 397 | } |
| 398 | |
| 399 | // Focus trap: keep focus within modal |
| 400 | modal.addEventListener('keydown', (e) => { |
| 401 | if (e.key === 'Tab') { |
| 402 | const focusable = modal.querySelectorAll('button, input, select, textarea, [tabindex]:not([tabindex="-1"])'); |
| 403 | if (focusable.length === 0) return; |
| 404 | |
| 405 | const first = focusable[0]; |
| 406 | const last = focusable[focusable.length - 1]; |
| 407 | |
| 408 | if (e.shiftKey && document.activeElement === first) { |
| 409 | e.preventDefault(); |
| 410 | last.focus(); |
| 411 | } else if (!e.shiftKey && document.activeElement === last) { |
| 412 | e.preventDefault(); |
| 413 | first.focus(); |
| 414 | } |
| 415 | } |
| 416 | }); |
| 417 | |
| 418 | return modal; |
| 419 | } |
| 420 | |
| 421 | /** |
| 422 | * Setup password toggle functionality (uses CSS masking since type="text" to avoid password managers) |
| 423 | */ |
| 424 | setupPasswordToggle(container) { |
| 425 | const toggleBtn = container.querySelector('.toggle-password-btn'); |
| 426 | const passwordInput = container.querySelector('.password-input'); |
| 427 | if (!toggleBtn || !passwordInput) return; |
| 428 | |
| 429 | // Prevent button from stealing focus |
no test coverage detected