Skip to content

Commit b3752bc

Browse files
authored
Icon title feature + related bug fixes (#1858)
* Add title property to icon component * Update icons in other templates
1 parent 7ce128f commit b3752bc

File tree

16 files changed

+83
-37
lines changed

16 files changed

+83
-37
lines changed

.changeset/cuddly-poems-hang.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cloudfour/patterns': minor
3+
---
4+
5+
Add new `title` property to Icon component to make semantic fallback text much more straightforward

.changeset/curly-cameras-fix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cloudfour/patterns': patch
3+
---
4+
5+
The Ground Nav button's icon is no longer presented inconsistently with other button icons

.changeset/gold-pans-sin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cloudfour/patterns': patch
3+
---
4+
5+
The default icon fallback now exists (oops)

.changeset/sixty-starfishes-nail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cloudfour/patterns': patch
3+
---
4+
5+
Icons used in the Alert component no longer use invalid `aria-hidden` values

src/components/alert/alert.twig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
{% if icon %}
66
{% include '@cloudfour/components/icon/icon.twig' with {
77
name: icon,
8-
aria_hidden: true
98
} only %}
109
{% endif %}
1110
{% endblock %}
@@ -30,7 +29,6 @@
3029
{% include '@cloudfour/components/icon/icon.twig' with {
3130
class: 'c-alert__dismiss-icon',
3231
name: 'x',
33-
aria_hidden: true,
3432
} %}
3533
<span class="u-hidden-visually">Dismiss alert</span>
3634
</button>

src/components/badge/badge.twig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
{% if icon %}
44
{% include '@cloudfour/components/icon/icon.twig' with {
55
name: icon,
6-
aria_hidden: 'true',
76
} only %}
87
{% endif %}
98
{% endblock %}

src/components/cloud-cover/demo/extra.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
We
1111
{% include '@cloudfour/components/icon/icon.twig' with {
1212
name: 'heart',
13+
title: 'love',
1314
inline: true
1415
} only %}
1516
<span class="u-hidden-visually">love</span>

src/components/cloud-cover/demo/scene.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
We
1111
{% include '@cloudfour/components/icon/icon.twig' with {
1212
name: 'heart',
13+
title: 'love',
1314
inline: true
1415
} only %}
1516
<span class="u-hidden-visually">love</span>

src/components/comment/comment.twig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
{% include '@cloudfour/components/icon/icon.twig' with {
5757
name: 'link',
5858
inline: true,
59-
aria_hidden: 'true',
6059
} only %}
6160
</span>
6261
<span class="u-hidden-visually">

src/components/footnote/footnote.twig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
{% include '@cloudfour/components/icon/icon.twig' with {
88
name: 'arrow-hook-left',
9-
aria_hidden: 'true',
109
} only %}
1110
</a>
1211
</li>

src/components/ground-nav/ground-nav.twig

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,11 @@
1818
{{ lead_in }}
1919
</h2>
2020
<p class="c-ground-nav__action-title">
21-
{% embed '@cloudfour/components/button/button.twig' with {
21+
{% include '@cloudfour/components/button/button.twig' with {
2222
href: link,
2323
label: title,
24-
_ground_nav_icon: icon
24+
content_start_icon: icon ?? 'link'
2525
} only %}
26-
{% block content %}
27-
{% if _ground_nav_icon %}
28-
{% include '@cloudfour/components/icon/icon.twig' with {
29-
name: _ground_nav_icon,
30-
fallback: 'link',
31-
inline: true,
32-
focusable: 'false'
33-
} only %}
34-
{% endif %}
35-
{{ label }}
36-
{% endblock %}
37-
{% endembed %}
3826
</p>
3927
{% include '@cloudfour/assets/illustrations/portland.svg.twig' with {
4028
class: 'c-ground-nav__action-illustration'

src/components/heading/heading.twig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
<a class="c-heading__permalink" href="#{{ id }}">
6767
{% include '@cloudfour/components/icon/icon.twig' with {
6868
name: 'link',
69-
aria_hidden: 'true'
7069
} only %}
7170
<span class="u-hidden-visually">Permalink to {{ _content }}</span>
7271
</a>

src/components/icon/demo/a11y.twig

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<p>
2+
I
3+
{% include '@cloudfour/components/icon/icon.twig' with {
4+
name: 'heart',
5+
title: 'love',
6+
inline: true,
7+
} %}
8+
icons with semantic fallbacks.
9+
</p>
10+
<p>
11+
{% include '@cloudfour/components/icon/icon.twig' with {
12+
name: 'check',
13+
inline: true
14+
} %}
15+
Decorative icons are nice, too!
16+
</p>

src/components/icon/icon.stories.mdx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import template from './icon.twig';
88
// within a Storybook docs page and not within an actual component).
99
// This can be revisited in the future if Storybook no longer relies on Webpack.
1010
// eslint-disable-next-line @cloudfour/import/no-webpack-loader-syntax
11+
import a11yDemoSource from '!!raw-loader!./demo/a11y.twig';
12+
import a11yDemo from './demo/a11y.twig';
13+
// eslint-disable-next-line @cloudfour/import/no-webpack-loader-syntax
1114
import inlineDemoSource from '!!raw-loader!./demo/inline.twig';
1215
import inlineDemo from './demo/inline.twig';
1316
const iconStory = (args) => {
@@ -38,12 +41,26 @@ For a list of available icons, visit [the Icons page](/docs/design-icons--page).
3841
fallback: { type: { name: 'string' } },
3942
inline: { type: { name: 'boolean' } },
4043
class: { type: { name: 'string' } },
44+
title: { type: { name: 'string' } },
4145
}}
4246
>
4347
{(args) => iconStory(args)}
4448
</Story>
4549
</Canvas>
4650

51+
## Accessibility
52+
53+
By default, an icon is assumed to be decorative. If the `title` property is provided, it will be used as the icon's accessible fallback text. The default values for `aria-hidden` and `role` will be adjusted accordingly as well. ([More info](https://css-tricks.com/accessible-svgs/#aa-example-1-standalone-icon-meaningful))
54+
55+
<Canvas>
56+
<Story
57+
name="Accessibility"
58+
parameters={{ docs: { source: { code: a11yDemoSource } } }}
59+
>
60+
{a11yDemo}
61+
</Story>
62+
</Canvas>
63+
4764
## Modifier: Inline
4865

4966
Icons without a flex or grid container may appear [slightly low in comparison to adjacent text](https://cloudfour.com/thinks/some-imaginary-css/#align-to-typeface-median). The `c-icon--inline` modifier applies a slight positioning adjustment to account for this.
@@ -65,10 +82,11 @@ Icons without a flex or grid container may appear [slightly low in comparison to
6582

6683
The component template supports the following unique properties:
6784

68-
- `name`: The name of the intended icon [in our library](/docs/design-icons--page).
69-
- `fallback`: The name of an icon to display if the first doesn't exist. Useful if you are displaying unique icons based on dynamic content. Defaults to `close`.
70-
- `inline`: When `true`, the inline modifier will be applied.
7185
- `class`: Will append to `c-icon` and any other modifier classes.
86+
- `fallback`: The name of an icon to display if the one specified by `name` doesn't exist. Useful if you are displaying unique icons based on dynamic content. Defaults to `x`.
87+
- `inline`: When `true`, the inline modifier will be applied.
88+
- `name`: The name of the intended icon [in our library](/docs/design-icons--page).
89+
- `title`: If provided, a `title` element will be prepended to the icon source with the contents of this property. This will also set the `role` to `img` unless it is already specified. ([More info](https://css-tricks.com/accessible-svgs/#aa-example-1-standalone-icon-meaningful))
7290

7391
Additional SVG properties will be passed to the Twig template for the asset itself:
7492

src/components/icon/icon.twig

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% set fallback = fallback|default('close') %}
1+
{% set fallback = fallback|default('x') %}
22

33
{% set _dir = '@cloudfour/assets/icons/' %}
44
{% set _ext = '.svg.twig' %}
@@ -15,6 +15,20 @@
1515
{% set _class = _class ~ ' ' ~ class %}
1616
{% endif %}
1717

18-
{% include [ _path, _fallback_path ] with {
19-
class: _class,
20-
} %}
18+
{% if title %}
19+
{% set _role = role ?? 'img' %}
20+
{% embed [ _path, _fallback_path ] with {
21+
class: _class,
22+
role: _role,
23+
} %}
24+
{% block before %}
25+
<title>{{title}}</title>
26+
{% endblock %}
27+
{% endembed %}
28+
{% else %}
29+
{% set _aria_hidden = aria_hidden ?? 'true' %}
30+
{% include [ _path, _fallback_path ] with {
31+
class: _class,
32+
aria_hidden: _aria_hidden,
33+
} %}
34+
{% endif %}

src/objects/rhythm/demo/article.twig

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,11 @@
4343
<p>This is similar to <a href="http://sonspring.com/">Nathan Smith’s</a> <a href="http://adapt.960.gs/">Adaptive.js</a> library which puts breakpoints in JavaScript instead of CSS.</p>
4444
<p>So by definition, Google Plus is not a responsive web design. It may look like one, but it doesn’t contain the three technical pieces necessary to be a responsive web design.</p>
4545
<p>
46-
{% embed '@cloudfour/components/button/button.twig' with {
47-
href: 'https://cloudfour.com/thinks/defining-responsiveness/'
46+
{% include '@cloudfour/components/button/button.twig' with {
47+
href: 'https://cloudfour.com/thinks/defining-responsiveness/',
48+
label: 'Full article',
49+
content_end_icon: 'arrow-right'
4850
} only %}
49-
{% block content %}
50-
Full article
51-
{% include '@cloudfour/components/icon/icon.twig' with {
52-
name: 'arrow-right',
53-
inline: true
54-
} only %}
55-
{% endblock %}
56-
{% endembed %}
5751
</p>
5852
{% endblock %}
5953
{% endembed %}

0 commit comments

Comments
 (0)