Skip to content

Commit f9c51ec

Browse files
committed
Rename text_area to textarea
Follow-up to [rails#52432][] Related to [rails#52430][] Helpers like `text_area_tag` construct [textarea][] elements. This commit renames all view helper and form builder methods to replace occurrences of `text_area` with `textarea`. In the same style, this commit also renames the `rich_text`-prefixed helpers to utilize a `textarea` suffix instead of the existing `text_area` suffix. To preserve backwards compatibility, this commit defines aliases for the existing `text_area` format. [rails#52432]: rails#52432 [rails#52430]: rails#52430 [textarea]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/textarea
1 parent 9674fa9 commit f9c51ec

File tree

26 files changed

+238
-213
lines changed

26 files changed

+238
-213
lines changed

actionmailbox/app/views/rails/conductor/action_mailbox/inbound_emails/new.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040

4141
<div>
4242
<%= form.label :body, "Body" %><br>
43-
<%= form.text_area :body, size: "40x20", value: params[:body] %>
43+
<%= form.textarea :body, size: "40x20", value: params[:body] %>
4444
</div>
4545

4646
<div>

actionmailbox/app/views/rails/conductor/action_mailbox/inbound_emails/sources/new.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<%= form_with(url: main_app.rails_conductor_inbound_email_sources_path, local: true) do |form| %>
66
<div>
77
<%= form.label :source, "Source" %><br>
8-
<%= form.text_area :source, size: "80x60" %>
8+
<%= form.textarea :source, size: "80x60" %>
99
</div>
1010

1111
<%= form.submit "Deliver inbound email" %>

actiontext/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
* Rename `rich_text_area` methods into `rich_textarea`
2+
3+
Old names are still available as aliases.
4+
5+
*Sean Doyle*
6+
7+
18
* Only sanitize `content` attribute when present in attachments.
29

310
*Petrik de Heus*

actiontext/app/helpers/action_text/tag_helper.rb

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ module TagHelper
2424
#
2525
# #### Example
2626
#
27-
# rich_text_area_tag "content", message.content
27+
# rich_textarea_tag "content", message.content
2828
# # <input type="hidden" name="content" id="trix_input_post_1">
2929
# # <trix-editor id="content" input="trix_input_post_1" class="trix-content" ...></trix-editor>
30-
def rich_text_area_tag(name, value = nil, options = {})
30+
def rich_textarea_tag(name, value = nil, options = {})
3131
options = options.symbolize_keys
3232
form = options.delete(:form)
3333

@@ -43,6 +43,7 @@ def rich_text_area_tag(name, value = nil, options = {})
4343

4444
input_tag + editor_tag
4545
end
46+
alias_method :rich_text_area_tag, :rich_textarea_tag
4647
end
4748
end
4849

@@ -56,7 +57,7 @@ def render
5657
options = @options.stringify_keys
5758
add_default_name_and_id(options)
5859
options["input"] ||= dom_id(object, [options["id"], :trix_input].compact.join("_")) if object
59-
html_tag = @template_object.rich_text_area_tag(options.delete("name"), options.fetch("value") { value }, options.except("value"))
60+
html_tag = @template_object.rich_textarea_tag(options.delete("name"), options.fetch("value") { value }, options.except("value"))
6061
error_wrapping(html_tag)
6162
end
6263
end
@@ -76,28 +77,30 @@ module FormHelper
7677
#
7778
#
7879
# #### Example
79-
# rich_text_area :message, :content
80+
# rich_textarea :message, :content
8081
# # <input type="hidden" name="message[content]" id="message_content_trix_input_message_1">
8182
# # <trix-editor id="content" input="message_content_trix_input_message_1" class="trix-content" ...></trix-editor>
8283
#
83-
# rich_text_area :message, :content, value: "<h1>Default message</h1>"
84+
# rich_textarea :message, :content, value: "<h1>Default message</h1>"
8485
# # <input type="hidden" name="message[content]" id="message_content_trix_input_message_1" value="<h1>Default message</h1>">
8586
# # <trix-editor id="content" input="message_content_trix_input_message_1" class="trix-content" ...></trix-editor>
86-
def rich_text_area(object_name, method, options = {})
87+
def rich_textarea(object_name, method, options = {})
8788
Tags::ActionText.new(object_name, method, self, options).render
8889
end
90+
alias_method :rich_text_area, :rich_textarea
8991
end
9092

9193
class FormBuilder
92-
# Wraps ActionView::Helpers::FormHelper#rich_text_area for form builders:
94+
# Wraps ActionView::Helpers::FormHelper#rich_textarea for form builders:
9395
#
9496
# <%= form_with model: @message do |f| %>
95-
# <%= f.rich_text_area :content %>
97+
# <%= f.rich_textarea :content %>
9698
# <% end %>
9799
#
98100
# Please refer to the documentation of the base helper for details.
99-
def rich_text_area(method, options = {})
100-
@template.rich_text_area(@object_name, method, objectify_options(options))
101+
def rich_textarea(method, options = {})
102+
@template.rich_textarea(@object_name, method, objectify_options(options))
101103
end
104+
alias_method :rich_text_area, :rich_textarea
102105
end
103106
end

actiontext/lib/action_text/system_test_helper.rb

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,45 @@ module SystemTestHelper
1717
# Examples:
1818
#
1919
# # <trix-editor id="message_content" ...></trix-editor>
20-
# fill_in_rich_text_area "message_content", with: "Hello <em>world!</em>"
20+
# fill_in_rich_textarea "message_content", with: "Hello <em>world!</em>"
2121
#
2222
# # <trix-editor placeholder="Your message here" ...></trix-editor>
23-
# fill_in_rich_text_area "Your message here", with: "Hello <em>world!</em>"
23+
# fill_in_rich_textarea "Your message here", with: "Hello <em>world!</em>"
2424
#
2525
# # <label for="message_content">Message content</label>
2626
# # <trix-editor id="message_content" ...></trix-editor>
27-
# fill_in_rich_text_area "Message content", with: "Hello <em>world!</em>"
27+
# fill_in_rich_textarea "Message content", with: "Hello <em>world!</em>"
2828
#
2929
# # <trix-editor aria-label="Message content" ...></trix-editor>
30-
# fill_in_rich_text_area "Message content", with: "Hello <em>world!</em>"
30+
# fill_in_rich_textarea "Message content", with: "Hello <em>world!</em>"
3131
#
3232
# # <input id="trix_input_1" name="message[content]" type="hidden">
3333
# # <trix-editor input="trix_input_1"></trix-editor>
34-
# fill_in_rich_text_area "message[content]", with: "Hello <em>world!</em>"
35-
def fill_in_rich_text_area(locator = nil, with:)
36-
find(:rich_text_area, locator).execute_script("this.editor.loadHTML(arguments[0])", with.to_s)
34+
# fill_in_rich_textarea "message[content]", with: "Hello <em>world!</em>"
35+
def fill_in_rich_textarea(locator = nil, with:)
36+
find(:rich_textarea, locator).execute_script("this.editor.loadHTML(arguments[0])", with.to_s)
3737
end
38+
alias_method :fill_in_rich_text_area, :fill_in_rich_textarea
3839
end
3940
end
4041

41-
Capybara.add_selector :rich_text_area do
42-
label "rich-text area"
43-
xpath do |locator|
44-
if locator.nil?
45-
XPath.descendant(:"trix-editor")
46-
else
47-
input_located_by_name = XPath.anywhere(:input).where(XPath.attr(:name) == locator).attr(:id)
48-
input_located_by_label = XPath.anywhere(:label).where(XPath.string.n.is(locator)).attr(:for)
42+
%i[rich_textarea rich_text_area].each do |rich_textarea|
43+
Capybara.add_selector rich_textarea do
44+
label "rich-text area"
45+
xpath do |locator|
46+
if locator.nil?
47+
XPath.descendant(:"trix-editor")
48+
else
49+
input_located_by_name = XPath.anywhere(:input).where(XPath.attr(:name) == locator).attr(:id)
50+
input_located_by_label = XPath.anywhere(:label).where(XPath.string.n.is(locator)).attr(:for)
4951

50-
XPath.descendant(:"trix-editor").where \
51-
XPath.attr(:id).equals(locator) |
52-
XPath.attr(:placeholder).equals(locator) |
53-
XPath.attr(:"aria-label").equals(locator) |
54-
XPath.attr(:input).equals(input_located_by_name) |
55-
XPath.attr(:id).equals(input_located_by_label)
52+
XPath.descendant(:"trix-editor").where \
53+
XPath.attr(:id).equals(locator) |
54+
XPath.attr(:placeholder).equals(locator) |
55+
XPath.attr(:"aria-label").equals(locator) |
56+
XPath.attr(:input).equals(input_located_by_name) |
57+
XPath.attr(:id).equals(input_located_by_label)
58+
end
5659
end
5760
end
5861
end

actiontext/test/dummy/app/views/messages/_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<div class="field">
2020
<%= form.label :content, "Message content label" %>
21-
<%= form.rich_text_area :content, class: "trix-content",
21+
<%= form.rich_textarea :content, class: "trix-content",
2222
placeholder: "Your message here", aria: { label: "Message content aria-label" } %>
2323
</div>
2424

actiontext/test/system/system_test_helper_test.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,36 @@ def setup
99

1010
test "filling in a rich-text area by ID" do
1111
assert_selector "trix-editor#message_content"
12-
fill_in_rich_text_area "message_content", with: "Hello world!"
12+
fill_in_rich_textarea "message_content", with: "Hello world!"
1313
assert_selector :field, "message[content]", with: /Hello world!/, type: "hidden"
1414
end
1515

1616
test "filling in a rich-text area by placeholder" do
1717
assert_selector "trix-editor[placeholder='Your message here']"
18-
fill_in_rich_text_area "Your message here", with: "Hello world!"
18+
fill_in_rich_textarea "Your message here", with: "Hello world!"
1919
assert_selector :field, "message[content]", with: /Hello world!/, type: "hidden"
2020
end
2121

2222
test "filling in a rich-text area by aria-label" do
2323
assert_selector "trix-editor[aria-label='Message content aria-label']"
24-
fill_in_rich_text_area "Message content aria-label", with: "Hello world!"
24+
fill_in_rich_textarea "Message content aria-label", with: "Hello world!"
2525
assert_selector :field, "message[content]", with: /Hello world!/, type: "hidden"
2626
end
2727

2828
test "filling in a rich-text area by label" do
2929
assert_selector "label", text: "Message content label"
30-
fill_in_rich_text_area "Message content label", with: "Hello world!"
30+
fill_in_rich_textarea "Message content label", with: "Hello world!"
3131
assert_selector :field, "message[content]", with: /Hello world!/, type: "hidden"
3232
end
3333

3434
test "filling in a rich-text area by input name" do
3535
assert_selector "trix-editor[input]"
36-
fill_in_rich_text_area "message[content]", with: "Hello world!"
36+
fill_in_rich_textarea "message[content]", with: "Hello world!"
3737
assert_selector :field, "message[content]", with: /Hello world!/, type: "hidden"
3838
end
3939

4040
test "filling in the only rich-text area" do
41-
fill_in_rich_text_area with: "Hello world!"
41+
fill_in_rich_textarea with: "Hello world!"
4242
assert_selector :field, "message[content]", with: /Hello world!/, type: "hidden"
4343
end
4444
end

actiontext/test/template/form_helper_test.rb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ def form_with(*, **)
2525
)
2626
end
2727

