Skip to content

Integrate :rich_text_area with placeholders#1842

Merged
nashby merged 1 commit intoheartcombo:mainfrom
seanpdoyle:rich-text-area-placeholder
Jun 24, 2024
Merged

Integrate :rich_text_area with placeholders#1842
nashby merged 1 commit intoheartcombo:mainfrom
seanpdoyle:rich-text-area-placeholder

Conversation

@seanpdoyle
Copy link
Copy Markdown
Contributor

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.

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.

[0.9.0]: https://github.com/basecamp/trix/tree/0.9.0?tab=readme-ov-file#creating-an-editor
[2.1.1]: https://github.com/basecamp/trix/tree/v2.1.1?tab=readme-ov-file#creating-an-editor
@seanpdoyle
Copy link
Copy Markdown
Contributor Author

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 nashby merged commit ef9f350 into heartcombo:main Jun 24, 2024
@nashby
Copy link
Copy Markdown
Collaborator

nashby commented Jun 24, 2024

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

@seanpdoyle seanpdoyle deleted the rich-text-area-placeholder branch June 24, 2024 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants