I am experimenting with theming comments for Drulma and I noticed that the textarea display goes off screen because there is no template override.
I created a textarea.html.twig:
{#
/**
* @file
* Theme override for a 'textarea' #type form element.
*
* Available variables
* - wrapper_attributes: A list of HTML attributes for the wrapper element.
* - attributes: A list of HTML attributes for the textarea element.
* - resizable: An indicator for whether the textarea is resizable.
* - required: An indicator for whether the textarea is required.
* - value: The textarea content.
*
* @see template_preprocess_textarea()
*/
#}
{%
set classes = [
'textarea',
'form-textarea',
'form-control',
resizable ? 'resize-' ~ resizable,
required ? 'required',
]
%}
<div{{ wrapper_attributes.addClass('form-textarea-wrapper','control') }}>
<textarea{{ attributes.addClass(classes) }}>{{ value }}</textarea>
</div>
This is just the core template with an added textarea class for the textarea and control class for the wrapper div.
Textarea support is a necessity for many sites so I submit this for general inclusion into the theme.
| Comment | File | Size | Author |
|---|---|---|---|
| textarea_inside.PNG | 4.14 KB | ptmkenny | |
| textarea_outside.PNG | 4.17 KB | ptmkenny |
Comments
Comment #2
rodrigoaguileraThis was in my todo list for a while since it is a basic element that was left without the Bulma styling.
The template override is a great approach but usually when is just two classes I prefer to use template_preprocess_textarea().
You can see the change here
https://gitlab.com/upstreamable/drulma/-/commit/fd1a1f9d4bd7d79a42b5d6a0...
Thank you for bringing this into my radar.
Comment #3
ptmkenny commentedThanks, that's great! Yes, preprocess is a much more concise way to do this.