28-
test "#rich_text_area_tag helper" do
28+
test "#rich_textarea_tag helper" do
2929
message = Message.new
3030

31-
concat rich_text_area_tag :content, message.content, { input: "trix_input_1" }
31+
concat rich_textarea_tag :content, message.content, { input: "trix_input_1" }
3232

3333
assert_dom_equal \
3434
'<input type="hidden" name="content" id="trix_input_1" autocomplete="off" />' \
@@ -37,8 +37,8 @@ def form_with(*, **)
3737
output_buffer
3838
end
3939

40-
test "#rich_text_area helper" do
41-
concat rich_text_area :message, :content, input: "trix_input_1"
40+
test "#rich_textarea helper" do
41+
concat rich_textarea :message, :content, input: "trix_input_1"
4242

4343
assert_dom_equal \
4444
'<input type="hidden" name="message[content]" id="trix_input_1" autocomplete="off" />' \
@@ -47,10 +47,10 @@ def form_with(*, **)
4747
output_buffer
4848
end
4949

50-
test "#rich_text_area helper renders the :value argument into the hidden field" do
50+
test "#rich_textarea helper renders the :value argument into the hidden field" do
5151
message = Message.new content: "<h1>hello world</h1>"
5252

53-
concat rich_text_area :message, :title, value: message.content, input: "trix_input_1"
53+
concat rich_textarea :message, :title, value: message.content, input: "trix_input_1"
5454

