Skip to content

Textarea

Textarea
Thymeleaf source
<sl:label for="message">Message</sl:label>
<sl:textarea th:field="*{message}" placeholder="Type your message here."/>
Rendered HTML
<label class="label" for="message">Message</label>
<textarea class="textarea" id="message" name="message" placeholder="Type your message here."></textarea>

The textarea grows with its content in browsers that support field-sizing; elsewhere it keeps its height and scrolls. rows sets a starting height.

With th:field, Spring fills the textarea from the field. Without it, the component’s content is the initial text:

Initial textWithout th:field, the content is the initial text.
Thymeleaf source
<sl:label for="textarea-notes">Notes</sl:label>
<sl:textarea id="textarea-notes" name="notes">Leave the parcel at the back door.</sl:textarea>
Rendered HTML
<label class="label" for="textarea-notes">Notes</label>
<textarea class="textarea" id="textarea-notes" name="notes">Leave the parcel at the back door.</textarea>

As with the input, a field with errors marks the textarea aria-invalid="true".

Invalid
Thymeleaf source
<sl:label for="message">Message</sl:label>
<sl:textarea th:field="*{message}"/>
Rendered HTML
<label class="label" for="textarea-invalid">Message</label>
<textarea class="textarea" id="textarea-invalid" name="message" aria-invalid="true"></textarea>

As the input: faded, not focusable and not submitted; lyra adds a grey background.

Disabled
Thymeleaf source
<sl:label for="textarea-disabled">Message</sl:label>
<sl:textarea id="textarea-disabled" name="message" disabled/>
Rendered HTML
<label class="label" for="textarea-disabled">Message</label>
<textarea class="textarea" id="textarea-disabled" name="message" disabled></textarea>

As the input: a muted background and full text colour; it takes focus and is submitted.

Read-only
Thymeleaf source
<sl:label for="textarea-instructions">Delivery instructions</sl:label>
<sl:textarea id="textarea-instructions" name="instructions" readonly>Leave the parcel with the neighbours at number 12.</sl:textarea>
Rendered HTML
<label class="label" for="textarea-instructions">Delivery instructions</label>
<textarea class="textarea" id="textarea-instructions" name="instructions" readonly>Leave the parcel with the neighbours at number 12.</textarea>

sl:textarea declares no props; every attribute passes through.