ruby-on-railssimple-formruby-on-rails-6trixactiontext

How do I customize the number of rows in my rich_text_area for simple_form?


I am using SimpleForm 5.0.2 along with ActionText.

I would like the main body field of my form to be multiple rows (say 10), but I can't figure out how to get it to work.

This is my current attempt:

<%= f.rich_text_area :body, class: 'form-control', name: "article-text", input_html: { rows: 10 }, placeholder: "Enter your article body here..." %>

That produces this HTML:

<trix-editor class="form-control" input_html="{:rows=>10}" placeholder="Enter your article body here..." id="article_body" input="article_body_trix_input_article" data-direct-upload-url="http://localhost:3000/rails/active_storage/direct_uploads" data-blob-url-template="http://localhost:3000/rails/active_storage/blobs/:signed_id/:filename" contenteditable="" role="textbox" trix-id="1" toolbar="trix-toolbar-1"></trix-editor>

Which looks like this:

simple-form-rich-text-area

Note that I also tried various iterations of input_html:, including but not limited to:

<%= ... input_html: { 'rows': '10' } ... %>

<%= ... input_html: { rows: "10" } ... %>

All to no avail.

How do I get this working?


Solution

  • It looks like the rich_text_area only accepts :class option so the :input_html does nothing here. But because the height is decided by CSS, we can achive what you want by overrding the default min-height CSS of trix-editor.

    In app/assets/stylesheets/actiontext.scss

    trix-editor {
      &.customized-min-height {
        min-height: 15em;
      }
    }
    

    In your view file

    f.rich_text_area :body, class: "form-control customized-min-height"