heartcombo / simple_form

Forms made easy for Rails! It's tied to a simple DSL, with no opinion on markup.
http://blog.plataformatec.com.br/tag/simple_form
MIT License
8.21k stars 1.31k forks source link

Integrate `:rich_text_area` with placeholders #1842

Closed seanpdoyle closed 2 months ago

seanpdoyle commented 3 months ago

Trix (the rich text editor that's rendered by Action View's form builder) has supported the [placeholder] attribute since at least version 0.9.0 (and continues to support it in 2.1.1.

This commit enables :placeholder support in the SimpleForm::Inputs::RichTextAreaInput class to transform placeholder internationalization strings into trix-editor[placeholder] HTML attributes.

seanpdoyle commented 3 months ago

I had originally tried to add test coverage by making the following change:

diff --git a/test/inputs/rich_text_area_input_test.rb b/test/inputs/rich_text_area_input_test.rb
index 15d12a5..1fc3df7 100644
--- a/test/inputs/rich_text_area_input_test.rb
+++ b/test/inputs/rich_text_area_input_test.rb
@@ -12,4 +12,11 @@ class RichTextAreaInputTest < ActionView::TestCase
     with_input_for @user, :description, :text, placeholder: 'Put in some text'
     assert_select 'textarea.text[placeholder="Put in some text"]'
   end
+
+  test 'input generates a rich text area for rich text area attributes from placeholder translations' do
+    store_translations(:en, simple_form: { placeholders: { user: { description: "placeholder from i18n en.simple_form.placeholders.user.description" } } }) do
+      with_input_for @user, :description, :rich_text_area
+      assert_select 'trix-editor.rich_text_are="placeholder from i18n en.simple_form.placeholders.user.description"]'
+    end
+  end
 end

Unfortunately, Action Text and Trix are not available to the Simple Form test suite. Similarly, the existing coverage in test/inputs/rich_text_area_input_test.rb introduced in 3b3ab24 appears to make assertions about :text and <textarea> elements instead of :rich_text_area and <trix-editor> elements.

nashby commented 2 months ago

@seanpdoyle thank you! Yeah, I know about that rich_text_area spec, I'll try to look into it a bit later.