Skip to content

Commit 4765698

Browse files
committed
Document tag.attributes helper
The `tag.attributes` helper introduced in [rails#40657][] is implemented on a `:nodoc:`-private `TagBuilder` class, so the documentation for the method is omitted when generating the API Guides HTML pages. This commit extends the `ActionView::Helpers::TagHelper` module documentation comment to mention the new attribute building capabilities, along with some examples. [rails#40657]: rails#40657
1 parent 396b22d commit 4765698

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

actionview/lib/action_view/helpers/tag_helper.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,20 @@ def method_missing(called, *args, **options, &block)
235235
# # A void element:
236236
# tag.br # => <br>
237237
#
238+
# === Building HTML attributes
239+
#
240+
# Transforms a Hash into HTML attributes, ready to be interpolated into
241+
# ERB. Includes or omits boolean attributes based on their truthiness.
242+
# Transforms keys nested within
243+
# <tt>aria:</tt> or <tt>data:</tt> objects into `aria-` and `data-`
244+
# prefixed attributes:
245+
#
246+
# <input <%= tag.attributes(type: :text, aria: { label: "Search" }) %>>
247+
# # => <input type="text" aria-label="Search">
248+
#
249+
# <button <%= tag.attributes id: "call-to-action", disabled: false, aria: { expanded: false } %> class="primary">Get Started!</button>
250+
# => <button id="call-to-action" aria-expanded="false" class="primary">Get Started!</button>
251+
#
238252
# === Legacy syntax
239253
#
240254
# The following format is for legacy syntax support. It will be deprecated in future versions of Rails.

0 commit comments

Comments
 (0)