Textarea
Textarea 컴포넌트는 사용자가 한 줄을 넘는 긴 텍스트를 입력해야 할 때 쓰는 컴포넌트예요.
출처: 문서
본문
<div class="govuk-form-group">
<h1 class="govuk-label-wrapper">
<label class="govuk-label govuk-label--l" for="more-detail">
Can you provide more detail?
</label>
</h1>
<div id="more-detail-hint" class="govuk-hint">
Do not include personal or financial information, like your National Insurance number or credit card details
</div>
<textarea class="govuk-textarea" id="more-detail" name="moreDetail" rows="5" aria-describedby="more-detail-hint"></textarea>
</div>
{% from "govuk/components/textarea/macro.njk" import govukTextarea %}
{{ govukTextarea({
name: "moreDetail",
id: "more-detail",
label: {
text: "Can you provide more detail?",
classes: "govuk-label--l",
isPageHeading: true
},
hint: {
text: "Do not include personal or financial information, like your National Insurance number or credit card details"
}
}) }}
When to use this component
textarea 컴포넌트는 사용자가 한 줄을 넘는 양의 텍스트를 입력해야 할 때 사용해요.
When not to use this component
사용자는 개방형 질문(open-ended question)에 답하기 어려워할 수 있어요. 하나의 복잡한 질문을 일련의 단순한 질문들로 쪼개는 게 더 나을 수도 있어요. 예를 들어 Radios 컴포넌트로 사용자가 옵션에서 선택할 수 있게 하는 경우처럼요.
If you need to ask an open question
전화번호나 이름처럼 한 줄을 넘지 않는 짧은 답변을 입력하게 해야 한다면 textarea 컴포넌트를 사용하지 마세요. 그런 경우에는 Text input 컴포넌트를 사용해야 해요.
How it works
textarea에는 label을 반드시 붙여야 해요. placeholder 텍스트는 label의 적절한 대체물이 아니에요. 사용자가 textarea 안을 클릭하면 사라지기 때문이에요.
label은 가리키는 textarea 위쪽에 정렬해야 해요. label은 짧고 직접적이어야 하며 문장형 대소문자(sentence case)로 써야 해요. label 끝에 콜론(:)은 붙이지 마세요.
textarea 컴포넌트를 쓰는 방법은 두 가지예요. HTML을 쓸 수도 있고, Nunjucks나 GOV.UK Prototype Kit을 쓰고 있다면 Nunjucks 매크로를 쓸 수도 있어요.
<div class="govuk-form-group">
<h1 class="govuk-label-wrapper">
<label class="govuk-label govuk-label--l" for="more-detail">
Can you provide more detail?
</label>
</h1>
<div id="more-detail-hint" class="govuk-hint">
Do not include personal or financial information, like your National Insurance number or credit card details
</div>
<textarea class="govuk-textarea" id="more-detail" name="moreDetail" rows="5" aria-describedby="more-detail-hint"></textarea>
</div>
{% from "govuk/components/textarea/macro.njk" import govukTextarea %}
{{ govukTextarea({
name: "moreDetail",
id: "more-detail",
label: {
text: "Can you provide more detail?",
classes: "govuk-label--l",
isPageHeading: true
},
hint: {
text: "Do not include personal or financial information, like your National Insurance number or credit card details"
}
}) }}
Use appropriately-sized textareas
textarea의 높이를 사용자가 입력할 것으로 예상되는 텍스트 양에 비례하게 만드세요. rows 속성을 지정해서 textarea의 높이를 설정할 수 있어요.
<div class="govuk-form-group">
<h1 class="govuk-label-wrapper">
<label class="govuk-label govuk-label--l" for="more-detail">
Can you provide more detail?
</label>
</h1>
<div id="more-detail-hint" class="govuk-hint">
Do not include personal or financial information, like your National Insurance number or credit card details
</div>
<textarea class="govuk-textarea" id="more-detail" name="moreDetail" rows="8" aria-describedby="more-detail-hint"></textarea>
</div>
{% from "govuk/components/textarea/macro.njk" import govukTextarea %}
{{ govukTextarea({
name: "moreDetail",
id: "more-detail",
rows: "8",
label: {
text: "Can you provide more detail?",
classes: "govuk-label--l",
isPageHeading: true
},
hint: {
text: "Do not include personal or financial information, like your National Insurance number or credit card details"
}
}) }}
Do not disable copy and paste
사용자는 종종 textarea에 정보를 복사·붙여넣기 해야 하므로, 그걸 막지 마세요.
If you’re asking more than one question on the page
페이지에서 둘 이상의 질문을 묻는다면 ``의 내용을 페이지 제목으로 설정하지 마세요. Question pages에서 여러 질문을 묻는 방법에 대해 더 읽어보세요.
<div class="govuk-form-group">
<label class="govuk-label" for="more-detail">
Can you provide more detail?
</label>
<textarea class="govuk-textarea" id="more-detail" name="moreDetail" rows="5"></textarea>
</div>
{% from "govuk/components/textarea/macro.njk" import govukTextarea %}
{{ govukTextarea({
name: "moreDetail",
id: "more-detail",
label: {
text: "Can you provide more detail?"
}
}) }}
Limiting the number of characters
사용자가 입력할 수 있는 문자 수를 제한할 합당한 이유가 있다면 Character count 컴포넌트를 사용할 수 있어요.
Error messages
오류 메시지는 다음과 같이 스타일링해야 해요:
<div class="govuk-form-group govuk-form-group--error">
<h1 class="govuk-label-wrapper">
<label class="govuk-label govuk-label--l" for="more-detail">
Can you provide more detail?
</label>
</h1>
<div id="more-detail-hint" class="govuk-hint">
Do not include personal or financial information, like your National Insurance number or credit card details
</div>
<p id="more-detail-error" class="govuk-error-message">
<span class="govuk-visually-hidden">Error:</span> Enter more detail
</p>
<textarea class="govuk-textarea govuk-textarea--error" id="more-detail" name="moreDetail" rows="5" aria-describedby="more-detail-hint more-detail-error"></textarea>
</div>
{% from "govuk/components/textarea/macro.njk" import govukTextarea %}
{{ govukTextarea({
name: "moreDetail",
id: "more-detail",
label: {
text: "Can you provide more detail?",
classes: "govuk-label--l",
isPageHeading: true
},
hint: {
text: "Do not include personal or financial information, like your National Insurance number or credit card details"
},
errorMessage: {
text: "Enter more detail"
}
}) }}
오류가 Error message 컴포넌트의 안내를 따르고, 각 오류 상태에 맞는 구체적인 오류 메시지가 있게 하세요.
If the input is empty
'[무엇이든]을 입력하세요(Say ‘Enter [whatever it is]’)'라고 말하세요. 예: '요약을 입력하세요(Enter summary)'.
If the input is too long
'[무엇이든]은 [숫자]자 이하여야 합니다([whatever it is] must be [number] characters or less)'라고 말하세요. 예: '요약은 400자 이하여야 합니다(Summary must be 400 characters or less)'.
If the input is too short
'[무엇이든]은 [숫자]자 이상이어야 합니다([whatever it is] must be [number] characters or more)'라고 말하세요. 예: '요약은 10자 이상이어야 합니다(Summary must be 10 characters or more)'.
If the input is too long or too short
'[무엇이든]은 [숫자]자에서 [숫자]자 사이여야 합니다([whatever it is] must be between [number] and [number] characters)'라고 말하세요. 예: '요약은 10자에서 400자 사이여야 합니다(Summary must be between 10 and 400 characters)'.
If the input uses characters that are not allowed and you know what the characters are
'[무엇이든]에는 [문자]가 포함되면 안 됩니다([whatever it is] must not include [characters])'라고 말하세요. 예: '요약에는 è와 £가 포함되면 안 됩니다(Summary must not include è and £)'.
If the input uses characters that are not allowed and you do not know what the characters are
'[무엇이든]에는 [허용 문자 목록]만 포함되어야 합니다([whatever it is] must only include [list of allowed characters])'라고 말하세요. 예: '요약에는 a부터 z까지의 문자, 하이픈, 공백, 아포스트로피만 포함되어야 합니다(Summary must only include letters a to z, hyphens, spaces and apostrophes)'.
더 알아보기 (Learn more)
- textarea의 크기, label, 오류 메시지 작성법에 대한 자세한 원문은 위 출처 문서를 참고하세요.