From 9a74c7b99bf0ac901f86bb38372a68e157cf9c73 Mon Sep 17 00:00:00 2001 From: Cameron Cundiff Date: Wed, 16 Aug 2017 14:34:02 -0400 Subject: Do not generate default alt text in image tags - Auto-generating content from the filename of an image is not suitable alternative text; alt text that isn't fully considered can be distracting and fatiguing for screen readers users (blind, low vision, dyslexic people). - Setting a filename fallback short circuits screen reader default behavior and configuration for blank descriptions. - Setting poor defaults also creates false negatives for accessibility linting and testing software, that makes it harder to improve application accessibility. *** - After this change, if authors leave images without alt text, screen readers will fallback to default behavior for missing alt text. - Also with this change, Automated linting and testing tools will correctly generate warnings. [Fixes #30096] --- .../lib/action_view/helpers/asset_tag_helper.rb | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'actionview/lib/action_view/helpers') diff --git a/actionview/lib/action_view/helpers/asset_tag_helper.rb b/actionview/lib/action_view/helpers/asset_tag_helper.rb index 82b0fcbf2e..4557c76dfe 100644 --- a/actionview/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionview/lib/action_view/helpers/asset_tag_helper.rb @@ -13,7 +13,7 @@ module ActionView # the assets exist before linking to them: # # image_tag("rails.png") - # # => Rails + # # => # stylesheet_link_tag("application") # # => module AssetTagHelper @@ -207,8 +207,6 @@ module ActionView # You can add HTML attributes using the +options+. The +options+ supports # additional keys for convenience and conformance: # - # * :alt - If no alt text is given, the file name part of the - # +source+ is used (capitalized and without the extension) # * :size - Supplied as "{Width}x{Height}" or "{Number}", so "30x45" becomes # width="30" and height="45", and "50" becomes width="50" and height="50". # :size will be ignored if the value is not in the correct format. @@ -220,17 +218,17 @@ module ActionView # Assets (images that are part of your app): # # image_tag("icon") - # # => Icon + # # => # image_tag("icon.png") - # # => Icon + # # => # image_tag("icon.png", size: "16x10", alt: "Edit Entry") # # => Edit Entry # image_tag("/icons/icon.gif", size: "16") - # # => Icon + # # => # image_tag("/icons/icon.gif", height: '32', width: '32') - # # => Icon + # # => # image_tag("/icons/icon.gif", class: "menu_icon") - # # => Icon + # # => # image_tag("/icons/icon.gif", data: { title: 'Rails Application' }) # # => # image_tag("icon.png", srcset: { "icon_2x.png" => "2x", "icon_4x.png" => "4x" }) @@ -251,11 +249,7 @@ module ActionView check_for_image_tag_errors(options) skip_pipeline = options.delete(:skip_pipeline) - src = options[:src] = resolve_image_source(source, skip_pipeline) - - unless src.start_with?("cid:") || src.start_with?("data:") || src.blank? - options[:alt] = options.fetch(:alt) { image_alt(src) } - end + options[:src] = resolve_image_source(source, skip_pipeline) if options[:srcset] && !options[:srcset].is_a?(String) options[:srcset] = options[:srcset].map do |src_path, size| @@ -286,6 +280,8 @@ module ActionView # image_alt('underscored_file_name.png') # # => Underscored file name def image_alt(src) + ActiveSupport::Deprecation.warn("image_alt is deprecated and will be removed from Rails 6.0. You must explicitly set alt text on images.") + File.basename(src, ".*".freeze).sub(/-[[:xdigit:]]{32,64}\z/, "".freeze).tr("-_".freeze, " ".freeze).capitalize end -- cgit v1.2.3