diff --git a/static/js/emailLibrary.js b/static/js/emailLibrary.js index b588e88dd..5f3473d0a 100644 --- a/static/js/emailLibrary.js +++ b/static/js/emailLibrary.js @@ -5899,10 +5899,17 @@ function _showAiReplyChoice(btn, em, data) { const rect = btn.getBoundingClientRect(); const menu = document.createElement('div'); menu.className = 'email-ai-reply-choice'; + /* Clamp width to viewport minus 16px margin so the menu (now wider + because of the note textarea) never spills off the right edge + on narrow mobile screens. */ + const menuMaxW = Math.min(220, window.innerWidth - 16); + const left = Math.max(8, Math.min(rect.left, window.innerWidth - menuMaxW - 8)); menu.style.cssText = [ 'position:fixed', - `left:${Math.max(8, Math.min(rect.left, window.innerWidth - 190))}px`, + `left:${left}px`, `top:${Math.min(window.innerHeight - 96, rect.bottom + 6)}px`, + `max-width:${menuMaxW}px`, + 'box-sizing:border-box', 'z-index:10060', 'display:flex', 'gap:6px', @@ -5930,24 +5937,13 @@ function _showAiReplyChoice(btn, em, data) { - `; const notePanel = menu.querySelector('[data-note-panel]'); const noteInput = menu.querySelector('[data-note-input]'); - const noteActions = menu.querySelector('[data-note-actions]'); menu.querySelector('[data-act="note-toggle"]').addEventListener('click', (ev) => { ev.preventDefault(); ev.stopPropagation(); @@ -5959,18 +5955,15 @@ function _showAiReplyChoice(btn, em, data) { notePanel.setAttribute('hidden', ''); } }); - noteInput.addEventListener('input', () => { - if (noteInput.value.trim()) noteActions.removeAttribute('hidden'); - else noteActions.setAttribute('hidden', ''); - }); menu.addEventListener('click', async (ev) => { const choice = ev.target.closest('[data-mode]'); if (!choice) return; ev.preventDefault(); ev.stopPropagation(); const mode = choice.getAttribute('data-mode') || 'ai-reply'; - const useNote = choice.getAttribute('data-note') === '1'; - const noteHint = useNote ? (noteInput.value || '').trim() : ''; + // Always pick up whatever's in the textarea — empty = no note, + // typed = passed through as steering context. + const noteHint = (noteInput.value || '').trim(); _closeAiReplyChoice(); await _runAiReplyFromButton(btn, em, data, mode, noteHint); });