5555
assert_dom_equal \
5656
'<input type="hidden" name="message[title]" id="trix_input_1" value="&lt;h1&gt;hello world&lt;/h1&gt;" autocomplete="off" />' \
@@ -61,7 +61,7 @@ def form_with(*, **)
6161

6262
test "form with rich text area" do
6363
form_with model: Message.new, scope: :message do |form|
64-
form.rich_text_area :content
64+
form.rich_textarea :content
6565
end
6666

6767
assert_dom_equal \
@@ -75,7 +75,7 @@ def form_with(*, **)
7575

7676
test "form with rich text area having class" do
7777
form_with model: Message.new, scope: :message do |form|
78-
form.rich_text_area :content, class: "custom-class"
78+
form.rich_textarea :content, class: "custom-class"
7979
end
8080

8181
assert_dom_equal \
@@ -92,7 +92,7 @@ def form_with(*, **)
9292
message.errors.add(:content, :blank)
9393

9494
form_with model: message, scope: :message do |form|
95-
form.rich_text_area :content
95+
form.rich_textarea :content
9696
end
9797

9898
assert_dom_equal \
@@ -108,7 +108,7 @@ def form_with(*, **)
108108

109109
test "form with rich text area for non-attribute" do
110110
form_with model: Message.new, scope: :message do |form|
111-
form.rich_text_area :not_an_attribute
111+
form.rich_textarea :not_an_attribute
112112
end
113113

