diff --git a/actiontext/app/helpers/action_text/tag_helper.rb b/actiontext/app/helpers/action_text/tag_helper.rb index 8434f2c6117db9680712a2e8b5f41ebd5d41fa5a..1dc6202ae1e5908e819cca61e936488e754da1dc 100644 --- a/actiontext/app/helpers/action_text/tag_helper.rb +++ b/actiontext/app/helpers/action_text/tag_helper.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require "action_view/helpers/tags/placeholderable" + module ActionText module TagHelper cattr_accessor(:id, instance_accessor: false) { 0 } @@ -35,6 +37,8 @@ def rich_text_area_tag(name, value = nil, options = {}) module ActionView::Helpers class Tags::ActionText < Tags::Base + include Tags::Placeholderable + delegate :dom_id, to: ActionView::RecordIdentifier def render diff --git a/actiontext/test/template/form_helper_test.rb b/actiontext/test/template/form_helper_test.rb index a8c7a4dae2997311a46d8fc64a02c983b2abf142..cf7e4c0c695ac63df342fef2057252f46f4bf20b 100644 --- a/actiontext/test/template/form_helper_test.rb +++ b/actiontext/test/template/form_helper_test.rb @@ -5,6 +5,26 @@ class ActionText::FormHelperTest < ActionView::TestCase tests ActionText::TagHelper + def form_with(*) + @output_buffer = super + end + + teardown do + I18n.backend.reload! + end + + setup do + I18n.backend.store_translations("placeholder", + activerecord: { + attributes: { + message: { + title: "Story title" + } + } + } + ) + end + test "form with rich text area" do form_with model: Message.new, scope: :message do |form| form.rich_text_area :content @@ -61,7 +81,33 @@ class ActionText::FormHelperTest < ActionView::TestCase output_buffer end - def form_with(*) - @output_buffer = super + test "form with rich text area having placeholder without locale" do + form_with model: Message.new, scope: :message do |form| + form.rich_text_area :content, placeholder: true + end + + assert_dom_equal \ + '
' \ + '' \ + '' \ + "" \ + "
", + output_buffer + end + + test "form with rich text area having placeholder with locale" do + I18n.with_locale :placeholder do + form_with model: Message.new, scope: :message do |form| + form.rich_text_area :title, placeholder: true + end + end + + assert_dom_equal \ + '
' \ + '' \ + '' \ + "" \ + "
", + output_buffer end end