Skip to content

Commit

Permalink
SVG accessibility fixes (#27826)
Browse files Browse the repository at this point in the history
* SVG accessibility fixes

- add `focusable="false"` to all SVGs, to stop IE from including the `<svg>` in its default focus cycle
- completely hide decorative SVGs using `aria-hidden="true"`
- add `role="img"` to meaningful/"content" SVGs, ensure they have an appropriate `<title>` and/or `aria-label`
- simplify placeholder default title

* Simplify usage of placeholder.svg in the docs

- in most cases, no need for separate/redundant text and title (now that we make text itself part of the alternative text explicitly)
- no need (expect in rare cirumstances) to describe the placeholder image (unless the look of the image is important/the actual content, as is the case with the image thumbnail class)

* Simplify example.html rewriting of <svg> to <img> code sample

- as the `alt` for the placeholder isn't really important, just add an ellipsis instead (otherwise, to be correct, we'd have to construct the whole "title+text" construct like we do now in the
placeholder.svg itself

* Change svgo configuration to retain role attribute and add/force focusable=false

- regarding `focusable=false`, see svg/svgo#1011 (which would be the "proper" SVGO fix) and the (hacky) solution svg/svgo#817
  • Loading branch information
patrickhlauke authored Dec 13, 2018
1 parent 375d137 commit c031584
Show file tree
Hide file tree
Showing 25 changed files with 94 additions and 92 deletions.
9 changes: 7 additions & 2 deletions build/svgo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ js2svg:
indent: 2

plugins:
# remove this with IE 11 is no longer supported
- addAttributesToSVGElement:
attributes:
- focusable: false
- cleanupAttrs: true
- cleanupEnableBackground: true
- cleanupIDs: true
Expand All @@ -41,8 +45,9 @@ plugins:
- removeHiddenElems: true
- removeMetadata: true
- removeNonInheritableGroupAttrs: true
- removeTitle: true
- removeUnknownsAndDefaults: true
- removeTitle: false
- removeUnknownsAndDefaults:
keepRoleAttr: true
- removeUnusedNS: true
- removeUselessDefs: true
- removeUselessStrokeAndFill: true
Expand Down
8 changes: 1 addition & 7 deletions site/_includes/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,10 @@
{%- assign image_class = image_class[1] | replace: 'bd-placeholder-img-lg', '' | strip -%}
{%- endif -%}
{%- assign image_alt = include.content
| replace: '<title>', '<title>✂️'
| replace: '</title>', '✂️</title>'
| split: '✂️' -%}
{%- assign image_alt = image_alt[1] -%}
{%- for content_chunk in modified_content -%}
{%- if content_chunk contains '<svg class="bd-placeholder-img' -%}
{%- capture img_placeholder -%}
<img src="..." {% if image_class %}class="{{ image_class }}" {% endif %}alt="{{ image_alt }}">
<img src="..." {% if image_class %}class="{{ image_class }}" {% endif %}alt="...">
{%- endcapture -%}
{{- img_placeholder -}}
{%- else -%}
Expand Down
2 changes: 1 addition & 1 deletion site/_includes/icons/bootstrap-stack.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion site/_includes/icons/bootstrap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion site/_includes/icons/download.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion site/_includes/icons/github.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion site/_includes/icons/import.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion site/_includes/icons/lightning.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion site/_includes/icons/menu.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions site/_includes/icons/placeholder.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion site/_includes/icons/slack.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit c031584

Please sign in to comment.