114114
assert_dom_equal \
@@ -122,7 +122,7 @@ def form_with(*, **)
122122

123123
test "modelless form with rich text area" do
124124
form_with url: "/messages", scope: :message do |form|
125-
form.rich_text_area :content, { input: "trix_input_2" }
125+
form.rich_textarea :content, { input: "trix_input_2" }
126126
end
127127

128128
assert_dom_equal \
@@ -136,7 +136,7 @@ def form_with(*, **)
136136

137137
test "form with rich text area having placeholder without locale" do
138138
form_with model: Message.new, scope: :message do |form|
139-
form.rich_text_area :content, placeholder: true
139+
form.rich_textarea :content, placeholder: true
140140
end
141141

142142
assert_dom_equal \
@@ -151,7 +151,7 @@ def form_with(*, **)
151151
test "form with rich text area having placeholder with locale" do
152152
I18n.with_locale :placeholder do
153153
form_with model: Message.new, scope: :message do |form|
154-
form.rich_text_area :title, placeholder: true
154+
form.rich_textarea :title, placeholder: true
155155
end
156156
end
157157

@@ -166,7 +166,7 @@ def form_with(*, **)
166166

167167
test "form with rich text area with value" do
168168
form_with model: Message.new, scope: :message do |form|
169-
form.rich_text_area :title, value: "<h1>hello world</h1>"
169+
form.rich_textarea :title, value: "<h1>hello world</h1>"
170170
end
171171

172172
assert_dom_equal \
@@ -180,7 +180,7 @@ def form_with(*, **)
180180

181181
test "form with rich text area with form attribute" do
182182
form_with model: Message.new, scope: :message do |form|
183-
form.rich_text_area :title, form: "other_form"
183+
form.rich_textarea :title, form: "other_form"
184184
end
185185

186186
assert_dom_equal \
@@ -194,7 +194,7 @@ def form_with(*, **)
194194

195195
test "form with rich text area with data[direct_upload_url]" do
196196
form_with model: Message.new, scope: :message do |form|
197-
form.rich_text_area :content, data: { direct_upload_url: "http://test.host/direct_uploads" }
197+
form.rich_textarea :content, data: { direct_upload_url: "http://test.host/direct_uploads" }
198198
end
199199

200200
assert_dom_equal \
@@ -208,7 +208,7 @@ def form_with(*, **)
208208

209209
test "form with rich text area with data[blob_url_template]" do
210210
form_with model: Message.new, scope: :message do |form|
211-
form.rich_text_area :content, data: { blob_url_template: "http://test.host/blobs/:signed_id/:filename" }
211+
form.rich_textarea :content, data: { blob_url_template: "http://test.host/blobs/:signed_id/:filename" }
212212
end
213213

214214
assert_dom_equal \

actionview/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
* Rename `text_area` methods into `textarea`
2+
3+
Old names are still available as aliases.
4+
5+
*Sean Doyle*
6+
17
* Rename `check_box*` methods into `checkbox*`.
28

39
Old names are still available as aliases.

0 commit comments

Comments
 (0)