프롬프트 입력창

Prompt input

입력한 줄 수만큼 자동으로 높이가 늘어나고, 첨부·전송 버튼이 딸린 대화 입력 상자.

다른 이름: ComposerChat input box
···
html
<div class="composer">
  <button class="icon" aria-label="첨부"><svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 11.5V7a4 4 0 0 0-4-4h-2a4 4 0 0 0-4 4v10a3 3 0 0 0 6 0V8"/></svg></button>
  <textarea id="ta" rows="1" readonly placeholder="메시지를 입력하세요"></textarea>
  <button class="send" id="send" aria-label="전송"><svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4"><path d="M5 12h14M13 6l6 6-6 6"/></svg></button>
</div>
css
.composer{width:min(300px,94%);display:flex;align-items:flex-end;gap:6px;padding:8px;border-radius:16px;background:var(--surface);border:1px solid var(--line)}
.icon{flex-shrink:0;width:28px;height:28px;border:0;border-radius:8px;background:none;color:var(--muted);display:grid;place-items:center;cursor:pointer}
textarea{flex:1;resize:none;border:0;background:none;color:var(--fg);font:inherit;font-size:12.5px;line-height:1.5;max-height:76px;overflow-y:auto;padding:5px 0}
textarea::placeholder{color:var(--muted)}
.send{flex-shrink:0;width:28px;height:28px;border-radius:50%;border:0;background:var(--line);color:var(--muted);display:grid;place-items:center;cursor:pointer;transition:background .18s,color .18s}
.send[data-ready]{background:var(--accent);color:#fff}
js
const ta = document.getElementById('ta'), send = document.getElementById('send');
const line = '내일까지 발표자료 3장 요약해서\n핵심만 불릿으로 정리해줘';
let i = 0;
function type() {
  ta.value = line.slice(0, i);
  ta.style.height = 'auto';
  ta.style.height = Math.min(ta.scrollHeight, 76) + 'px';
  if (i < line.length) { i++; setTimeout(type, 42); }
  else { send.setAttribute('data-ready', ''); setTimeout(sendMsg, 900); }
}
function sendMsg() {
  send.removeAttribute('data-ready');
  ta.value = '';
  ta.style.height = 'auto';
  setTimeout(() => { i = 0; type(); }, 1000);
}
setTimeout(type, 400);

한 줄 입력창(<input>)이 아니라 여러 줄을 감당하는 <textarea>가 기반입니다. 핵심은 자동 높이 조절(autosize)입니다 — 매 입력마다 height를 auto로 리셋한 뒤 scrollHeight만큼 다시 늘려서, 스크롤바 없이 내용만큼 상자가 커지게 만듭니다. 최대 높이를 넘으면 그때부터 내부 스크롤로 전환합니다.

전송 버튼은 입력이 비어 있을 때 비활성화하고, 텍스트가 생기면 색이 채워지는 식으로 지금 보낼 수 있는지를 미리 알려줍니다. Enter로 전송, Shift+Enter로 줄바꿈이 관례지만 모바일에서는 반대로 기대하는 사람도 있으니 플랫폼에 맞춰 조정합니다.

첨부 아이콘은 파일·이미지 업로드를 겸하는 경우가 많고, 마이크 아이콘이 있으면 음성 입력으로 전환됩니다. 버튼이 많아질수록 입력창이 좁아지므로, 자주 안 쓰는 기능은 + 메뉴 뒤로 숨기는 게 낫습니다.

언제 쓰나

거의 모든 대화형 AI 제품의 기본 입력 컴포넌트입니다. 입력이 항상 짧은 한 줄 명령이라면 굳이 자동 높이 조절이 필요 없을 수 있습니다.