메시지 입력창
메시지나 프롬프트를 작성하는 입력창입니다. 텍스트에 따라 입력란이 늘어나며 그 아래에 도구가 한 줄로 배치됩니다.
이 페이지의 내용
메시지 입력창은 메시지나 프롬프트를 입력하는 곳입니다. 살짝 떠 있는 표면에는 별도의 테두리 없이 텍스트에 따라 높이가 늘어나는 입력란이 있고, 그 아래에는 눈에 덜 띄는 도구들이 한 줄로 배치되며 맨 끝에 전송 버튼이 놓입니다. 입력 컴포넌트와 마찬가지로 입력란에 포커스가 오면 표면에 잉크색 윤곽선 하나와 은은한 빛 테두리가 나타납니다.
메시지 입력창
<form class="composer max-w(480) mx-auto"> <textarea class="composer-field" name="message" aria-label="Message" placeholder="Ask anything"></textarea> <div class="composer-toolbar"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Attach a file"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /><path d="M8 3L8 13" /> </svg> </button> <button type="button" class="btn btn-quiet btn-sm"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <circle cx="8" cy="8" r="6" /><path d="M8.7707 2.0497A6.0005 6.0005 0 0 0 7.2293 2.0497Q6.1162 3.1938 5.4813 4.6077Q4.8542 6.0044 4.7648 7.5H2.0209A5.9913 5.9913 0 0 0 2.0209 8.5H4.7648Q4.8542 9.9956 5.4813 11.3923Q6.1162 12.8062 7.2293 13.9503A6.0005 6.0005 0 0 0 8.7707 13.9503Q9.8838 12.8062 10.5187 11.3923Q11.1458 9.9956 11.2352 8.5H13.9791A5.9913 5.9913 0 0 0 13.9791 7.5H11.2352Q11.1458 6.0044 10.5187 4.6077Q9.8838 3.1938 8.7707 2.0497ZM9.6064 5.0173Q10.1455 6.2181 10.2331 7.5H5.7669Q5.8545 6.2181 6.3936 5.0173Q6.971 3.7314 8 2.6921Q9.029 3.7314 9.6064 5.0173ZM6.3936 10.9827Q5.8545 9.7819 5.7669 8.5H10.2331Q10.1455 9.7819 9.6064 10.9827Q9.029 12.2686 8 13.3079Q6.971 12.2686 6.3936 10.9827Z" fill="currentColor" stroke="none" fill-rule="evenodd" /> </svg>Search </button> <div class="composer-end"> <span class="composer-hint">Enter to send</span> <button class="btn btn-primary btn-square btn-sm" aria-label="Send"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M13.6362 7.5189A0.4947 0.4947 0 0 0 13.5 7.5L2.4755 7.5006A0.5 0.5 0 0 0 2.4266 8.4946L2.5 8.5H13.5A0.4947 0.4947 0 0 0 13.6362 8.4811A0.7009 0.7009 0 0 0 13.6362 7.5189Z" fill="currentColor" stroke="none" fill-rule="evenodd" transform="rotate(-90 8 8)" /><path d="M8 4.5L13.2348 7.8313A0.2 0.2 0 0 1 13.2348 8.1687L8 11.5" transform="rotate(-90 8 8)" /> </svg> </button> </div> </div></form>import PlusIcon from '@master/icons-react/native/16/soft/plus'import GlobeIcon from '@master/icons-react/native/16/soft/globe'import ArrowUpIcon from '@master/icons-react/native/16/soft/arrow-up'<form className="composer max-w(480) mx-auto"> <textarea className="composer-field" name="message" aria-label="Message" placeholder="Ask anything">{``}</textarea> <div className="composer-toolbar"> <button type="button" className="btn btn-quiet btn-square btn-sm" aria-label="Attach a file"> <PlusIcon className="icon" /> </button> <button type="button" className="btn btn-quiet btn-sm"> <GlobeIcon className="icon" />Search </button> <div className="composer-end"> <span className="composer-hint">Enter to send</span> <button className="btn btn-primary btn-square btn-sm" aria-label="Send"> <ArrowUpIcon className="icon" /> </button> </div> </div></form><script> import PlusIcon from '@master/icons-svelte/native/16/soft/plus' import GlobeIcon from '@master/icons-svelte/native/16/soft/globe' import ArrowUpIcon from '@master/icons-svelte/native/16/soft/arrow-up'</script><form class="composer max-w(480) mx-auto"> <textarea class="composer-field" name="message" aria-label="Message" placeholder="Ask anything"></textarea> <div class="composer-toolbar"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Attach a file"> <PlusIcon class="icon" /> </button> <button type="button" class="btn btn-quiet btn-sm"><GlobeIcon class="icon" />Search</button> <div class="composer-end"> <span class="composer-hint">Enter to send</span> <button class="btn btn-primary btn-square btn-sm" aria-label="Send"> <ArrowUpIcon class="icon" /> </button> </div> </div></form><script setup>import PlusIcon from '@master/icons-vue/native/16/soft/plus'import GlobeIcon from '@master/icons-vue/native/16/soft/globe'import ArrowUpIcon from '@master/icons-vue/native/16/soft/arrow-up'</script><template> <form class="composer max-w(480) mx-auto"> <textarea class="composer-field" name="message" aria-label="Message" placeholder="Ask anything"></textarea> <div class="composer-toolbar"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Attach a file"> <PlusIcon class="icon" /> </button> <button type="button" class="btn btn-quiet btn-sm"><GlobeIcon class="icon" />Search</button> <div class="composer-end"> <span class="composer-hint">Enter to send</span> <button class="btn btn-primary btn-square btn-sm" aria-label="Send"> <ArrowUpIcon class="icon" /> </button> </div> </div> </form></template>입력란은 field-sizing: content가 적용된 <textarea>입니다. 한 줄에서 시작해 최대 10줄까지 늘어나며, 그 이후에는 스크롤됩니다. 최소 줄 수는 --composer-rows로, 최대 줄 수는 --composer-max-rows로 바꾸세요. 브라우저가 내용에 맞춰 입력란의 크기를 조절할 수 없으면 높이가 3줄로 유지되며, 그 이상은 스크롤됩니다.
버튼은 표면 가장자리에서 8px 안쪽에 배치되며, 모서리 곡선은 표면의 모서리와 같은 중심을 기준으로 그려집니다. 그래서 전송 버튼의 모서리 곡선이 표면의 모서리 곡선을 따라갑니다.
#첨부 항목
composer-attachments 영역은 입력란 위에 있으며 메시지에 첨부할 항목을 한 줄로 나열합니다. 파일을 나타내는 칩이나 썸네일을 배치하며, 공간이 부족하면 다음 줄로 넘어갑니다.
첨부 항목
<form class="composer max-w(480) mx-auto"> <div class="composer-attachments"> <span class="chip"> brief.pdf<button type="button" class="chip-remove" aria-label="Remove brief.pdf"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M4 4L12 12" /><path d="M4 12L12 4" /> </svg> </button> </span> <span class="chip"> notes.md<button type="button" class="chip-remove" aria-label="Remove notes.md"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M4 4L12 12" /><path d="M4 12L12 4" /> </svg> </button> </span> </div> <textarea class="composer-field" name="message" aria-label="Message">Summarise the brief against these notes, and list what the notes leave out. Keep it to one page so the team can read it before the review on Thursday.</textarea> <div class="composer-toolbar"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Attach a file"> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M3 8L13 8" /><path d="M8 3L8 13" /> </svg> </button> <div class="composer-end"> <span class="composer-hint">138 / 2000</span> <button class="btn btn-primary btn-sm">Send</button> </div> </div></form>import XIcon from '@master/icons-react/native/16/soft/x'import PlusIcon from '@master/icons-react/native/16/soft/plus'<form className="composer max-w(480) mx-auto"> <div className="composer-attachments"> <span className="chip"> brief.pdf<button type="button" className="chip-remove" aria-label="Remove brief.pdf"> <XIcon className="icon" /> </button> </span> <span className="chip"> notes.md<button type="button" className="chip-remove" aria-label="Remove notes.md"> <XIcon className="icon" /> </button> </span> </div> <textarea className="composer-field" name="message" aria-label="Message" defaultValue="Summarise the brief against these notes, and list what the notes leave out. Keep it to one page so the team can read it before the review on Thursday." /> <div className="composer-toolbar"> <button type="button" className="btn btn-quiet btn-square btn-sm" aria-label="Attach a file"> <PlusIcon className="icon" /> </button> <div className="composer-end"> <span className="composer-hint">138 / 2000</span> <button className="btn btn-primary btn-sm">Send</button> </div> </div></form><script> import XIcon from '@master/icons-svelte/native/16/soft/x' import PlusIcon from '@master/icons-svelte/native/16/soft/plus'</script><form class="composer max-w(480) mx-auto"> <div class="composer-attachments"> <span class="chip"> brief.pdf<button type="button" class="chip-remove" aria-label="Remove brief.pdf"> <XIcon class="icon" /> </button> </span> <span class="chip"> notes.md<button type="button" class="chip-remove" aria-label="Remove notes.md"> <XIcon class="icon" /> </button> </span> </div> <textarea class="composer-field" name="message" aria-label="Message">Summarise the brief against these notes, and list what the notes leave out. Keep it to one page so the team can read it before the review on Thursday.</textarea> <div class="composer-toolbar"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Attach a file"> <PlusIcon class="icon" /> </button> <div class="composer-end"> <span class="composer-hint">138 / 2000</span> <button class="btn btn-primary btn-sm">Send</button> </div> </div></form><script setup>import XIcon from '@master/icons-vue/native/16/soft/x'import PlusIcon from '@master/icons-vue/native/16/soft/plus'</script><template> <form class="composer max-w(480) mx-auto"> <div class="composer-attachments"> <span class="chip"> brief.pdf<button type="button" class="chip-remove" aria-label="Remove brief.pdf"> <XIcon class="icon" /> </button> </span> <span class="chip"> notes.md<button type="button" class="chip-remove" aria-label="Remove notes.md"> <XIcon class="icon" /> </button> </span> </div> <textarea class="composer-field" name="message" aria-label="Message">Summarise the brief against these notes, and list what the notes leave out. Keep it to one page so the team can read it before the review on Thursday.</textarea> <div class="composer-toolbar"> <button type="button" class="btn btn-quiet btn-square btn-sm" aria-label="Attach a file"> <PlusIcon class="icon" /> </button> <div class="composer-end"> <span class="composer-hint">138 / 2000</span> <button class="btn btn-primary btn-sm">Send</button> </div> </div> </form></template>#비활성 상태
입력란을 비활성화하면 표면이 오목하게 들어가고 더 이상 떠오르지 않습니다. 전송 버튼도 함께 비활성화하고, 그 이유를 플레이스홀더나 메시지 입력창 옆에 표시하세요.
비활성 상태
<form class="composer max-w(480) mx-auto"> <textarea class="composer-field" name="message" aria-label="Message" placeholder="Replies are closed for this thread" disabled></textarea> <div class="composer-toolbar"> <div class="composer-end"> <button class="btn btn-primary btn-square btn-sm" aria-label="Send" disabled> <svg class="icon" viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"> <path d="M13.6362 7.5189A0.4947 0.4947 0 0 0 13.5 7.5L2.4755 7.5006A0.5 0.5 0 0 0 2.4266 8.4946L2.5 8.5H13.5A0.4947 0.4947 0 0 0 13.6362 8.4811A0.7009 0.7009 0 0 0 13.6362 7.5189Z" fill="currentColor" stroke="none" fill-rule="evenodd" transform="rotate(-90 8 8)" /><path d="M8 4.5L13.2348 7.8313A0.2 0.2 0 0 1 13.2348 8.1687L8 11.5" transform="rotate(-90 8 8)" /> </svg> </button> </div> </div></form>import ArrowUpIcon from '@master/icons-react/native/16/soft/arrow-up'<form className="composer max-w(480) mx-auto"> <textarea className="composer-field" name="message" aria-label="Message" placeholder="Replies are closed for this thread" disabled>{``}</textarea> <div className="composer-toolbar"> <div className="composer-end"> <button className="btn btn-primary btn-square btn-sm" aria-label="Send" disabled> <ArrowUpIcon className="icon" /> </button> </div> </div></form><script> import ArrowUpIcon from '@master/icons-svelte/native/16/soft/arrow-up'</script><form class="composer max-w(480) mx-auto"> <textarea class="composer-field" name="message" aria-label="Message" placeholder="Replies are closed for this thread" disabled></textarea> <div class="composer-toolbar"> <div class="composer-end"> <button class="btn btn-primary btn-square btn-sm" aria-label="Send" disabled> <ArrowUpIcon class="icon" /> </button> </div> </div></form><script setup>import ArrowUpIcon from '@master/icons-vue/native/16/soft/arrow-up'</script><template> <form class="composer max-w(480) mx-auto"> <textarea class="composer-field" name="message" aria-label="Message" placeholder="Replies are closed for this thread" disabled></textarea> <div class="composer-toolbar"> <div class="composer-end"> <button class="btn btn-primary btn-square btn-sm" aria-label="Send" disabled> <ArrowUpIcon class="icon" /> </button> </div> </div> </form></template>#Enter 키로 전송
textarea에서 Enter를 누르면 줄바꿈이 입력됩니다. Enter로 전송하고 Shift+Enter로 줄바꿈하려면 이벤트 리스너 하나면 충분합니다. 입력기가 문자를 조합 중일 때는 이 처리를 건너뛰세요.
field.addEventListener('keydown', event => { if (event.key === 'Enter' && !event.shiftKey && !event.isComposing && event.keyCode !== 229) { event.preventDefault() field.form.requestSubmit() }})제품마다 키 동작이 다르므로 도구 옆에 composer-hint를 넣어 Enter로 전송하고 Shift+Enter로 줄을 바꾼다고 안내하세요.
#접근성
- 입력란에는 접근 가능한 이름이 필요합니다.
aria-label을 사용하거나 메시지 입력창 위에<label for>요소를 배치해 레이블이 보이도록 하세요. 플레이스홀더는 접근 가능한 이름으로 인정되지 않습니다. - 메시지 입력창은
<form>이므로 전송 버튼을 누르면 폼이 제출되며, 비밀번호 관리자나 브라우저 확장 프로그램도 이 폼을 찾을 수 있습니다. - 아이콘 버튼에는
aria-label이 지정됩니다. Tab 키로 이동하면 입력란 다음에 도구가 읽는 순서대로 포커스를 받습니다. - 표면의 패딩 영역을 클릭하는 것만으로는 입력란에 포커스가 가지 않습니다. 표면 전체를 클릭해 입력란에 포커스를 주려면 입력란을
<label>요소로 감싸세요. - 터치 화면에서도 입력란의 글자 크기는 그대로이며, 포커스를 받을 때 iOS가 페이지를 확대하지 않도록 페이지의 뷰포트에서 막습니다.
- 어시스턴트의 답변처럼 답변이 작성되는 동안에도 사용자가 다음 메시지를 쓸 수 있도록 입력란을 활성 상태로 두고, 전송 버튼 자리에 텍스트로 이름을 붙인 ‘중지’ 버튼을 두세요. 메시지 입력창 전체를 비활성화하면 중지 버튼과 초안도 함께 사용할 수 없게 됩니다. 답변을 중지했다면 완전한 답변이 아니라 일부라는 점을 알리세요.
#클래스
| 클래스 | 설명 |
|---|---|
composer | 양식에 적용하는 표면으로, 필드와 도구를 감싸며 주변보다 높게 표시됩니다. 필드의 포커스 표시를 이 표면에 그리고, 버튼의 모서리는 바깥 모서리와 중심을 맞춰 둥글게 처리합니다. |
composer-field | 별도의 배경이 없는 textarea입니다. 내용에 따라 --composer-rows에서 --composer-max-rows까지 줄 수가 늘어나고, 그 이상은 스크롤됩니다 |
composer-attachments | 메시지에 첨부할 항목을 칩이나 썸네일로 표시하는 필드 위의 행. 공간이 부족하면 다음 줄로 넘어갑니다. |
composer-toolbar | 필드 아래의 도구 행 |
composer-end | 보내기 버튼이 들어가는 도구 모음 끝쪽 그룹 |
composer-hint | 도구 옆에 모델 이름, 글자 수, 단축키 같은 정보를 낮은 강조도의 한 줄로 표시합니다. |
#사용자 지정 속성
| 속성 | 기본값 | 설명 |
|---|---|---|
--composer-rows | 1 | 필드의 초기 줄 수 |
--composer-max-rows | 10 | 필드에 스크롤이 생기기 전까지 표시되는 줄 수 |
--composer-radius | var(--radius-surface) | 표면의 모서리 반경 |
--composer-inset | .5rem | 표면의 안쪽 여백이자 버튼 모서리를 안쪽으로 들이는 기준값 |