aboutsummaryrefslogtreecommitdiffstats
path: root/actionview
diff options
context:
space:
mode:
authorPaoMar <paomarcasadiego@gmail.com>2014-09-03 15:03:58 -0500
committerPaoMar <paomarcasadiego@gmail.com>2014-09-03 16:14:21 -0500
commitee61b76a810ad67ca064be2922a8b481fa840043 (patch)
treef653efa7c90db7f10f071502851942afb2b314c7 /actionview
parentb79ab4ca953949d953db772ba40bef2adc936fc3 (diff)
downloadrails-ee61b76a810ad67ca064be2922a8b481fa840043.tar.gz
rails-ee61b76a810ad67ca064be2922a8b481fa840043.tar.bz2
rails-ee61b76a810ad67ca064be2922a8b481fa840043.zip
Add support for ARIA attributes in tags
Diffstat (limited to 'actionview')
-rw-r--r--actionview/CHANGELOG.md12
-rw-r--r--actionview/lib/action_view/helpers/tag_helper.rb8
-rw-r--r--actionview/test/template/tag_helper_test.rb7
3 files changed, 23 insertions, 4 deletions
diff --git a/actionview/CHANGELOG.md b/actionview/CHANGELOG.md
index f5c520937c..5e0b134ba4 100644
--- a/actionview/CHANGELOG.md
+++ b/actionview/CHANGELOG.md
@@ -1,3 +1,15 @@
+* Add support for ARIA attributes in tags.
+
+ Example:
+
+ <%= f.text_field :name, aria: { required: "true", hidden: "false" } %>
+
+ now generates:
+
+ <input aria-hidden="false" aria-required="true" id="user_name" name="user[name]" type="text">
+
+ *Paola Garcia Casadiego*
+
* Provide a `builder` object when using the `label` form helper in block form.
The new `builder` object responds to `translation`, allowing I18n fallback support
diff --git a/actionview/lib/action_view/helpers/tag_helper.rb b/actionview/lib/action_view/helpers/tag_helper.rb
index 268558669e..f200d424c0 100644
--- a/actionview/lib/action_view/helpers/tag_helper.rb
+++ b/actionview/lib/action_view/helpers/tag_helper.rb
@@ -148,9 +148,9 @@ module ActionView
return if options.blank?
attrs = []
options.each_pair do |key, value|
- if key.to_s == 'data' && value.is_a?(Hash)
+ if (key.to_s == 'data' || key.to_s == 'aria') && value.is_a?(Hash)
value.each_pair do |k, v|
- attrs << data_tag_option(k, v, escape)
+ attrs << prefix_tag_option(key, k, v, escape)
end
elsif BOOLEAN_ATTRIBUTES.include?(key)
attrs << boolean_tag_option(key) if value
@@ -161,8 +161,8 @@ module ActionView
" #{attrs.sort! * ' '}" unless attrs.empty?
end
- def data_tag_option(key, value, escape)
- key = "data-#{key.to_s.dasherize}"
+ def prefix_tag_option(prefix, key, value, escape)
+ key = "#{prefix}-#{key.to_s.dasherize}"
unless value.is_a?(String) || value.is_a?(Symbol) || value.is_a?(BigDecimal)
value = value.to_json
end
diff --git a/actionview/test/template/tag_helper_test.rb b/actionview/test/template/tag_helper_test.rb
index 0ea669b3d0..ce89d5728e 100644
--- a/actionview/test/template/tag_helper_test.rb
+++ b/actionview/test/template/tag_helper_test.rb
@@ -156,4 +156,11 @@ class TagHelperTest < ActionView::TestCase
tag('a', { data => { a_float: 3.14, a_big_decimal: BigDecimal.new("-123.456"), a_number: 1, string: 'hello', symbol: :foo, array: [1, 2, 3], hash: { key: 'value'}, string_with_quotes: 'double"quote"party"' } })
}
end
+
+ def test_aria_attributes
+ ['aria', :aria].each { |aria|
+ assert_dom_equal '<a aria-a-float="3.14" aria-a-big-decimal="-123.456" aria-a-number="1" aria-array="[1,2,3]" aria-hash="{&quot;key&quot;:&quot;value&quot;}" aria-string-with-quotes="double&quot;quote&quot;party&quot;" aria-string="hello" aria-symbol="foo" />',
+ tag('a', { aria => { a_float: 3.14, a_big_decimal: BigDecimal.new("-123.456"), a_number: 1, string: 'hello', symbol: :foo, array: [1, 2, 3], hash: { key: 'value'}, string_with_quotes: 'double"quote"party"' } })
+ }
+ end
end