0
0
mirror of https://github.com/twbs/bootstrap.git synced 2024-12-04 16:24:22 +01:00
Bootstrap/site/_includes/icons/placeholder.svg
Patrick H. Lauke c031584bcd
SVG accessibility fixes (#27826)
* 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 https://github.com/svg/svgo/issues/1011 (which would be the "proper" SVGO fix) and the (hacky) solution https://github.com/svg/svgo/pull/817
2018-12-13 13:09:47 +00:00

36 lines
1.6 KiB
XML

{%- comment -%}
Usage: include icons/placeholder.svg args
args can be one of the following:
title: Used in the SVG `title` tag
text: The text to show in the image - default: 'width x height'
class: default: 'bd-placeholder-img'
color: The text color (foreground) - default: '#dee2e6'
background: The background color - default: '#868e96'
width: default: 100%
height: default: 180px
{%- endcomment -%}
{%- assign title = include.title | default: 'Placeholder' -%}
{%- assign class = include.class | default: '' -%}
{%- assign color = include.color | default: site.data.grays[2].hex -%}
{%- assign background = include.background | default: site.data.grays[5].hex -%}
{%- assign width = include.width | default: '100%' -%}
{%- assign height = include.height | default: '180' -%}
{%- if include.text -%}
{%- assign text = include.text -%}
{%- else -%}
{%- assign text = width | append: 'x' | append: height -%}
{%- endif -%}
{%- capture svg -%}
<svg class="bd-placeholder-img{% if class != '' %} {{ class }}{% endif %}" width="{{ width }}" height="{{ height }}" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid slice" focusable="false" role="img" {% if title != ' ' or text != ' ' %}aria-label="{% if title != ' ' %}{{ title }}{% if text != ' ' %}: {% endif %}{% endif %}{% if text != ' ' %}{{ text }}{% endif %}"{% endif %}>
{% if title != ' ' %}<title>{{ title }}</title>{% endif %}
<rect fill="{{ background }}" width="100%" height="100%"/>
{% if text != ' ' %}<text fill="{{ color }}" dy=".3em" x="50%" y="50%">{{ text }}</text>{% endif %}
</svg>
{%- endcapture -%}
{{- svg | replace: ' ', '' | strip_newlines -}}